/* * Compiler begins execution here */ int main(int argc, char** argv) { gargc = argc; gargv = argv; /* allocate space for arrays */ litq = MALLOC(FNLITQ); /* literals, these 2 dumped end */ dubq = MALLOC(FNLITQ); /* Doubles */ tempq = MALLOC(LITABSZ); /* Temp strings... */ glbq = MALLOC(LITABSZ); /* Used for glb lits, dumped now */ symtab = NULL; loctab = MALLOC(NUMLOC * sizeof(SYMBOL)); wqueue = MALLOC(NUMWHILE * sizeof(WHILE_TAB)); gotoq = MALLOC(NUMGOTO * sizeof(GOTO_TAB)); swnext = MALLOC(NUMCASE * sizeof(SW_TAB)); swend = swnext + (NUMCASE - 1); stage = MALLOC(STAGESIZE); stagelast = stage + STAGELIMIT; glbcnt = 0; /* clear global symbols */ locptr = STARTLOC; /* clear local symbols */ wqptr = wqueue; /* clear while queue */ gltptr = 0; /* clear literal pools */ *litq = 0; /* First entry in literal queue is zero */ litptr = 1; /* So miniprintf search works */ Zsp = /* stack ptr (relative) */ errcnt = /* no errors */ c_errstop = /* keep going after an error */ eof = /* not eof yet */ ncmp = /* no open compound states */ lastst = /* not first file to asm */ lineno = /* no lines read from file */ infunc = /* not in function now */ 0; /* ...all set to zero.... */ stagenext = NULL; /* direct output mode */ input = /* no input file */ inpt2 = /* or include file */ saveout = /* no diverted output */ output = NULL; /* no open units */ currfn = NULL; /* no function yet */ macptr = cmode = 1; /* clear macro pool and enable preprocessing */ ncomp = need_floatpack = 0; c_default_unsigned = NO; nxtlab = 0;/* start numbers at lowest possible */ c_intermix_ccode = 0; /* don't include the C text as comments */ c_errstop =0; /* don't stop after errors */ c_verbose = 0; c_double_strings = 0; c_notaltreg = NO; debuglevel = NO; c_assembler_type = ASM_Z80ASM; c_framepointer_is_ix = -1; c_use_r2l_calling_convention = NO; setup_sym(); /* define some symbols */ /* Parse the command line options */ atexit(atexit_deallocate); /* To free everything */ clear(); filenum = 0; gargc = parse_arguments(sccz80_opts, argc, argv); clear(); if (gargc == 0) { info(); exit(1); } if ( c_maths_mode == MATHS_IEEE ) { c_fp_size = 4; type_double = &(Type){ KIND_DOUBLE, 4, 0, .len=1 }; c_fp_exponent_bias = 126; c_fp_mantissa_bytes = 3; WriteDefined("CLIB_32BIT_FLOATS", 1); } else if ( c_maths_mode == MATHS_MBFS ) {
/* * Compiler begins execution here */ int main(int argc, char **argv) { int n; /* Loop counter */ int i; gargc = argc ; gargv = argv ; /* * Empty our mem ptrs */ litq=dubq=tempq=glbq=0; symtab=loctab=0; wqueue=0;membptr=0;tagptr=0;swnext=0;stage=0; gotoq=0; /* allocate space for arrays */ litq = mymalloc(FNLITQ) ; /* literals, these 2 dumped end */ dubq = mymalloc(FNLITQ) ; /* Doubles */ tempq = mymalloc(LITABSZ) ; /* Temp strings... */ glbq = mymalloc(LITABSZ) ; /* Used for glb lits, dumped now */ symtab = SYM_CAST mymalloc(NUMGLBS*sizeof(SYMBOL)) ; loctab = SYM_CAST mymalloc(NUMLOC*sizeof(SYMBOL)) ; wqueue = WQ_CAST mymalloc(NUMWHILE*sizeof(WHILE_TAB)) ; gotoq= (GOTO_TAB *)calloc(NUMGOTO,sizeof(GOTO_TAB)); if (gotoq==NULL) OutOfMem(); tagptr = tagtab = TAG_CAST mymalloc(NUMTAG*sizeof(TAG_SYMBOL)) ; membptr = membtab = SYM_CAST mymalloc(NUMMEMB*sizeof(SYMBOL)) ; swnext = SW_CAST mymalloc(NUMCASE*sizeof(SW_TAB)) ; swend = swnext + (NUMCASE-1) ; stage = mymalloc(STAGESIZE) ; stagelast = stage+STAGELIMIT ; /* empty symbol table */ glbptr = STARTGLB; while ( glbptr < ENDGLB ) { glbptr->name[0] = 0 ; ++glbptr ; } glbcnt = 0 ; /* clear global symbols */ locptr = STARTLOC ; /* clear local symbols */ wqptr = wqueue ; /* clear while queue */ gltptr=dubptr=0 ; /* clear literal pools */ *litq=0; /* First entry in literal queue is zero */ litptr=1; /* So miniprintf search works */ Zsp = /* stack ptr (relative) */ errcnt = /* no errors */ errstop = /* keep going after an error */ eof = /* not eof yet */ swactive = /* not in switch */ skiplevel = /* #if not encountered */ iflevel = /* #if nesting level = 0 */ ncmp = /* no open compound states */ lastst = /* not first file to asm */ fnstart = /* current "function" started at line 0 */ lineno = /* no lines read from file */ infunc = /* not in function now */ 0 ; /* ...all set to zero.... */ stagenext = NULL_CHAR ; /* direct output mode */ input = /* no input file */ inpt2 = /* or include file */ saveout = /* no diverted output */ output = NULL_FD ; /* no open units */ currfn = NULL_SYM ; /* no function yet */ macptr = cmode = 1 ; /* clear macro pool and enable preprocessing */ ncomp=doinline=mathz88 = incfloat= compactcode =0; intuition=zorg=lpointer=cppcom=appz88=0; dosigned=NO; makelib=useshare=makeshare=sharedfile=NO; smartprintf=expanded=YES; startup=0; /* Which startup do we want? */ nxtlab = /* start numbers at lowest possible */ ctext = /* don't include the C text as comments */ errstop = /* don't stop after errors */ verbose = 0; gotocnt=0; defdenums=0; doublestrings = 0; noaltreg = NO; safedata=reqpag = -1; shareoffset=SHAREOFFSET; /* Offset for shared libs */ debuglevel=NO; farheapsz=-1; /* Size of far heap */ assemtype = ASM_Z80ASM; printflevel=0; #ifdef USEFRAME indexix=YES; useframe=NO; #endif /* * compiler body */ setup_sym() ; /* define some symbols */ /* Parse the command line options */ atexit(MemCleanup); /* To free everything */ clear(); filenum=0; for (n=1;n<argc;n++) { if (argv[n][0]=='-') ParseArgs(1+argv[n]); else {filenum=n; break;} } clear(); if (filenum == 0) { info(); exit(1); } litlab=getlabel(); /* Get labels for function lits*/ dublab=getlabel(); /* and fn doubles*/ openout(); /* get the output file */ openin(); /* and initial input file */ header(); /* intro code */ parse(); /* process ALL input */ /* dump literal queues, with label */ /* litq starts from 1, so literp has to be -1 */ dumplits(0, YES,litptr-1,litlab,litq+1) ; dumplits(1, YES,dubptr,dublab,dubq) ; dumpvars(); dumpfns(); trailer(); /* follow-up code */ closeout(); errsummary(); /* summarize errors */ if (errcnt) exit(1); exit(0); }