int dolabel() { int savelptr; char sname[NAMESIZE]; SYMBOL* ptr; blanks(); savelptr = lptr; if (symname(sname)) { if (gch() == ':') { if ((ptr = findgoto(sname)) && ptr->ident == ID_GOTOLABEL) { /* Label already goto'd, find some others with * same stack */ debug(DBG_GOTO, "Starting chase %s\n", sname); ChaseGoto(ptr); ptr->type = KIND_PTR; } else { ptr = addgotosym(sname); ptr->type = KIND_PTR; } debug(DBG_GOTO, "Adding label not called %s\n", sname); ptr->offset.i = Zsp; /* Save stack for label */ postlabel(ptr->size = getlabel()); return (1); } } lptr = savelptr; return (0); }
void ChaseGoto(SYMBOL* ptr) { GOTO_TAB* gptr; int i; if (gotocnt == 0) return; /* No gotos */ gptr = gotoq + 1; for (i = 0; i < gotocnt; i++) { debug(DBG_GOTO, "Chasing %s # %d\n", ptr->name, i); if (gptr->sym == ptr && gptr->sp == Zsp) { debug(DBG_GOTO, "Matched #%d \n", i); postlabel(gptr->label); gptr->sym = NULL; } gptr++; } }
void goto_cleanup(void) { int i; GOTO_TAB* gptr; if (gotocnt == 0) return; gptr = gotoq + 1; for (i = 0; i < gotocnt; i++) { if (gptr->sym) { debug(DBG_GOTO, "Cleaning %s #%d\n", gptr->sym->name, i); postlabel(gptr->label); modstk((gptr->sym->offset.i) - (gptr->sp), NO, NO); jump(gptr->sym->size); /* label label(!) */ } gptr++; } /* Wipe out reference to our goto labels in symbol table */ gotocnt = 0; }
/** \brief Set the argument offsets for a function, then kick off compiling * of the function * * \param prevarg - Last argument * \param currfn - Current function */ void setlocvar(SYMBOL *prevarg,SYMBOL *currfn) { int lgh,where; int *iptr; SYMBOL *copyarg; int argnumber; char buffer2[120]; unsigned char tester; lgh = 0; /* Initialise it */ if ( prevarg != NULL && currfn->prototyped == 0 ) { StoreFunctionSignature(prevarg); } argnumber=currfn->prototyped; /* * If we have filled up our number of arguments, then pretend * we don't have any..nasty, nasty */ if (argnumber==(MAXARGS-1)) argnumber=0; else if (argnumber) argnumber=1; /* * Dump some info about defining the function etc */ if (verbose){ toconsole(); outstr("Defining function: "); outstr(currfn->name); nl(); tofile(); } nl();prefix();outname(currfn->name,dopref(currfn));col();nl(); /* print function name */ infunc=1; /* In a function for sure! */ copyarg=prevarg; if ( ( (currfn->flags&SHARED) && makeshare ) || sharedfile ) { /* Shared library definition, offset the stack */ where= 2 +shareoffset; } else where = 2 ; /* If we use frame pointer we preserve previous framepointer on entry * to each function */ #ifdef USEFRAME if (useframe) where+=2; #endif while ( prevarg ) { lgh = 2 ; /* Default length */ /* This is strange, previously double check for ->type */ if ( prevarg->type == LONG && prevarg->ident != POINTER ) lgh=4; if ( prevarg->type == DOUBLE && prevarg->ident != POINTER ) lgh=6; /* Far pointers */ if ( (prevarg->flags&FARPTR)==FARPTR && prevarg->ident == POINTER) lgh=4; prevarg->size=lgh; #ifdef CODSWALLOP /* All pointers are pushed onto the stack for functions as 4 bytes, if * needed, near pointers are padded out to compensate for this by dummy * loading with zero, this allows us to have one set of routines to * cope with this and hence solve a lot of duplication */ if (prevarg->ident == POINTER && lpointer) lgh=4; prevarg->size=lgh; #endif /* * Check the definition against prototypes here... */ if (argnumber) { tester=CalcArgValue(prevarg->type,prevarg->ident,prevarg->flags); if (currfn->args[argnumber] != tester ) { if (currfn->args[argnumber] != PELLIPSES ) { if (currfn->args[argnumber] == 0 ) { warning(W_2MADECL); } else { if ( (currfn->args[argnumber]&PMASKSIGN) == (tester&PMASKSIGN) ) { warning(W_SIGNARG); } else { error(E_ARGMIS1,currfn->name,currfn->prototyped-argnumber+1, ExpandArgValue(tester,buffer2,prevarg->tag_idx) ); error(E_ARGMIS2,ExpandArgValue(currfn->args[argnumber],buffer2, currfn->tagarg[argnumber])); } } } } argnumber++; } iptr = &prevarg->offset.i ; prevarg = prevarg->offset.p ; /* follow ptr to prev. arg */ *iptr = where ; /* insert offset */ where += lgh ; /* calculate next offset */ } #ifdef USEFRAME pushframe(); #endif currfn->handled=YES; if (currfn->prototyped==1 && (currfn->flags®CALL) ) { /* * Fast call routine.. */ if (lgh==2) zpush(); else if (lgh==4) lpush(); else if (lgh==6) dpush(); /* erk, if not matched, dodgy type! */ copyarg->offset.i=-lgh; where=2; } stackargs=where; lstdecl=0; /* Set number of local statics to zero */ if ( statement() != STRETURN ) { if (lstdecl) postlabel(lstlab); lstdecl=0; /* do a statement, but if it's a return, skip */ /* cleaning up the stack */ leave(NO,NO) ; } CleanGoto(); /* Asz80 needs a label at the end to sort out local symbols */ if (asxx) { nl();prefix(); outstr("smce_"); outname(currfn->name,NO); col();nl(); } #ifdef INBUILT_OPTIMIZER generate(); #endif infunc = 0 ; /* not in fn. any more */ }