sourcepawn/compiler/sc4.c
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3951 c3f26df2183f
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /*  Pawn compiler - code generation (unoptimized "assembler" code)
     2  *
     3  *  Copyright (c) ITB CompuPhase, 1997-2006
     4  *
     5  *  This software is provided "as-is", without any express or implied warranty.
     6  *  In no event will the authors be held liable for any damages arising from
     7  *  the use of this software.
     8  *
     9  *  Permission is granted to anyone to use this software for any purpose,
    10  *  including commercial applications, and to alter it and redistribute it
    11  *  freely, subject to the following restrictions:
    12  *
    13  *  1.  The origin of this software must not be misrepresented; you must not
    14  *      claim that you wrote the original software. If you use this software in
    15  *      a product, an acknowledgment in the product documentation would be
    16  *      appreciated but is not required.
    17  *  2.  Altered source versions must be plainly marked as such, and must not be
    18  *      misrepresented as being the original software.
    19  *  3.  This notice may not be removed or altered from any source distribution.
    20  *
    21  *  Version: $Id$
    22  */
    23 #include <assert.h>
    24 #include <ctype.h>
    25 #include <stdio.h>
    26 #include <stdlib.h>     /* for _MAX_PATH */
    27 #include <string.h>
    28 #if defined FORTIFY
    29   #include <alloc/fortify.h>
    30 #endif
    31 #include "sc.h"
    32 
    33 static int fcurseg;     /* the file number (fcurrent) for the active segment */
    34 
    35 
    36 /* When a subroutine returns to address 0, the AMX must halt. In earlier
    37  * releases, the RET and RETN opcodes checked for the special case 0 address.
    38  * Today, the compiler simply generates a HALT instruction at address 0. So
    39  * a subroutine can savely return to 0, and then encounter a HALT.
    40  */
    41 SC_FUNC void writeleader(symbol *root)
    42 {
    43   int lbl_nostate,lbl_table;
    44   int statecount;
    45   symbol *sym;
    46   constvalue *fsa, *state, *stlist;
    47   int fsa_id,listid;
    48   char lbl_default[sNAMEMAX+1];
    49 
    50   assert(code_idx==0);
    51 
    52   begcseg();
    53   stgwrite(";program exit point\n");
    54   stgwrite("\thalt 0\n\n");
    55   code_idx+=opcodes(1)+opargs(1);       /* calculate code length */
    56 
    57   /* check whether there are any functions that have states */
    58   for (sym=root->next; sym!=NULL; sym=sym->next)
    59     if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL)
    60       break;
    61   if (sym==NULL)
    62     return;             /* no function has states, nothing to do next */
    63 
    64   /* generate an error function that is called for an undefined state */
    65   stgwrite("\n;exit point for functions called from the wrong state\n");
    66   lbl_nostate=getlabel();
    67   setlabel(lbl_nostate);
    68   stgwrite("\thalt ");
    69   outval(AMX_ERR_INVSTATE,TRUE);
    70   code_idx+=opcodes(1)+opargs(1);       /* calculate code length */
    71 
    72   /* write the "state-selectors" table with all automatons (update the
    73    * automatons structure too, as we are now assigning the address to
    74    * each automaton state-selector variable)
    75    */
    76   assert(glb_declared==0);
    77   begdseg();
    78   for (fsa=sc_automaton_tab.next; fsa!=NULL; fsa=fsa->next) {
    79     defstorage();
    80     stgwrite("0\t; automaton ");
    81     if (strlen(fsa->name)==0)
    82       stgwrite("(anonymous)");
    83     else
    84       stgwrite(fsa->name);
    85     stgwrite("\n");
    86     fsa->value=glb_declared*sizeof(cell);
    87     glb_declared++;
    88   } /* for */
    89 
    90   /* write stubs and jump tables for all state functions */
    91   begcseg();
    92   for (sym=root->next; sym!=NULL; sym=sym->next) {
    93     if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL) {
    94       stlist=sym->states->next;
    95       assert(stlist!=NULL);     /* there should be at least one state item */
    96       listid=stlist->index;
    97       assert(listid==-1 || listid>0);
    98       if (listid==-1 && stlist->next!=NULL) {
    99         /* first index is the "fallback", take the next one (if available) */
   100         stlist=stlist->next;
   101         listid=stlist->index;
   102       } /* if */
   103       if (listid==-1) {
   104         /* first index is the fallback, there is no second... */
   105         strcpy(stlist->name,"0"); /* insert dummy label number */
   106         /* this is an error, but we postpone adding the error message until the
   107          * function definition
   108          */
   109         continue;
   110       } /* if */
   111       /* generate label numbers for all statelist ids */
   112       for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   113         assert(strlen(stlist->name)==0);
   114         strcpy(stlist->name,itoh(getlabel()));
   115       } /* for */
   116       if (strcmp(sym->name,uENTRYFUNC)==0)
   117         continue;               /* do not generate stubs for this special function */
   118       sym->addr=code_idx;       /* fix the function address now */
   119       /* get automaton id for this function */
   120       assert(listid>0);
   121       fsa_id=state_getfsa(listid);
   122       assert(fsa_id>=0);        /* automaton 0 exists */
   123       fsa=automaton_findid(fsa_id);
   124       /* count the number of states actually used; at the sane time, check
   125        * whether there is a default state function
   126        */
   127       statecount=0;
   128       strcpy(lbl_default,itoh(lbl_nostate));
   129       for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   130         if (stlist->index==-1) {
   131           assert(strlen(stlist->name)<sizeof lbl_default);
   132           strcpy(lbl_default,stlist->name);
   133         } else {
   134           statecount+=state_count(stlist->index);
   135         } /* if */
   136       } /* for */
   137       /* generate a stub entry for the functions */
   138       stgwrite("\tload.pri ");
   139       outval(fsa->value,FALSE);
   140       stgwrite("\t; ");
   141       stgwrite(sym->name);
   142       stgwrite("\n");
   143       code_idx+=opcodes(1)+opargs(1);   /* calculate code length */
   144       lbl_table=getlabel();
   145       ffswitch(lbl_table);
   146       /* generate the jump table */
   147       setlabel(lbl_table);
   148       ffcase(statecount,lbl_default,TRUE);
   149       for (state=sc_state_tab.next; state!=NULL; state=state->next) {
   150         if (state->index==fsa_id) {
   151           /* find the label for this list id */
   152           for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   153             if (stlist->index!=-1 && state_inlist(stlist->index,(int)state->value)) {
   154               ffcase(state->value,stlist->name,FALSE);
   155               break;
   156             } /* if */
   157           } /* for */
   158           if (stlist==NULL && strtol(lbl_default,NULL,16)==lbl_nostate)
   159             error(230,state->name,sym->name);  /* unimplemented state, no fallback */
   160         } /* if (state belongs to automaton of function) */
   161       } /* for (state) */
   162       stgwrite("\n");
   163     } /* if (is function, used & having states) */
   164   } /* for (sym) */
   165 }
   166 
   167 /*  writetrailer
   168  *  Not much left of this once important function.
   169  *
   170  *  Global references: pc_stksize       (referred to only)
   171  *                     sc_dataalign     (referred to only)
   172  *                     code_idx         (altered)
   173  *                     glb_declared     (altered)
   174  */
   175 SC_FUNC void writetrailer(void)
   176 {
   177   assert(sc_dataalign % opcodes(1) == 0);   /* alignment must be a multiple of
   178                                              * the opcode size */
   179   assert(sc_dataalign!=0);
   180 
   181   /* pad code to align data segment */
   182   if ((code_idx % sc_dataalign)!=0) {
   183     begcseg();
   184     while ((code_idx % sc_dataalign)!=0)
   185       nooperation();
   186   } /* if */
   187 
   188   /* pad data segment to align the stack and the heap */
   189   assert(litidx==0);            /* literal queue should have been emptied */
   190   assert(sc_dataalign % sizeof(cell) == 0);
   191   if (((glb_declared*sizeof(cell)) % sc_dataalign)!=0) {
   192     begdseg();
   193     defstorage();
   194     while (((glb_declared*sizeof(cell)) % sc_dataalign)!=0) {
   195       stgwrite("0 ");
   196       glb_declared++;
   197     } /* while */
   198   } /* if */
   199 
   200   stgwrite("\nSTKSIZE ");       /* write stack size (align stack top) */
   201   outval(pc_stksize - (pc_stksize % sc_dataalign), TRUE);
   202 }
   203 
   204 /*
   205  *  Start (or restart) the CODE segment.
   206  *
   207  *  In fact, the code and data segment specifiers are purely informational;
   208  *  the "DUMP" instruction itself already specifies that the following values
   209  *  should go to the data segment. All other instructions go to the code
   210  *  segment.
   211  *
   212  *  Global references: curseg
   213  *                     fcurrent
   214  */
   215 SC_FUNC void begcseg(void)
   216 {
   217   if (sc_status!=statSKIP && (curseg!=sIN_CSEG || fcurrent!=fcurseg)) {
   218     stgwrite("\n");
   219     stgwrite("CODE ");
   220     outval(fcurrent,FALSE);
   221     stgwrite("\t; ");
   222     outval(code_idx,TRUE);
   223     curseg=sIN_CSEG;
   224     fcurseg=fcurrent;
   225   } /* endif */
   226 }
   227 
   228 /*
   229  *  Start (or restart) the DATA segment.
   230  *
   231  *  Global references: curseg
   232  */
   233 SC_FUNC void begdseg(void)
   234 {
   235   if (sc_status!=statSKIP && (curseg!=sIN_DSEG || fcurrent!=fcurseg)) {
   236     stgwrite("\n");
   237     stgwrite("DATA ");
   238     outval(fcurrent,FALSE);
   239     stgwrite("\t; ");
   240     outval((glb_declared-litidx)*sizeof(cell),TRUE);
   241     curseg=sIN_DSEG;
   242     fcurseg=fcurrent;
   243   } /* if */
   244 }
   245 
   246 SC_FUNC void setline(int chkbounds)
   247 {
   248   if (sc_asmfile) {
   249     stgwrite("\t; line ");
   250     outval(fline,TRUE);
   251   } /* if */
   252   if ((sc_debug & sSYMBOLIC)!=0 || (chkbounds && (sc_debug & sCHKBOUNDS)!=0)) {
   253     /* generate a "break" (start statement) opcode rather than a "line" opcode
   254      * because earlier versions of Small/Pawn have an incompatible version of the
   255      * line opcode
   256      */
   257     stgwrite("\tbreak\t; ");
   258     outval(code_idx,TRUE);
   259     code_idx+=opcodes(1);
   260   } /* if */
   261 }
   262 
   263 SC_FUNC void setfiledirect(char *name)
   264 {
   265   if (sc_status==statFIRST && sc_listing) {
   266     assert(name!=NULL);
   267     pc_writeasm(outf,"#file ");
   268     pc_writeasm(outf,name);
   269     pc_writeasm(outf,"\n");
   270   } /* if */
   271 }
   272 
   273 SC_FUNC void setlinedirect(int line)
   274 {
   275   if (sc_status==statFIRST && sc_listing) {
   276     char string[40];
   277     sprintf(string,"#line %d\n",line);
   278     pc_writeasm(outf,string);
   279   } /* if */
   280 }
   281 
   282 /*  setlabel
   283  *
   284  *  Post a code label (specified as a number), on a new line.
   285  */
   286 SC_FUNC void setlabel(int number)
   287 {
   288   assert(number>=0);
   289   stgwrite("l.");
   290   stgwrite((char *)itoh(number));
   291   /* To assist verification of the assembled code, put the address of the
   292    * label as a comment. However, labels that occur inside an expression
   293    * may move (through optimization or through re-ordering). So write the
   294    * address only if it is known to accurate.
   295    */
   296   if (!staging) {
   297     stgwrite("\t\t; ");
   298     outval(code_idx,FALSE);
   299   } /* if */
   300   stgwrite("\n");
   301 }
   302 
   303 /* Write a token that signifies the start or end of an expression or special
   304  * statement. This allows several simple optimizations by the peephole
   305  * optimizer.
   306  */
   307 SC_FUNC void markexpr(optmark type,const char *name,cell offset)
   308 {
   309   switch (type) {
   310   case sEXPR:
   311     stgwrite("\t;$exp\n");
   312     break;
   313   case sPARM:
   314     stgwrite("\t;$par\n");
   315     break;
   316   case sLDECL:
   317     assert(name!=NULL);
   318     stgwrite("\t;$lcl ");
   319     stgwrite(name);
   320     stgwrite(" ");
   321     outval(offset,TRUE);
   322     break;
   323   default:
   324     assert(0);
   325   } /* switch */
   326 }
   327 
   328 /*  startfunc   - declare a CODE entry point (function start)
   329  *
   330  *  Global references: funcstatus  (referred to only)
   331  */
   332 SC_FUNC void startfunc(char *fname)
   333 {
   334   stgwrite("\tproc");
   335   if (sc_asmfile) {
   336     char symname[2*sNAMEMAX+16];
   337     funcdisplayname(symname,fname);
   338     stgwrite("\t; ");
   339     stgwrite(symname);
   340   } /* if */
   341   stgwrite("\n");
   342   code_idx+=opcodes(1);
   343 }
   344 
   345 /*  endfunc
   346  *
   347  *  Declare a CODE ending point (function end)
   348  */
   349 SC_FUNC void endfunc(void)
   350 {
   351   stgwrite("\n");       /* skip a line */
   352 }
   353 
   354 /*  alignframe
   355  *
   356  *  Aligns the frame (and the stack) of the current function to a multiple
   357  *  of the specified byte count. Two caveats: the alignment ("numbytes") should
   358  *  be a power of 2, and this alignment must be done right after the frame
   359  *  is set up (before the first variable is declared)
   360  */
   361 SC_FUNC void alignframe(int numbytes)
   362 {
   363   #if !defined NDEBUG
   364     /* "numbytes" should be a power of 2 for this code to work */
   365     int i,count=0;
   366     for (i=0; i<sizeof numbytes*8; i++)
   367       if (numbytes & (1 << i))
   368         count++;
   369     assert(count==1);
   370   #endif
   371 
   372   stgwrite("\tlctrl 4\n");      /* get STK in PRI */
   373   stgwrite("\tconst.alt ");     /* get ~(numbytes-1) in ALT */
   374   outval(~(numbytes-1),TRUE);
   375   stgwrite("\tand\n");          /* PRI = STK "and" ~(numbytes-1) */
   376   stgwrite("\tsctrl 4\n");      /* set the new value of STK ... */
   377   stgwrite("\tsctrl 5\n");      /* ... and FRM */
   378   code_idx+=opcodes(5)+opargs(4);
   379 }
   380 
   381 /*  rvalue
   382  *
   383  *  Generate code to get the value of a symbol into "primary".
   384  */
   385 SC_FUNC void rvalue(value *lval)
   386 {
   387   symbol *sym;
   388 
   389   sym=lval->sym;
   390   if (lval->ident==iARRAYCELL) {
   391     /* indirect fetch, address already in PRI */
   392     stgwrite("\tload.i\n");
   393     code_idx+=opcodes(1);
   394   } else if (lval->ident==iARRAYCHAR) {
   395     /* indirect fetch of a character from a pack, address already in PRI */
   396     stgwrite("\tlodb.i ");
   397     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
   398     code_idx+=opcodes(1)+opargs(1);
   399   } else if (lval->ident==iREFERENCE) {
   400     /* indirect fetch, but address not yet in PRI */
   401     assert(sym!=NULL);
   402     assert(sym->vclass==sLOCAL);/* global references don't exist in Pawn */
   403     if (sym->vclass==sLOCAL)
   404       stgwrite("\tlref.s.pri ");
   405     else
   406       stgwrite("\tlref.pri ");
   407     outval(sym->addr,TRUE);
   408     markusage(sym,uREAD);
   409     code_idx+=opcodes(1)+opargs(1);
   410   } else {
   411     /* direct or stack relative fetch */
   412     assert(sym!=NULL);
   413     if (sym->vclass==sLOCAL)
   414       stgwrite("\tload.s.pri ");
   415     else
   416       stgwrite("\tload.pri ");
   417     outval(sym->addr,TRUE);
   418     markusage(sym,uREAD);
   419     code_idx+=opcodes(1)+opargs(1);
   420   } /* if */
   421 }
   422 
   423 /* Get the address of a symbol into the primary or alternate register (used
   424  * for arrays, and for passing arguments by reference).
   425  */
   426 SC_FUNC void address(symbol *sym,regid reg)
   427 {
   428   assert(sym!=NULL);
   429   assert(reg==sPRI || reg==sALT);
   430   /* the symbol can be a local array, a global array, or an array
   431    * that is passed by reference.
   432    */
   433   if (sym->ident==iREFARRAY || sym->ident==iREFERENCE) {
   434     /* reference to a variable or to an array; currently this is
   435      * always a local variable */
   436     switch (reg) {
   437     case sPRI:
   438       stgwrite("\tload.s.pri ");
   439       break;
   440     case sALT:
   441       stgwrite("\tload.s.alt ");
   442       break;
   443     } /* switch */
   444   } else {
   445     /* a local array or local variable */
   446     switch (reg) {
   447     case sPRI:
   448       if (sym->vclass==sLOCAL)
   449         stgwrite("\taddr.pri ");
   450       else
   451         stgwrite("\tconst.pri ");
   452       break;
   453     case sALT:
   454       if (sym->vclass==sLOCAL)
   455         stgwrite("\taddr.alt ");
   456       else
   457         stgwrite("\tconst.alt ");
   458       break;
   459     } /* switch */
   460   } /* if */
   461   outval(sym->addr,TRUE);
   462   markusage(sym,uREAD);
   463   code_idx+=opcodes(1)+opargs(1);
   464 }
   465 
   466 /*  store
   467  *
   468  *  Saves the contents of "primary" into a memory cell, either directly
   469  *  or indirectly (at the address given in the alternate register).
   470  */
   471 SC_FUNC void store(value *lval)
   472 {
   473   symbol *sym;
   474 
   475   sym=lval->sym;
   476   if (lval->ident==iARRAYCELL) {
   477     /* store at address in ALT */
   478     stgwrite("\tstor.i\n");
   479     code_idx+=opcodes(1);
   480   } else if (lval->ident==iARRAYCHAR) {
   481     /* store at address in ALT */
   482     stgwrite("\tstrb.i ");
   483     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
   484     code_idx+=opcodes(1)+opargs(1);
   485   } else if (lval->ident==iREFERENCE) {
   486     assert(sym!=NULL);
   487     if (sym->vclass==sLOCAL)
   488       stgwrite("\tsref.s.pri ");
   489     else
   490       stgwrite("\tsref.pri ");
   491     outval(sym->addr,TRUE);
   492     code_idx+=opcodes(1)+opargs(1);
   493   } else {
   494     assert(sym!=NULL);
   495     markusage(sym,uWRITTEN);
   496     if (sym->vclass==sLOCAL)
   497       stgwrite("\tstor.s.pri ");
   498     else
   499       stgwrite("\tstor.pri ");
   500     outval(sym->addr,TRUE);
   501     code_idx+=opcodes(1)+opargs(1);
   502   } /* if */
   503 }
   504 
   505 /* Get a cell from a fixed address in memory */
   506 SC_FUNC void loadreg(cell address,regid reg)
   507 {
   508   assert(reg==sPRI || reg==sALT);
   509   if (reg==sPRI)
   510     stgwrite("\tload.pri ");
   511   else
   512     stgwrite("\tload.alt ");
   513   outval(address,TRUE);
   514   code_idx+=opcodes(1)+opargs(1);
   515 }
   516 
   517 /* Store a cell into a fixed address in memory */
   518 SC_FUNC void storereg(cell address,regid reg)
   519 {
   520   assert(reg==sPRI || reg==sALT);
   521   if (reg==sPRI)
   522     stgwrite("\tstor.pri ");
   523   else
   524     stgwrite("\tstor.alt ");
   525   outval(address,TRUE);
   526   code_idx+=opcodes(1)+opargs(1);
   527 }
   528 
   529 /* source must in PRI, destination address in ALT. The "size"
   530  * parameter is in bytes, not cells.
   531  */
   532 SC_FUNC void memcopy(cell size)
   533 {
   534   stgwrite("\tmovs ");
   535   outval(size,TRUE);
   536 
   537   code_idx+=opcodes(1)+opargs(1);
   538 }
   539 
   540 /* Address of the source must already have been loaded in PRI
   541  * "size" is the size in bytes (not cells).
   542  */
   543 SC_FUNC void copyarray(symbol *sym,cell size)
   544 {
   545   assert(sym!=NULL);
   546   /* the symbol can be a local array, a global array, or an array
   547    * that is passed by reference.
   548    */
   549   if (sym->ident==iREFARRAY) {
   550     /* reference to an array; currently this is always a local variable */
   551     assert(sym->vclass==sLOCAL);        /* symbol must be stack relative */
   552     stgwrite("\tload.s.alt ");
   553   } else {
   554     /* a local or global array */
   555     if (sym->vclass==sLOCAL)
   556       stgwrite("\taddr.alt ");
   557     else
   558       stgwrite("\tconst.alt ");
   559   } /* if */
   560   outval(sym->addr,TRUE);
   561   markusage(sym,uWRITTEN);
   562 
   563   code_idx+=opcodes(1)+opargs(1);
   564   memcopy(size);
   565 }
   566 
   567 SC_FUNC void fillarray(symbol *sym,cell size,cell value)
   568 {
   569   ldconst(value,sPRI);  /* load value in PRI */
   570 
   571   assert(sym!=NULL);
   572   /* the symbol can be a local array, a global array, or an array
   573    * that is passed by reference.
   574    */
   575   if (sym->ident==iREFARRAY) {
   576     /* reference to an array; currently this is always a local variable */
   577     assert(sym->vclass==sLOCAL);        /* symbol must be stack relative */
   578     stgwrite("\tload.s.alt ");
   579   } else {
   580     /* a local or global array */
   581     if (sym->vclass==sLOCAL)
   582       stgwrite("\taddr.alt ");
   583     else
   584       stgwrite("\tconst.alt ");
   585   } /* if */
   586   outval(sym->addr,TRUE);
   587   markusage(sym,uWRITTEN);
   588 
   589   assert(size>0);
   590   stgwrite("\tfill ");
   591   outval(size,TRUE);
   592 
   593   code_idx+=opcodes(2)+opargs(2);
   594 }
   595 
   596 SC_FUNC void stradjust(regid reg)
   597 {
   598   assert(reg==sPRI);
   599   stgwrite("\tstradjust.pri\n");
   600   code_idx+=opcodes(1);
   601 }
   602 
   603 /* Instruction to get an immediate value into the primary or the alternate
   604  * register
   605  */
   606 SC_FUNC void ldconst(cell val,regid reg)
   607 {
   608   assert(reg==sPRI || reg==sALT);
   609   switch (reg) {
   610   case sPRI:
   611     if (val==0) {
   612       stgwrite("\tzero.pri\n");
   613       code_idx+=opcodes(1);
   614     } else {
   615       stgwrite("\tconst.pri ");
   616       outval(val, TRUE);
   617       code_idx+=opcodes(1)+opargs(1);
   618     } /* if */
   619     break;
   620   case sALT:
   621     if (val==0) {
   622       stgwrite("\tzero.alt\n");
   623       code_idx+=opcodes(1);
   624     } else {
   625       stgwrite("\tconst.alt ");
   626       outval(val, TRUE);
   627       code_idx+=opcodes(1)+opargs(1);
   628     } /* if */
   629     break;
   630   } /* switch */
   631 }
   632 
   633 /* Copy value in alternate register to the primary register */
   634 SC_FUNC void moveto1(void)
   635 {
   636   stgwrite("\tmove.pri\n");
   637   code_idx+=opcodes(1)+opargs(0);
   638 }
   639 
   640 /* Push primary or the alternate register onto the stack
   641  */
   642 SC_FUNC void pushreg(regid reg)
   643 {
   644   assert(reg==sPRI || reg==sALT);
   645   switch (reg) {
   646   case sPRI:
   647     stgwrite("\tpush.pri\n");
   648     break;
   649   case sALT:
   650     stgwrite("\tpush.alt\n");
   651     break;
   652   } /* switch */
   653   code_idx+=opcodes(1);
   654 }
   655 
   656 /*
   657  *  Push a constant value onto the stack
   658  */
   659 SC_FUNC void pushval(cell val)
   660 {
   661   stgwrite("\tpush.c ");
   662   outval(val, TRUE);
   663   code_idx+=opcodes(1)+opargs(1);
   664 }
   665 
   666 /* Pop stack into the primary or the alternate register
   667  */
   668 SC_FUNC void popreg(regid reg)
   669 {
   670   assert(reg==sPRI || reg==sALT);
   671   switch (reg) {
   672   case sPRI:
   673     stgwrite("\tpop.pri\n");
   674     break;
   675   case sALT:
   676     stgwrite("\tpop.alt\n");
   677     break;
   678   } /* switch */
   679   code_idx+=opcodes(1);
   680 }
   681 
   682 /*
   683  * Generate an array
   684  */
   685 SC_FUNC void genarray(int dims, int _autozero)
   686 {
   687   if (_autozero) {
   688     stgwrite("\tgenarray.z ");
   689   } else {
   690     stgwrite("\tgenarray ");
   691   }
   692   outval(dims, TRUE);
   693   code_idx+=opcodes(1)+opargs(1);
   694 }
   695 
   696 /*
   697  *  swap the top-of-stack with the value in primary register
   698  */
   699 SC_FUNC void swap1(void)
   700 {
   701   stgwrite("\tswap.pri\n");
   702   code_idx+=opcodes(1);
   703 }
   704 
   705 /* Switch statements
   706  * The "switch" statement generates a "case" table using the "CASE" opcode.
   707  * The case table contains a list of records, each record holds a comparison
   708  * value and a label to branch to on a match. The very first record is an
   709  * exception: it holds the size of the table (excluding the first record) and
   710  * the label to branch to when none of the values in the case table match.
   711  * The case table is sorted on the comparison value. This allows more advanced
   712  * abstract machines to sift the case table with a binary search.
   713  */
   714 SC_FUNC void ffswitch(int label)
   715 {
   716   stgwrite("\tswitch ");
   717   outval(label,TRUE);           /* the label is the address of the case table */
   718   code_idx+=opcodes(1)+opargs(1);
   719 }
   720 
   721 SC_FUNC void ffcase(cell value,char *labelname,int newtable)
   722 {
   723   if (newtable) {
   724     stgwrite("\tcasetbl\n");
   725     code_idx+=opcodes(1);
   726   } /* if */
   727   stgwrite("\tcase ");
   728   outval(value,FALSE);
   729   stgwrite(" ");
   730   stgwrite(labelname);
   731   stgwrite("\n");
   732   code_idx+=opcodes(0)+opargs(2);
   733 }
   734 
   735 /*
   736  *  Call specified function
   737  */
   738 SC_FUNC void ffcall(symbol *sym,const char *label,int numargs)
   739 {
   740   char symname[2*sNAMEMAX+16];
   741   char aliasname[sNAMEMAX+1];
   742   int wasAlias = 0;
   743 
   744   assert(sym!=NULL);
   745   assert(sym->ident==iFUNCTN);
   746   if (sc_asmfile)
   747     funcdisplayname(symname,sym->name);
   748   if ((sym->usage & uNATIVE)!=0) {
   749     /* reserve a SYSREQ id if called for the first time */
   750     assert(label==NULL);
   751     stgwrite("\tsysreq.c ");
   752     if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0)
   753       sym->addr=ntv_funcid++;
   754     /* Look for an alias */
   755     if (lookup_alias(aliasname, sym->name)) {
   756       symbol *asym = findglb(aliasname, sGLOBAL);
   757       if (asym && asym->ident==iFUNCTN && ((sym->usage & uNATIVE) != 0)) {
   758         sym = asym;
   759         if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) {
   760           sym->addr=ntv_funcid++;
   761           markusage(sym, uREAD);
   762         }
   763       }
   764     }
   765     outval(sym->addr,FALSE);
   766     if (sc_asmfile) {
   767       stgwrite("\t; ");
   768       stgwrite(symname);
   769     } /* if */
   770     stgwrite("\n"); /* write on a separate line, to mark a sequence point for the peephole optimizer */
   771     stgwrite("\tstack ");
   772     outval((numargs+1)*sizeof(cell), TRUE);
   773     code_idx+=opcodes(2)+opargs(2);
   774   } else {
   775     /* normal function */
   776     stgwrite("\tcall ");
   777     if (label!=NULL) {
   778       stgwrite("l.");
   779       stgwrite(label);
   780     } else {
   781       stgwrite(sym->name);
   782     } /* if */
   783     if (sc_asmfile
   784         && (label!=NULL || (!isalpha(sym->name[0]) && sym->name[0]!='_'  && sym->name[0]!=sc_ctrlchar)))
   785     {
   786       stgwrite("\t; ");
   787       stgwrite(symname);
   788     } /* if */
   789     stgwrite("\n");
   790     code_idx+=opcodes(1)+opargs(1);
   791   } /* if */
   792 }
   793 
   794 /*  Return from function
   795  *
   796  *  Global references: funcstatus  (referred to only)
   797  */
   798 SC_FUNC void ffret(int remparams)
   799 {
   800   if (remparams)
   801     stgwrite("\tretn\n");
   802   else
   803     stgwrite("\tret\n");
   804   code_idx+=opcodes(1);
   805 }
   806 
   807 SC_FUNC void ffabort(int reason)
   808 {
   809   stgwrite("\thalt ");
   810   outval(reason,TRUE);
   811   code_idx+=opcodes(1)+opargs(1);
   812 }
   813 
   814 SC_FUNC void ffbounds(cell size)
   815 {
   816   if ((sc_debug & sCHKBOUNDS)!=0) {
   817     stgwrite("\tbounds ");
   818     outval(size,TRUE);
   819     code_idx+=opcodes(1)+opargs(1);
   820   } /* if */
   821 }
   822 
   823 /*
   824  *  Jump to local label number (the number is converted to a name)
   825  */
   826 SC_FUNC void jumplabel(int number)
   827 {
   828   stgwrite("\tjump ");
   829   outval(number,TRUE);
   830   code_idx+=opcodes(1)+opargs(1);
   831 }
   832 
   833 /*
   834  *   Define storage (global and static variables)
   835  */
   836 SC_FUNC void defstorage(void)
   837 {
   838   stgwrite("dump ");
   839 }
   840 
   841 /*
   842  *  Inclrement/decrement stack pointer. Note that this routine does
   843  *  nothing if the delta is zero.
   844  */
   845 SC_FUNC void modstk(int delta)
   846 {
   847   if (delta) {
   848     stgwrite("\tstack ");
   849     outval(delta, TRUE);
   850     code_idx+=opcodes(1)+opargs(1);
   851   } /* if */
   852 }
   853 
   854 /* set the stack to a hard offset from the frame */
   855 SC_FUNC void setstk(cell value)
   856 {
   857   stgwrite("\tstackadjust ");
   858   assert(value<=0);             /* STK should always become <= FRM */
   859   outval(value, TRUE);        /* add (negative) offset */
   860   code_idx+=opcodes(1)+opargs(1);
   861 }
   862 
   863 SC_FUNC void modheap(int delta)
   864 {
   865   if (delta) {
   866     stgwrite("\theap ");
   867     outval(delta, TRUE);
   868     code_idx+=opcodes(1)+opargs(1);
   869   } /* if */
   870 }
   871 
   872 SC_FUNC void modheap_i()
   873 {
   874   stgwrite("\ttracker.pop.setheap\n");
   875   code_idx+=opcodes(1);
   876 }
   877 
   878 SC_FUNC void setheap_save(cell value)
   879 {
   880   assert(value);
   881   stgwrite("\ttracker.push.c ");
   882   outval(value, TRUE);
   883   code_idx+=opcodes(1)+opargs(1);
   884 }
   885 
   886 SC_FUNC void setheap_pri(void)
   887 {
   888   stgwrite("\theap ");          /* ALT = HEA++ */
   889   outval(sizeof(cell), TRUE);
   890   stgwrite("\tstor.i\n");       /* store PRI (default value) at address ALT */
   891   stgwrite("\tmove.pri\n");     /* move ALT to PRI: PRI contains the address */
   892   code_idx+=opcodes(3)+opargs(1);
   893 }
   894 
   895 SC_FUNC void setheap(cell value)
   896 {
   897   stgwrite("\tconst.pri ");     /* load default value in PRI */
   898   outval(value, TRUE);
   899   code_idx+=opcodes(1)+opargs(1);
   900   setheap_pri();
   901 }
   902 
   903 /*
   904  *  Convert a cell number to a "byte" address; i.e. double or quadruple
   905  *  the primary register.
   906  */
   907 SC_FUNC void cell2addr(void)
   908 {
   909   #if PAWN_CELL_SIZE==16
   910     stgwrite("\tshl.c.pri 1\n");
   911   #elif PAWN_CELL_SIZE==32
   912     stgwrite("\tshl.c.pri 2\n");
   913   #elif PAWN_CELL_SIZE==64
   914     stgwrite("\tshl.c.pri 3\n");
   915   #else
   916     #error Unsupported cell size
   917   #endif
   918   code_idx+=opcodes(1)+opargs(1);
   919 }
   920 
   921 /*
   922  *  Double or quadruple the alternate register.
   923  */
   924 SC_FUNC void cell2addr_alt(void)
   925 {
   926   #if PAWN_CELL_SIZE==16
   927     stgwrite("\tshl.c.alt 1\n");
   928   #elif PAWN_CELL_SIZE==32
   929     stgwrite("\tshl.c.alt 2\n");
   930   #elif PAWN_CELL_SIZE==64
   931     stgwrite("\tshl.c.alt 3\n");
   932   #else
   933     #error Unsupported cell size
   934   #endif
   935   code_idx+=opcodes(1)+opargs(1);
   936 }
   937 
   938 /*
   939  *  Convert "distance of addresses" to "number of cells" in between.
   940  *  Or convert a number of packed characters to the number of cells (with
   941  *  truncation).
   942  */
   943 SC_FUNC void addr2cell(void)
   944 {
   945   #if PAWN_CELL_SIZE==16
   946     stgwrite("\tshr.c.pri 1\n");
   947   #elif PAWN_CELL_SIZE==32
   948     stgwrite("\tshr.c.pri 2\n");
   949   #elif PAWN_CELL_SIZE==64
   950     stgwrite("\tshr.c.pri 3\n");
   951   #else
   952     #error Unsupported cell size
   953   #endif
   954   code_idx+=opcodes(1)+opargs(1);
   955 }
   956 
   957 /* Convert from character index to byte address. This routine does
   958  * nothing if a character has the size of a byte.
   959  */
   960 SC_FUNC void char2addr(void)
   961 {
   962   #if sCHARBITS==16
   963     stgwrite("\tshl.c.pri 1\n");
   964     code_idx+=opcodes(1)+opargs(1);
   965   #endif
   966 }
   967 
   968 /* Align PRI (which should hold a character index) to an address.
   969  * The first character in a "pack" occupies the highest bits of
   970  * the cell. This is at the lower memory address on Big Endian
   971  * computers and on the higher address on Little Endian computers.
   972  * The ALIGN.pri/alt instructions must solve this machine dependence;
   973  * that is, on Big Endian computers, ALIGN.pri/alt shuold do nothing
   974  * and on Little Endian computers they should toggle the address.
   975  *
   976  * NOTE: For Source Pawn, this is fliped.  It will do nothing on Little-Endian.
   977  */
   978 SC_FUNC void charalign(void)
   979 {
   980 #if 0	/* TEMPORARILY DISABLED BECAUSE WE DON'T USE BIG ENDIAN */
   981   stgwrite("\talign.pri ");
   982   outval(sCHARBITS/8,TRUE);
   983   code_idx+=opcodes(1)+opargs(1);
   984 #endif
   985 }
   986 
   987 /*
   988  *  Add a constant to the primary register.
   989  */
   990 SC_FUNC void addconst(cell value)
   991 {
   992   if (value!=0) {
   993     stgwrite("\tadd.c ");
   994     outval(value,TRUE);
   995     code_idx+=opcodes(1)+opargs(1);
   996   } /* if */
   997 }
   998 
   999 /*
  1000  *  signed multiply of primary and secundairy registers (result in primary)
  1001  */
  1002 SC_FUNC void os_mult(void)
  1003 {
  1004   stgwrite("\tsmul\n");
  1005   code_idx+=opcodes(1);
  1006 }
  1007 
  1008 /*
  1009  *  signed divide of alternate register by primary register (quotient in
  1010  *  primary; remainder in alternate)
  1011  */
  1012 SC_FUNC void os_div(void)
  1013 {
  1014   stgwrite("\tsdiv.alt\n");
  1015   code_idx+=opcodes(1);
  1016 }
  1017 
  1018 /*
  1019  *  modulus of (alternate % primary), result in primary (signed)
  1020  */
  1021 SC_FUNC void os_mod(void)
  1022 {
  1023   stgwrite("\tsdiv.alt\n");
  1024   stgwrite("\tmove.pri\n");     /* move ALT to PRI */
  1025   code_idx+=opcodes(2);
  1026 }
  1027 
  1028 /*
  1029  *  Add primary and alternate registers (result in primary).
  1030  */
  1031 SC_FUNC void ob_add(void)
  1032 {
  1033   stgwrite("\tadd\n");
  1034   code_idx+=opcodes(1);
  1035 }
  1036 
  1037 /*
  1038  *  subtract primary register from alternate register (result in primary)
  1039  */
  1040 SC_FUNC void ob_sub(void)
  1041 {
  1042   stgwrite("\tsub.alt\n");
  1043   code_idx+=opcodes(1);
  1044 }
  1045 
  1046 /*
  1047  *  arithmic shift left alternate register the number of bits
  1048  *  given in the primary register (result in primary).
  1049  *  There is no need for a "logical shift left" routine, since
  1050  *  logical shift left is identical to arithmic shift left.
  1051  */
  1052 SC_FUNC void ob_sal(void)
  1053 {
  1054   stgwrite("\txchg\n");
  1055   stgwrite("\tshl\n");
  1056   code_idx+=opcodes(2);
  1057 }
  1058 
  1059 /*
  1060  *  arithmic shift right alternate register the number of bits
  1061  *  given in the primary register (result in primary).
  1062  */
  1063 SC_FUNC void os_sar(void)
  1064 {
  1065   stgwrite("\txchg\n");
  1066   stgwrite("\tsshr\n");
  1067   code_idx+=opcodes(2);
  1068 }
  1069 
  1070 /*
  1071  *  logical (unsigned) shift right of the alternate register by the
  1072  *  number of bits given in the primary register (result in primary).
  1073  */
  1074 SC_FUNC void ou_sar(void)
  1075 {
  1076   stgwrite("\txchg\n");
  1077   stgwrite("\tshr\n");
  1078   code_idx+=opcodes(2);
  1079 }
  1080 
  1081 /*
  1082  *  inclusive "or" of primary and alternate registers (result in primary)
  1083  */
  1084 SC_FUNC void ob_or(void)
  1085 {
  1086   stgwrite("\tor\n");
  1087   code_idx+=opcodes(1);
  1088 }
  1089 
  1090 /*
  1091  *  "exclusive or" of primary and alternate registers (result in primary)
  1092  */
  1093 SC_FUNC void ob_xor(void)
  1094 {
  1095   stgwrite("\txor\n");
  1096   code_idx+=opcodes(1);
  1097 }
  1098 
  1099 /*
  1100  *  "and" of primary and secundairy registers (result in primary)
  1101  */
  1102 SC_FUNC void ob_and(void)
  1103 {
  1104   stgwrite("\tand\n");
  1105   code_idx+=opcodes(1);
  1106 }
  1107 
  1108 /*
  1109  *  test ALT==PRI; result in primary register (1 or 0).
  1110  */
  1111 SC_FUNC void ob_eq(void)
  1112 {
  1113   stgwrite("\teq\n");
  1114   code_idx+=opcodes(1);
  1115 }
  1116 
  1117 /*
  1118  *  test ALT!=PRI
  1119  */
  1120 SC_FUNC void ob_ne(void)
  1121 {
  1122   stgwrite("\tneq\n");
  1123   code_idx+=opcodes(1);
  1124 }
  1125 
  1126 /* The abstract machine defines the relational instructions so that PRI is
  1127  * on the left side and ALT on the right side of the operator. For example,
  1128  * SLESS sets PRI to either 1 or 0 depending on whether the expression
  1129  * "PRI < ALT" is true.
  1130  *
  1131  * The compiler generates comparisons with ALT on the left side of the
  1132  * relational operator and PRI on the right side. The XCHG instruction
  1133  * prefixing the relational operators resets this. We leave it to the
  1134  * peephole optimizer to choose more compact instructions where possible.
  1135  */
  1136 
  1137 /* Relational operator prefix for chained relational expressions. The
  1138  * "suffix" code restores the stack.
  1139  * For chained relational operators, the goal is to keep the comparison
  1140  * result "so far" in PRI and the value of the most recent operand in
  1141  * ALT, ready for a next comparison.
  1142  * The "prefix" instruction pushed the comparison result (PRI) onto the
  1143  * stack and moves the value of ALT into PRI. If there is a next comparison,
  1144  * PRI can now serve as the "left" operand of the relational operator.
  1145  */
  1146 SC_FUNC void relop_prefix(void)
  1147 {
  1148   stgwrite("\tpush.pri\n");
  1149   stgwrite("\tmove.pri\n");
  1150   code_idx+=opcodes(2);
  1151 }
  1152 
  1153 SC_FUNC void relop_suffix(void)
  1154 {
  1155   stgwrite("\tswap.alt\n");
  1156   stgwrite("\tand\n");
  1157   stgwrite("\tpop.alt\n");
  1158   code_idx+=opcodes(3);
  1159 }
  1160 
  1161 /*
  1162  *  test ALT<PRI (signed)
  1163  */
  1164 SC_FUNC void os_lt(void)
  1165 {
  1166   stgwrite("\txchg\n");
  1167   stgwrite("\tsless\n");
  1168   code_idx+=opcodes(2);
  1169 }
  1170 
  1171 /*
  1172  *  test ALT<=PRI (signed)
  1173  */
  1174 SC_FUNC void os_le(void)
  1175 {
  1176   stgwrite("\txchg\n");
  1177   stgwrite("\tsleq\n");
  1178   code_idx+=opcodes(2);
  1179 }
  1180 
  1181 /*
  1182  *  test ALT>PRI (signed)
  1183  */
  1184 SC_FUNC void os_gt(void)
  1185 {
  1186   stgwrite("\txchg\n");
  1187   stgwrite("\tsgrtr\n");
  1188   code_idx+=opcodes(2);
  1189 }
  1190 
  1191 /*
  1192  *  test ALT>=PRI (signed)
  1193  */
  1194 SC_FUNC void os_ge(void)
  1195 {
  1196   stgwrite("\txchg\n");
  1197   stgwrite("\tsgeq\n");
  1198   code_idx+=opcodes(2);
  1199 }
  1200 
  1201 /*
  1202  *  logical negation of primary register
  1203  */
  1204 SC_FUNC void lneg(void)
  1205 {
  1206   stgwrite("\tnot\n");
  1207   code_idx+=opcodes(1);
  1208 }
  1209 
  1210 /*
  1211  *  two's complement primary register
  1212  */
  1213 SC_FUNC void neg(void)
  1214 {
  1215   stgwrite("\tneg\n");
  1216   code_idx+=opcodes(1);
  1217 }
  1218 
  1219 /*
  1220  *  one's complement of primary register
  1221  */
  1222 SC_FUNC void invert(void)
  1223 {
  1224   stgwrite("\tinvert\n");
  1225   code_idx+=opcodes(1);
  1226 }
  1227 
  1228 /*
  1229  *  nop
  1230  */
  1231 SC_FUNC void nooperation(void)
  1232 {
  1233   stgwrite("\tnop\n");
  1234   code_idx+=opcodes(1);
  1235 }
  1236 
  1237 
  1238 /*  increment symbol
  1239  */
  1240 SC_FUNC void inc(value *lval)
  1241 {
  1242   symbol *sym;
  1243 
  1244   sym=lval->sym;
  1245   if (lval->ident==iARRAYCELL) {
  1246     /* indirect increment, address already in PRI */
  1247     stgwrite("\tinc.i\n");
  1248     code_idx+=opcodes(1);
  1249   } else if (lval->ident==iARRAYCHAR) {
  1250     /* indirect increment of single character, address already in PRI */
  1251     stgwrite("\tpush.pri\n");
  1252     stgwrite("\tpush.alt\n");
  1253     stgwrite("\tmove.alt\n");   /* copy address */
  1254     stgwrite("\tlodb.i ");      /* read from PRI into PRI */
  1255     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
  1256     stgwrite("\tinc.pri\n");
  1257     stgwrite("\tstrb.i ");      /* write PRI to ALT */
  1258     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
  1259     stgwrite("\tpop.alt\n");
  1260     stgwrite("\tpop.pri\n");
  1261     code_idx+=opcodes(8)+opargs(2);
  1262   } else if (lval->ident==iREFERENCE) {
  1263     assert(sym!=NULL);
  1264     stgwrite("\tpush.pri\n");
  1265     /* load dereferenced value */
  1266     assert(sym->vclass==sLOCAL);    /* global references don't exist in Pawn */
  1267     if (sym->vclass==sLOCAL)
  1268       stgwrite("\tlref.s.pri ");
  1269     else
  1270       stgwrite("\tlref.pri ");
  1271     outval(sym->addr,TRUE);
  1272     /* increment */
  1273     stgwrite("\tinc.pri\n");
  1274     /* store dereferenced value */
  1275     if (sym->vclass==sLOCAL)
  1276       stgwrite("\tsref.s.pri ");
  1277     else
  1278       stgwrite("\tsref.pri ");
  1279     outval(sym->addr,TRUE);
  1280     stgwrite("\tpop.pri\n");
  1281     code_idx+=opcodes(5)+opargs(2);
  1282   } else {
  1283     /* local or global variable */
  1284     assert(sym!=NULL);
  1285     if (sym->vclass==sLOCAL)
  1286       stgwrite("\tinc.s ");
  1287     else
  1288       stgwrite("\tinc ");
  1289     outval(sym->addr,TRUE);
  1290     code_idx+=opcodes(1)+opargs(1);
  1291   } /* if */
  1292 }
  1293 
  1294 /*  decrement symbol
  1295  *
  1296  *  in case of an integer pointer, the symbol must be incremented by 2.
  1297  */
  1298 SC_FUNC void dec(value *lval)
  1299 {
  1300   symbol *sym;
  1301 
  1302   sym=lval->sym;
  1303   if (lval->ident==iARRAYCELL) {
  1304     /* indirect decrement, address already in PRI */
  1305     stgwrite("\tdec.i\n");
  1306     code_idx+=opcodes(1);
  1307   } else if (lval->ident==iARRAYCHAR) {
  1308     /* indirect decrement of single character, address already in PRI */
  1309     stgwrite("\tpush.pri\n");
  1310     stgwrite("\tpush.alt\n");
  1311     stgwrite("\tmove.alt\n");   /* copy address */
  1312     stgwrite("\tlodb.i ");      /* read from PRI into PRI */
  1313     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
  1314     stgwrite("\tdec.pri\n");
  1315     stgwrite("\tstrb.i ");      /* write PRI to ALT */
  1316     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
  1317     stgwrite("\tpop.alt\n");
  1318     stgwrite("\tpop.pri\n");
  1319     code_idx+=opcodes(8)+opargs(2);
  1320   } else if (lval->ident==iREFERENCE) {
  1321     assert(sym!=NULL);
  1322     stgwrite("\tpush.pri\n");
  1323     /* load dereferenced value */
  1324     assert(sym->vclass==sLOCAL);    /* global references don't exist in Pawn */
  1325     if (sym->vclass==sLOCAL)
  1326       stgwrite("\tlref.s.pri ");
  1327     else
  1328       stgwrite("\tlref.pri ");
  1329     outval(sym->addr,TRUE);
  1330     /* decrement */
  1331     stgwrite("\tdec.pri\n");
  1332     /* store dereferenced value */
  1333     if (sym->vclass==sLOCAL)
  1334       stgwrite("\tsref.s.pri ");
  1335     else
  1336       stgwrite("\tsref.pri ");
  1337     outval(sym->addr,TRUE);
  1338     stgwrite("\tpop.pri\n");
  1339     code_idx+=opcodes(5)+opargs(2);
  1340   } else {
  1341     /* local or global variable */
  1342     assert(sym!=NULL);
  1343     if (sym->vclass==sLOCAL)
  1344       stgwrite("\tdec.s ");
  1345     else
  1346       stgwrite("\tdec ");
  1347     outval(sym->addr,TRUE);
  1348     code_idx+=opcodes(1)+opargs(1);
  1349   } /* if */
  1350 }
  1351 
  1352 /*
  1353  *  Jumps to "label" if PRI != 0
  1354  */
  1355 SC_FUNC void jmp_ne0(int number)
  1356 {
  1357   stgwrite("\tjnz ");
  1358   outval(number,TRUE);
  1359   code_idx+=opcodes(1)+opargs(1);
  1360 }
  1361 
  1362 /*
  1363  *  Jumps to "label" if PRI == 0
  1364  */
  1365 SC_FUNC void jmp_eq0(int number)
  1366 {
  1367   stgwrite("\tjzer ");
  1368   outval(number,TRUE);
  1369   code_idx+=opcodes(1)+opargs(1);
  1370 }
  1371 
  1372 /* write a value in hexadecimal; optionally adds a newline */
  1373 SC_FUNC void outval(cell val,int newline)
  1374 {
  1375   stgwrite(itoh(val));
  1376   if (newline)
  1377     stgwrite("\n");
  1378 }