ident_t createid(idtype_t type, vartype_t subtype, char *id, symbol_t val){ symtab_t tab = global; ident_t nid; if(context){ tab = context->local; if(findTable(tab, id)){ msg(DEBUG, "identifier has been defined", line); exit(0); } } if(type==CONSTANT || type==LIT){ if(!typecheck(subtype, val->type)){ msg(ERR, "type mismatch", line); ERROR_STATUS = 1; } } nid = createIdent(); nid->type = type; if(type!=LABEL) nid->subtype = subtype; nid->name = id; if(val)nid->data = val->value; nid->extra = 0; if(insertTable(tab, nid)){ msg(DEBUG, "failed to insert identifier", line); exit(0); } if(tab == global) nid->loc = LOC_GLOBAL; else nid->loc = LOC_LOCAL; return nid; }
inline Sequence* StructFactoryImpl::fabricate (Query<Sequence> const& caps) { // when we reach this point it is clear a suitable sequence doesn't yet exist in the model TODO ("actually extract properties/capabilities from the query..."); string forkID = caps.extractID ("fork"); Query<Fork> desiredFork (isnil (forkID)? "" : "id("+forkID+")"); // PFork fork = Session::current->query (desiredFork); ///////////////////////////////////TICKET #639 // TODO: handle the following cases // - fork doesn't exist --> create and attach it as root // - fork exists and is root attached, but belongs already to a sequence --> throw // - fork exists, but isn't root attached ---> what do do here? steal it?? PSequence newSequence = Sequence::create (createIdent (caps)); ///////////TODO fed fork in here ENSURE (newSequence); ///////////////////////TICKET #565 maybe store the capabilities query within the Struct asset somehow? return newSequence.get(); }
ident_t getLiteral(symtab_t tab, symbol_t s){ symtab_t p = tab->next, q; ident_t id; while(p){ id = p->entry; if(id->type == LIT && id->subtype == translate(s->type) && id->data == s->value){ return id; } q = p; p = p->next; } id = createIdent(); id->type=LIT; id->subtype = translate(s->type); id->data = s->value; id->name = ccgenname(litnum++, '_'); id->loc = LOC_GLOBAL; insertTable(tab, id); return id; }
inline const ProcPatt* StructFactoryImpl::fabricate (Query<const ProcPatt> const& caps) { TODO ("actually extract properties/capabilities from the query..."); return new ProcPatt (createIdent (caps)); } ///////////////////////TICKET #565 maybe store the capabilities query within the Struct asset somehow?
void dag(qcode_t *first, qcode_t *last){ qcode_t p = *first, ret = 0, q; nodelist nr; dnode node, x, y, z, cur_inst = 0, new_inst; ident_t nid; if(p->code == NOP){ q = p; ret = q; } while(p && p->code != RET && (p->code < JGT || p->code > JMP)){ if(p->code == MOV){ nr = findlist(p->op1); if(!nr){ node = createLeaf(p->op1); updatelist(p->op1, node); }else{ node = nr->addr; } updatelist(p->opr, node); } else if(p->code!= CMP && p->code!=FCMP && p->code >= ADD && p->code <=FNEG){ nr = findlist(p->op1); if(!nr){ node = createLeaf(p->op1); updatelist(p->op1, node); }else{ node = nr->addr; } x = node; y = 0; if(p->op2){ nr = findlist(p->op2); if(!nr){ node = createLeaf(p->op2); updatelist(p->op2, node); }else{ node = nr->addr; } y = node; } nr = dnodelist; while(nr){ z = nr->addr; if(z->op == p->code && z->x == x && z->y == y) break; nr = nr->next; } if(!nr){ z = createNode(DAG_OP, p->code, 0, x, y); }else{ z = nr->addr; } updatelist(p->opr, z); } else { if(p->op1){ nr = findlist(p->op1); if(!nr){ x = createLeaf(p->op1); updatelist(p->op1, x); }else{ x = nr->addr; } }else{ x = 0; } if(p->op2){ nr = findlist(p->op2); if(!nr){ y = createLeaf(p->op2); updatelist(p->op2, y); }else{ y = nr->addr; } }else{ y = 0; } new_inst = createNode(DAG_INST, p->code, cur_inst, x, y); cur_inst = new_inst; if(p->opr){ nid = createIdent(); nid->name = ccgenname(namenum++, '$'); nid->type = TEMP; nid->subtype = p->opr->subtype; nid->loc = LOC_LOCAL; insertTable(stab, nid); cur_inst->oprand = nid; cur_inst->vartype = nid->subtype; updatelist(p->opr, cur_inst); }else{ cur_inst->vartype = TVOID; } } p = p->next; } if(ret) ret->next = undag(); else ret = undag(); *first = ret; q = ret; while(q->next){ q = q->next; } if(p){ if(p->code == RET && p->opr){ nr = findlist(p->opr); p->opr = nr->addr->oprand; } *last = p; q->next = p; p->next = 0; }else{ *last = q; } deleteNodes(); clearnodelist(); }
qcode_t undag(){ qcode_t ret = 0, nc; dnode cur = nodes; nodelist p = dnodelist; ident_t nid; while(p){ if(!(p->flag) && (p->addr->type != DAG_LEAF) && p->id->type == VAR){ p->flag = 1; p->addr->oprand = p->id; } p = p->next; } while(cur){ if(cur->type == DAG_OP && cur->oprand == 0){ nid = createIdent(); nid->name = ccgenname(namenum++, '$'); nid->type = TEMP; nid->subtype = cur->vartype; nid->loc = LOC_LOCAL; insertTable(stab, nid); cur->oprand = nid; } cur = cur->next; } p = dnodelist; while(p){ if(p->id->type == VAR && !(p->flag) && p->addr->oprand != p->id){ nc = createQCode(); nc->code = MOV; nc->op1 = p->addr->oprand; nc->op2 = 0; nc->opr = p->id; nc->next = ret; ret = nc; } p = p->next; } cur = getNode(); while(cur){ nc = createQCode(); nc->code = cur->op; nc->op1 = nc->op2 = nc->opr = 0; if( cur->x ){ if(cur->type <= DAG_INST) nc->op1 = cur->x->oprand; cur->x->nref--; } if( cur->y ){ if(cur->type <= DAG_INST) nc->op2 = cur->y->oprand; cur->y->nref--; } if(cur->oprand){ nc->opr = cur->oprand; } nc->next = ret; ret = nc; cur->type = DAG_DEAD; if(cur->l){ cur = cur->l; cur->nref--; }else cur = cur->x; if(!cur || cur->type == DAG_LEAF || cur->nref)cur = getNode(); } return ret; }