int InitializePointer() { SYM *sp; ENODE *n; long lng; if(lastst == bitandd) { /* address of a variable */ NextToken(); if( lastst != id) error(ERR_IDEXPECT); else if( (sp = gsearch(lastid)) == NULL) error(ERR_UNDEFINED); else { NextToken(); if( lastst == plus || lastst == minus) GenerateReference(sp,GetIntegerExpression((ENODE **)NULL)); else GenerateReference(sp,0); if( sp->storage_class == sc_auto) error(ERR_NOINIT); } } else if(lastst == sconst) { GenerateLabelReference(stringlit(laststr)); NextToken(); } else if (lastst == rconst) { GenerateLabelReference(quadlit(&rval128)); NextToken(); } //else if (lastst == id) { // sp = gsearch(lastid); // if (sp->tp->type == bt_func || sp->tp->type == bt_ifunc) { // NextToken(); // GenerateReference(sp,0); // } // else // GenerateLong(GetIntegerExpression(NULL)); //} else { lng = GetIntegerExpression(&n); if (n && n->nodetype == en_cnacon) { if (n->sp->length()) { sp = gsearch(*n->sp); GenerateReference(sp,0); } else GenerateLong(lng); } else { GenerateLong(lng); } } endinit(); return 2; /* pointers are 2 bytes long */ }
int InitializePointer() { SYM *sp; if(lastst == and) { /* address of a variable */ NextToken(); if( lastst != id) error(ERR_IDEXPECT); else if( (sp = gsearch(lastid)) == NULL) error(ERR_UNDEFINED); else { NextToken(); if( lastst == plus || lastst == minus) GenerateReference(sp,GetIntegerExpression()); else GenerateReference(sp,0); if( sp->storage_class == sc_auto) error(ERR_NOINIT); } } else if(lastst == sconst) { GenerateLabelReference(stringlit(laststr)); NextToken(); } else GenerateLong(GetIntegerExpression()); endinit(); return 8; /* pointers are 4 bytes long */ }
void insert(SYMBOL *in, HASHTABLE *table) { if (table) { #ifdef PARSER_ONLY if (table != defsyms && table != kwhash && table != labelSyms && table != ccHash) ccSetSymbol(in); #endif if (cparams.prm_extwarning) if (in->storage_class == sc_parameter || in->storage_class == sc_auto || in->storage_class == sc_register) { SYMBOL *sp; if ((sp = gsearch(in->name)) != NULL) preverror(ERR_VARIABLE_OBSCURES_VARIABLE_AT_HIGHER_SCOPE, in->name, sp->declfile, sp->declline); } #if defined (PARSER_ONLY) if (AddName(in, table) && table != ccHash) #else if (AddName(in, table)) #endif { #if defined(CPREPROCESSOR) || defined(PARSER_ONLY) pperrorstr(ERR_DUPLICATE_IDENTIFIER, in->name); #else preverrorsym(ERR_DUPLICATE_IDENTIFIER, in, in->declfile, in->declline); #endif } } else { diag("insert: cannot insert"); } }
AMODE *GenerateFunctionCall(ENODE *node, int flags) { AMODE *ap, *result; SYM *sym; int i; int msk; msk = SaveTempRegs(); sym = NULL; i = GeneratePushParameterList(node->p[1]); // Call the function if( node->p[0]->nodetype == en_nacon ) { GenerateDiadic(op_call,0,make_offset(node->p[0]),NULL); sym = gsearch(node->p[0]->sp); } else { ap = GenerateExpression(node->p[0],F_REG,8); ap->mode = am_ind; GenerateDiadic(op_jal,0,makereg(31),ap); ReleaseTempRegister(ap); } // Pop parameters off the stack if (i!=0) { if (sym) { if (!sym->IsPascal) GenerateTriadic(op_addui,0,makereg(30),makereg(30),make_immed(i * 8)); } else GenerateTriadic(op_addui,0,makereg(30),makereg(30),make_immed(i * 8)); } RestoreTempRegs(msk); result = GetTempRegister(); if( result->preg != 1 || (flags & F_REG) == 0 ) if (sym) { if (sym->tp->btp->type==bt_void) ; else GenerateDiadic(op_mov,0,result,makereg(1)); } else GenerateDiadic(op_mov,0,result,makereg(1)); return result; }
// Display the tab codes of the BLOBNBOXes in this grid. ScrollView* AlignedBlob::DisplayTabs(const char* window_name, ScrollView* tab_win) { #ifndef GRAPHICS_DISABLED if (tab_win == nullptr) tab_win = MakeWindow(0, 50, window_name); // For every tab in the grid, display it. GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this); gsearch.StartFullSearch(); BLOBNBOX* bbox; while ((bbox = gsearch.NextFullSearch()) != nullptr) { const TBOX& box = bbox->bounding_box(); int left_x = box.left(); int right_x = box.right(); int top_y = box.top(); int bottom_y = box.bottom(); TabType tabtype = bbox->left_tab_type(); if (tabtype != TT_NONE) { if (tabtype == TT_MAYBE_ALIGNED) tab_win->Pen(ScrollView::BLUE); else if (tabtype == TT_MAYBE_RAGGED) tab_win->Pen(ScrollView::YELLOW); else if (tabtype == TT_CONFIRMED) tab_win->Pen(ScrollView::GREEN); else tab_win->Pen(ScrollView::GREY); tab_win->Line(left_x, top_y, left_x, bottom_y); } tabtype = bbox->right_tab_type(); if (tabtype != TT_NONE) { if (tabtype == TT_MAYBE_ALIGNED) tab_win->Pen(ScrollView::MAGENTA); else if (tabtype == TT_MAYBE_RAGGED) tab_win->Pen(ScrollView::ORANGE); else if (tabtype == TT_CONFIRMED) tab_win->Pen(ScrollView::RED); else tab_win->Pen(ScrollView::GREY); tab_win->Line(right_x, top_y, right_x, bottom_y); } } tab_win->Update(); #endif return tab_win; }
IMODE *set_symbol(char *name, int isproc) /* * generate a call to a library routine. */ { SYMBOL *sp; IMODE *result; (void) isproc; sp = gsearch(name); if (sp == 0) { LIST *l1; IncGlobalFlag(); sp = (SYMBOL *)Alloc(sizeof(SYMBOL)); sp->storage_class = sc_external; sp->name = sp->errname = sp->decoratedName = litlate(name); sp->genreffed = TRUE; sp->tp = (TYPE *)Alloc(sizeof(TYPE)); sp->tp->type = isproc ? bt_func : bt_int; sp->safefunc = TRUE; insert(sp, globalNameSpace->syms); InsertExtern(sp); DecGlobalFlag(); } else { if (sp->storage_class == sc_overloads) sp = (SYMBOL *)(sp->tp->syms->table[0]->p); } result = (IMODE *)Alloc(sizeof(IMODE)); result->offset = varNode(en_global, sp); result->mode = i_direct; if (isproc) { result->offset->type = en_pc; if (chosenAssembler->arch->libsasimports) result->mode = i_direct; else result->mode = i_immed; } return result; }
AMODE *set_symbol(char *name, int flag) { SYM *sp; AMODE *ap; sp = gsearch(name); if (sp == 0) { ++global_flag; sp = makesym(flag ? sc_externalfunc : sc_external); sp->tp = &stdfunc; sp->name = name; sp->extflag = 1; insert(sp, gsyms); --global_flag; } ap = xalloc(sizeof(AMODE)); ap->mode = am_immed; ap->length = BESZ_DWORD; ap->offset = makenode(en_nacon, sp, 0); return ap; }
void insertOverload(SYMBOL *in, HASHTABLE *table) { if (cparams.prm_extwarning) if (in->storage_class == sc_parameter || in->storage_class == sc_auto || in->storage_class == sc_register) { SYMBOL *sp; if ((sp = gsearch(in->name)) != NULL) preverror(ERR_VARIABLE_OBSCURES_VARIABLE_AT_HIGHER_SCOPE, in->name, sp->declfile, sp->declline); } if (AddOverloadName(in, table)) { #ifdef CPREPROCESSOR pperrorstr(ERR_DUPLICATE_IDENTIFIER, in->name); #else SetLinkerNames(in, lk_cdecl); preverrorsym(ERR_DUPLICATE_IDENTIFIER, in, in->declfile, in->declline); #endif } }
AMODE *GenerateFunctionCall(ENODE *node, int flags) { AMODE *ap, *result; SYM *sym; int i; int msk; int sp; //msk = SaveTempRegs(); sp = TempInvalidate(); sym = (SYM*)NULL; i = GeneratePushParameterList(node->p[1]); // Call the function if( node->p[0]->nodetype == en_cnacon ) { GenerateMonadic(op_jsr,0,make_offset(node->p[0])); sym = gsearch(node->p[0]->sp); } else { ap = GenerateExpression(node->p[0],F_BREG,8); ap->mode = am_brind; GenerateDiadic(op_jsr,0,makebreg(LR),ap); ReleaseTempRegister(ap); } // Pop parameters off the stack if (i!=0) { if (sym) { if (!sym->IsPascal) GenerateTriadic(op_addui,0,makereg(regSP),makereg(regSP),make_immed(i * 8)); } else GenerateTriadic(op_addui,0,makereg(regSP),makereg(regSP),make_immed(i * 8)); } //RestoreTempRegs(msk); TempRevalidate(sp); ap = GetTempRegister(); GenerateDiadic(op_mov,0,ap,makereg(1)); return ap; }
AMODE *set_symbol(char *name,int flag) { SYM *sp; AMODE *ap; sp = gsearch(name); if( sp == 0 ) { ++global_flag; sp = xalloc(sizeof(SYM)); sp->tp = &stdfunc; sp->name = name; if (flag) sp->storage_class = sc_externalfunc; else sp->storage_class = sc_external; sp->extflag = 1; insert(sp,&gsyms); --global_flag; } ap = make_strlab(name); ap->mode = am_immed; return ap; }
AMODE *GenerateFunctionCall(ENODE *node, int flags) { AMODE *ap, *result; SYM *sym; int i; int msk; int sp; int isPascal = FALSE; dfs.puts("<GenerateFunctionCall>"); //msk = SaveTempRegs(); if (node->p[0] < (ENODE *)0x0FLL) { error(ERR_NULLPOINTER); goto xit1; } sp = TempInvalidate(); sym = (SYM*)NULL; i = GeneratePushParameterList(node->p[1]); // Call the function if( node->p[0]->nodetype == en_cnacon ) { dfs.printf("cnacon node:%s|\n",(char *)node->p[0]->sp->c_str()); // if (node->p[0]->i==25) // GenerateDiadic(op_sw,0,makereg(regCLP),make_indexed(0,regSP)); if (node->p[0]->sp < (std::string *)0x0FLL) node->p[0]->sp = new std::string("<null>"); GenerateMonadic(op_jsr,0,make_offset(node->p[0])); sym = gsearch(*node->p[0]->sp); dfs.puts((char*)(node->p[0]->sp->c_str())); if (sym) { dfs.puts("<found></found>"); } else { dfs.printf("<notfound>%s</notfound>",(char*)(node->p[0]->sp->c_str())); } } else { ap = GenerateExpression(node->p[0],F_BREG,8); ap->mode = am_brind; isPascal = node->p[0]->isPascal; GenerateDiadic(op_jsr,0,makebreg(1),ap); ReleaseTempRegister(ap); } // Pop parameters off the stack if (i!=0) { if (sym) { if (!sym->IsPascal) GenerateTriadic(op_addui,0,makereg(regSP),makereg(regSP),make_immed(i * 8)); } else if (!isPascal) GenerateTriadic(op_addui,0,makereg(regSP),makereg(regSP),make_immed(i * 8)); } //RestoreTempRegs(msk); TempRevalidate(sp); xit1: ap = GetTempRegister(); if (flags & F_NOVALUE) ; else GenerateDiadic(op_mov,0,ap,makereg(1)); dfs.puts("</GenerateFunctionCall>"); return ap; }
/* Search the tables looking for a match for an argument type list */ SYM *funcovermatch(char *name,TYP *tp) { #ifdef CPLUSPLUS char buf1[100]; TABLE *tbl1, *tbl2; if (prm_cplusplus) { SYM *sp2,*sp3,*sp4=0,*sp5=0,*sp6,*sp7; tbl1 = &lsyms; tbl2 = &gsyms; buf1[0] = '$'; buf1[1] = '$'; strcpy(&buf1[2],name); sp2 = search(buf1,tbl1); sp3 = search(buf1,tbl2); if (sp2) if (fomatch(sp2->tp,tp)) sp4 = sp2; if (sp3) if (fomatch(sp3->tp,tp)) sp5 = sp3; if (sp4 && sp5) { genfunc2error(ERR_AMBIGFUNC,sp4->defalt,sp5->defalt); return gsearch(sp4->defalt); } if (sp2) { sp6 = sp2->value.overlist.head; while (sp6) { if (fomatch(sp6->tp,tp)) { if (sp4) { genfunc2error(ERR_AMBIGFUNC,sp4->defalt,sp6->defalt); return gsearch(sp4->defalt); } else if (sp5) { genfunc2error(ERR_AMBIGFUNC,sp5->defalt,sp6->defalt); return gsearch(sp5->defalt); } else sp4 = sp6; } sp6 = sp6->next; } } if (sp3) { sp7 = sp3->value.overlist.head; while (sp7) { if (fomatch(sp7->tp,tp)) { if (sp4) { genfunc2error(ERR_AMBIGFUNC,sp4->defalt,sp7->defalt); return gsearch(sp4->defalt); } else if (sp5) { genfunc2error(ERR_AMBIGFUNC,sp5->defalt,sp7->defalt); return gsearch(sp5->defalt); } else sp5 = sp7; } sp7 = sp7->next; } } if (sp4) return gsearch(sp4->defalt); if (sp5) return gsearch(sp5->defalt); } #endif return(gsearch(name)); }
static long ieprimary(TYP **tp) /* * PRimary integer * defined(MACRO) * id * iconst * (cast )intexpr * (intexpr) */ { long temp=0; SYM *sp; if (tp) *tp = &stdint; if(lastst == id) { char *lid = lastid; if (prm_cmangle) lid++; sp = gsearch(lastid); if(sp == NULL) { gensymerror(ERR_UNDEFINED,lastid); getsym(); return 0; } if(sp->storage_class != sc_const && sp->tp->type != bt_enum) { generror(ERR_NEEDCONST,0,0); getsym(); return 0; } getsym(); return sp->value.i; } else if(lastst == iconst) { temp = ival; getsym(); return temp; } else if(lastst == lconst) { if (tp) *tp = &stdlong; temp = ival; getsym(); return temp; } else if(lastst == iuconst) { if (tp) *tp = &stduns; temp = ival; getsym(); return temp; } else if(lastst == luconst) { if (tp) *tp = &stdunsigned; temp = ival; getsym(); return temp; } else if(lastst == cconst) { if (tp) *tp = &stdchar; temp = ival; getsym(); return temp; } else if (lastst == openpa) { getsym(); if (castbegin(lastst)) { decl(0); decl1(); needpunc(closepa,0); if (tp) *tp = head; return intexpr(0); } else { temp = intexpr(tp); return(temp); } } getsym(); generror(ERR_NEEDCONST,0,0); return 0; }