1 /* Small compiler - code generation (unoptimized "assembler" code)
3 * Copyright (c) ITB CompuPhase, 1997-2003
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.
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:
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.
25 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
35 #include <stdlib.h> /* for _MAX_PATH */
38 #include "embryo_cc_sc.h"
40 /* When a subroutine returns to address 0, the AMX must halt. In earlier
41 * releases, the RET and RETN opcodes checked for the special case 0 address.
42 * Today, the compiler simply generates a HALT instruction at address 0. So
43 * a subroutine can savely return to 0, and then encounter a HALT.
48 assert(code_idx == 0);
49 stgwrite(";program exit point\n");
50 stgwrite("\thalt 0\n");
51 /* calculate code length */
52 code_idx += opcodes(1) + opargs(1);
56 * Not much left of this once important function.
58 * Global references: sc_stksize (referred to only)
59 * sc_dataalign (referred to only)
61 * glb_declared (altered)
66 assert(sc_dataalign % opcodes(1) == 0); /* alignment must be a multiple of
68 assert(sc_dataalign != 0);
70 /* pad code to align data segment */
71 if ((code_idx % sc_dataalign) != 0)
74 while ((code_idx % sc_dataalign) != 0)
78 /* pad data segment to align the stack and the heap */
79 assert(litidx == 0); /* literal queue should have been emptied */
80 assert(sc_dataalign % sizeof(cell) == 0);
81 if (((glb_declared * sizeof(cell)) % sc_dataalign) != 0)
85 while (((glb_declared * sizeof(cell)) % sc_dataalign) != 0)
92 stgwrite("\nSTKSIZE "); /* write stack size (align stack top) */
93 outval(sc_stksize - (sc_stksize % sc_dataalign), TRUE);
97 * Start (or restart) the CODE segment.
99 * In fact, the code and data segment specifiers are purely informational;
100 * the "DUMP" instruction itself already specifies that the following values
101 * should go to the data segment. All otherinstructions go to the code
104 * Global references: curseg
109 if (curseg != sIN_CSEG)
112 stgwrite("CODE\t; ");
113 outval(code_idx, TRUE);
119 * Start (or restart) the DATA segment.
121 * Global references: curseg
126 if (curseg != sIN_DSEG)
129 stgwrite("DATA\t; ");
130 outval(glb_declared - litidx, TRUE);
136 setactivefile(int fnumber)
138 stgwrite("curfile ");
139 outval(fnumber, TRUE);
143 nameincells(char *name)
146 (strlen(name) + sizeof(cell)) & ~(sizeof(cell) - 1);
151 setfile(char *name, int fileno)
153 if ((sc_debug & sSYMBOLIC) != 0)
157 outval(fileno, FALSE);
161 /* calculate code length */
162 code_idx += opcodes(1) + opargs(2) + nameincells(name);
167 setline(int line, int fileno)
169 if ((sc_debug & (sSYMBOLIC | sCHKBOUNDS)) != 0)
174 outval(fileno, FALSE);
176 outval(code_idx, TRUE);
177 code_idx += opcodes(1) + opargs(2);
183 * Post a code label (specified as a number), on a new line.
190 stgwrite((char *)itoh(number));
191 /* To assist verification of the assembled code, put the address of the
192 * label as a comment. However, labels that occur inside an expression
193 * may move (through optimization or through re-ordering). So write the
194 * address only if it is known to accurate.
199 outval(code_idx, FALSE);
204 /* Write a token that signifies the end of an expression, or the end of a
205 * function parameter. This allows several simple optimizations by the peephole
209 endexpr(int fullexpr)
212 stgwrite("\t;$exp\n");
214 stgwrite("\t;$par\n");
217 /* startfunc - declare a CODE entry point (function start)
219 * Global references: funcstatus (referred to only)
222 startfunc(char *fname __UNUSED__)
226 code_idx += opcodes(1);
231 * Declare a CODE ending point (function end)
236 stgwrite("\n"); /* skip a line */
241 * Aligns the frame (and the stack) of the current function to a multiple
242 * of the specified byte count. Two caveats: the alignment ("numbytes") should
243 * be a power of 2, and this alignment must be done right after the frame
244 * is set up (before the first variable is declared)
247 alignframe(int numbytes)
250 /* "numbytes" should be a power of 2 for this code to work */
253 for (i = 0; i < sizeof numbytes * 8; i++)
254 if (numbytes & (1 << i))
259 stgwrite("\tlctrl 4\n"); /* get STK in PRI */
260 stgwrite("\tconst.alt "); /* get ~(numbytes-1) in ALT */
261 outval(~(numbytes - 1), TRUE);
262 stgwrite("\tand\n"); /* PRI = STK "and" ~(numbytes-1) */
263 stgwrite("\tsctrl 4\n"); /* set the new value of STK ... */
264 stgwrite("\tsctrl 5\n"); /* ... and FRM */
265 code_idx += opcodes(5) + opargs(4);
268 /* Define a variable or function
271 defsymbol(char *name, int ident, int vclass, cell offset, int tag)
273 if ((sc_debug & sSYMBOLIC) != 0)
275 begcseg(); /* symbol definition in code segment */
281 outval(offset, FALSE);
284 outval(vclass, FALSE);
289 code_idx += opcodes(1) + opargs(3) + nameincells(name); /* class and ident encoded in "flags" */
291 /* also write the optional tag */
294 assert((tag & TAGMASK) != 0);
296 outval(tag & TAGMASK, TRUE);
297 code_idx += opcodes(1) + opargs(1);
303 symbolrange(int level, cell size)
305 if ((sc_debug & sSYMBOLIC) != 0)
307 begcseg(); /* symbol definition in code segment */
309 outval(level, FALSE);
312 code_idx += opcodes(1) + opargs(2);
318 * Generate code to get the value of a symbol into "primary".
326 if (lval->ident == iARRAYCELL)
328 /* indirect fetch, address already in PRI */
329 stgwrite("\tload.i\n");
330 code_idx += opcodes(1);
332 else if (lval->ident == iARRAYCHAR)
334 /* indirect fetch of a character from a pack, address already in PRI */
335 stgwrite("\tlodb.i ");
336 outval(charbits / 8, TRUE); /* read one or two bytes */
337 code_idx += opcodes(1) + opargs(1);
339 else if (lval->ident == iREFERENCE)
341 /* indirect fetch, but address not yet in PRI */
343 assert(sym->vclass == sLOCAL); /* global references don't exist in Small */
344 if (sym->vclass == sLOCAL)
345 stgwrite("\tlref.s.pri ");
347 stgwrite("\tlref.pri ");
348 outval(sym->addr, TRUE);
349 markusage(sym, uREAD);
350 code_idx += opcodes(1) + opargs(1);
354 /* direct or stack relative fetch */
356 if (sym->vclass == sLOCAL)
357 stgwrite("\tload.s.pri ");
359 stgwrite("\tload.pri ");
360 outval(sym->addr, TRUE);
361 markusage(sym, uREAD);
362 code_idx += opcodes(1) + opargs(1);
367 * Get the address of a symbol into the primary register (used for arrays,
368 * and for passing arguments by reference).
371 address(symbol * sym)
374 /* the symbol can be a local array, a global array, or an array
375 * that is passed by reference.
377 if (sym->ident == iREFARRAY || sym->ident == iREFERENCE)
379 /* reference to a variable or to an array; currently this is
380 * always a local variable */
381 stgwrite("\tload.s.pri ");
385 /* a local array or local variable */
386 if (sym->vclass == sLOCAL)
387 stgwrite("\taddr.pri ");
389 stgwrite("\tconst.pri ");
391 outval(sym->addr, TRUE);
392 markusage(sym, uREAD);
393 code_idx += opcodes(1) + opargs(1);
398 * Saves the contents of "primary" into a memory cell, either directly
399 * or indirectly (at the address given in the alternate register).
407 if (lval->ident == iARRAYCELL)
409 /* store at address in ALT */
410 stgwrite("\tstor.i\n");
411 code_idx += opcodes(1);
413 else if (lval->ident == iARRAYCHAR)
415 /* store at address in ALT */
416 stgwrite("\tstrb.i ");
417 outval(charbits / 8, TRUE); /* write one or two bytes */
418 code_idx += opcodes(1) + opargs(1);
420 else if (lval->ident == iREFERENCE)
423 if (sym->vclass == sLOCAL)
424 stgwrite("\tsref.s.pri ");
426 stgwrite("\tsref.pri ");
427 outval(sym->addr, TRUE);
428 code_idx += opcodes(1) + opargs(1);
433 markusage(sym, uWRITTEN);
434 if (sym->vclass == sLOCAL)
435 stgwrite("\tstor.s.pri ");
437 stgwrite("\tstor.pri ");
438 outval(sym->addr, TRUE);
439 code_idx += opcodes(1) + opargs(1);
443 /* source must in PRI, destination address in ALT. The "size"
444 * parameter is in bytes, not cells.
452 code_idx += opcodes(1) + opargs(1);
455 /* Address of the source must already have been loaded in PRI
456 * "size" is the size in bytes (not cells).
459 copyarray(symbol * sym, cell size)
462 /* the symbol can be a local array, a global array, or an array
463 * that is passed by reference.
465 if (sym->ident == iREFARRAY)
467 /* reference to an array; currently this is always a local variable */
468 assert(sym->vclass == sLOCAL); /* symbol must be stack relative */
469 stgwrite("\tload.s.alt ");
473 /* a local or global array */
474 if (sym->vclass == sLOCAL)
475 stgwrite("\taddr.alt ");
477 stgwrite("\tconst.alt ");
479 outval(sym->addr, TRUE);
480 markusage(sym, uWRITTEN);
482 code_idx += opcodes(1) + opargs(1);
487 fillarray(symbol * sym, cell size, cell value)
489 const1(value); /* load value in PRI */
492 /* the symbol can be a local array, a global array, or an array
493 * that is passed by reference.
495 if (sym->ident == iREFARRAY)
497 /* reference to an array; currently this is always a local variable */
498 assert(sym->vclass == sLOCAL); /* symbol must be stack relative */
499 stgwrite("\tload.s.alt ");
503 /* a local or global array */
504 if (sym->vclass == sLOCAL)
505 stgwrite("\taddr.alt ");
507 stgwrite("\tconst.alt ");
509 outval(sym->addr, TRUE);
510 markusage(sym, uWRITTEN);
515 code_idx += opcodes(2) + opargs(2);
519 * Instruction to get an immediate value into the primary register
526 stgwrite("\tzero.pri\n");
527 code_idx += opcodes(1);
531 stgwrite("\tconst.pri ");
533 code_idx += opcodes(1) + opargs(1);
538 * Instruction to get an immediate value into the secondary register
545 stgwrite("\tzero.alt\n");
546 code_idx += opcodes(1);
550 stgwrite("\tconst.alt ");
552 code_idx += opcodes(1) + opargs(1);
556 /* Copy value in secondary register to the primary register */
560 stgwrite("\tmove.pri\n");
561 code_idx += opcodes(1) + opargs(0);
565 * Push primary register onto the stack
570 stgwrite("\tpush.pri\n");
571 code_idx += opcodes(1);
575 * Push alternate register onto the stack
580 stgwrite("\tpush.alt\n");
581 code_idx += opcodes(1);
585 * Push a constant value onto the stack
590 stgwrite("\tpush.c ");
592 code_idx += opcodes(1) + opargs(1);
596 * pop stack to the primary register
601 stgwrite("\tpop.pri\n");
602 code_idx += opcodes(1);
606 * pop stack to the secondary register
611 stgwrite("\tpop.alt\n");
612 code_idx += opcodes(1);
616 * swap the top-of-stack with the value in primary register
621 stgwrite("\tswap.pri\n");
622 code_idx += opcodes(1);
626 * The "switch" statement generates a "case" table using the "CASE" opcode.
627 * The case table contains a list of records, each record holds a comparison
628 * value and a label to branch to on a match. The very first record is an
629 * exception: it holds the size of the table (excluding the first record) and
630 * the label to branch to when none of the values in the case table match.
631 * The case table is sorted on the comparison value. This allows more advanced
632 * abstract machines to sift the case table with a binary search.
637 stgwrite("\tswitch ");
638 outval(label, TRUE); /* the label is the address of the case table */
639 code_idx += opcodes(1) + opargs(1);
643 ffcase(cell value, char *labelname, int newtable)
647 stgwrite("\tcasetbl\n");
648 code_idx += opcodes(1);
651 outval(value, FALSE);
655 code_idx += opcodes(0) + opargs(2);
659 * Call specified function
662 ffcall(symbol * sym, int numargs)
665 assert(sym->ident == iFUNCTN);
666 if ((sym->usage & uNATIVE) != 0)
668 /* reserve a SYSREQ id if called for the first time */
669 if (sc_status == statWRITE && (sym->usage & uREAD) == 0
671 sym->addr = ntv_funcid++;
672 stgwrite("\tsysreq.c ");
673 outval(sym->addr, FALSE);
674 stgwrite("\n\tstack ");
675 outval((numargs + 1) * sizeof(cell), TRUE);
676 code_idx += opcodes(2) + opargs(2);
680 /* normal function */
684 code_idx += opcodes(1) + opargs(1);
688 /* Return from function
690 * Global references: funcstatus (referred to only)
695 stgwrite("\tretn\n");
696 code_idx += opcodes(1);
703 outval(reason, TRUE);
704 code_idx += opcodes(1) + opargs(1);
710 if ((sc_debug & sCHKBOUNDS) != 0)
712 stgwrite("\tbounds ");
714 code_idx += opcodes(1) + opargs(1);
719 * Jump to local label number (the number is converted to a name)
722 jumplabel(int number)
725 outval(number, TRUE);
726 code_idx += opcodes(1) + opargs(1);
730 * Define storage (global and static variables)
739 * Inclrement/decrement stack pointer. Note that this routine does
740 * nothing if the delta is zero.
747 stgwrite("\tstack ");
749 code_idx += opcodes(1) + opargs(1);
753 /* set the stack to a hard offset from the frame */
757 stgwrite("\tlctrl 5\n"); /* get FRM */
758 assert(value <= 0); /* STK should always become <= FRM */
761 stgwrite("\tadd.c ");
762 outval(value, TRUE); /* add (negative) offset */
763 code_idx += opcodes(1) + opargs(1);
764 // ??? write zeros in the space between STK and the value in PRI (the new stk)
765 // get value of STK in ALT
767 // need new FILL opcode that takes a variable size
769 stgwrite("\tsctrl 4\n"); /* store in STK */
770 code_idx += opcodes(2) + opargs(2);
780 code_idx += opcodes(1) + opargs(1);
787 stgwrite("\theap "); /* ALT = HEA++ */
788 outval(sizeof(cell), TRUE);
789 stgwrite("\tstor.i\n"); /* store PRI (default value) at address ALT */
790 stgwrite("\tmove.pri\n"); /* move ALT to PRI: PRI contains the address */
791 code_idx += opcodes(3) + opargs(1);
797 stgwrite("\tconst.pri "); /* load default value in PRI */
799 code_idx += opcodes(1) + opargs(1);
804 * Convert a cell number to a "byte" address; i.e. double or quadruple
805 * the primary register.
811 stgwrite("\tshl.c.pri 1\n");
813 stgwrite("\tshl.c.pri 2\n");
815 code_idx += opcodes(1) + opargs(1);
819 * Double or quadruple the alternate register.
825 stgwrite("\tshl.c.alt 1\n");
827 stgwrite("\tshl.c.alt 2\n");
829 code_idx += opcodes(1) + opargs(1);
833 * Convert "distance of addresses" to "number of cells" in between.
834 * Or convert a number of packed characters to the number of cells (with
841 stgwrite("\tshr.c.pri 1\n");
843 stgwrite("\tshr.c.pri 2\n");
845 code_idx += opcodes(1) + opargs(1);
848 /* Convert from character index to byte address. This routine does
849 * nothing if a character has the size of a byte.
856 stgwrite("\tshl.c.pri 1\n");
857 code_idx += opcodes(1) + opargs(1);
861 /* Align PRI (which should hold a character index) to an address.
862 * The first character in a "pack" occupies the highest bits of
863 * the cell. This is at the lower memory address on Big Endian
864 * computers and on the higher address on Little Endian computers.
865 * The ALIGN.pri/alt instructions must solve this machine dependence;
866 * that is, on Big Endian computers, ALIGN.pri/alt shuold do nothing
867 * and on Little Endian computers they should toggle the address.
872 stgwrite("\talign.pri ");
873 outval(charbits / 8, TRUE);
874 code_idx += opcodes(1) + opargs(1);
878 * Add a constant to the primary register.
885 stgwrite("\tadd.c ");
887 code_idx += opcodes(1) + opargs(1);
892 * signed multiply of primary and secundairy registers (result in primary)
897 stgwrite("\tsmul\n");
898 code_idx += opcodes(1);
902 * signed divide of alternate register by primary register (quotient in
903 * primary; remainder in alternate)
908 stgwrite("\tsdiv.alt\n");
909 code_idx += opcodes(1);
913 * modulus of (alternate % primary), result in primary (signed)
918 stgwrite("\tsdiv.alt\n");
919 stgwrite("\tmove.pri\n"); /* move ALT to PRI */
920 code_idx += opcodes(2);
924 * Add primary and alternate registers (result in primary).
930 code_idx += opcodes(1);
934 * subtract primary register from alternate register (result in primary)
939 stgwrite("\tsub.alt\n");
940 code_idx += opcodes(1);
944 * arithmic shift left alternate register the number of bits
945 * given in the primary register (result in primary).
946 * There is no need for a "logical shift left" routine, since
947 * logical shift left is identical to arithmic shift left.
952 stgwrite("\txchg\n");
954 code_idx += opcodes(2);
958 * arithmic shift right alternate register the number of bits
959 * given in the primary register (result in primary).
964 stgwrite("\txchg\n");
965 stgwrite("\tsshr\n");
966 code_idx += opcodes(2);
970 * logical (unsigned) shift right of the alternate register by the
971 * number of bits given in the primary register (result in primary).
976 stgwrite("\txchg\n");
978 code_idx += opcodes(2);
982 * inclusive "or" of primary and secondary registers (result in primary)
988 code_idx += opcodes(1);
992 * "exclusive or" of primary and alternate registers (result in primary)
998 code_idx += opcodes(1);
1002 * "and" of primary and secundairy registers (result in primary)
1007 stgwrite("\tand\n");
1008 code_idx += opcodes(1);
1012 * test ALT==PRI; result in primary register (1 or 0).
1018 code_idx += opcodes(1);
1027 stgwrite("\tneq\n");
1028 code_idx += opcodes(1);
1031 /* The abstract machine defines the relational instructions so that PRI is
1032 * on the left side and ALT on the right side of the operator. For example,
1033 * SLESS sets PRI to either 1 or 0 depending on whether the expression
1034 * "PRI < ALT" is true.
1036 * The compiler generates comparisons with ALT on the left side of the
1037 * relational operator and PRI on the right side. The XCHG instruction
1038 * prefixing the relational operators resets this. We leave it to the
1039 * peephole optimizer to choose more compact instructions where possible.
1042 /* Relational operator prefix for chained relational expressions. The
1043 * "suffix" code restores the stack.
1044 * For chained relational operators, the goal is to keep the comparison
1045 * result "so far" in PRI and the value of the most recent operand in
1046 * ALT, ready for a next comparison.
1047 * The "prefix" instruction pushed the comparison result (PRI) onto the
1048 * stack and moves the value of ALT into PRI. If there is a next comparison,
1049 * PRI can now serve as the "left" operand of the relational operator.
1054 stgwrite("\tpush.pri\n");
1055 stgwrite("\tmove.pri\n");
1056 code_idx += opcodes(2);
1062 stgwrite("\tswap.alt\n");
1063 stgwrite("\tand\n");
1064 stgwrite("\tpop.alt\n");
1065 code_idx += opcodes(3);
1069 * test ALT<PRI (signed)
1074 stgwrite("\txchg\n");
1075 stgwrite("\tsless\n");
1076 code_idx += opcodes(2);
1080 * test ALT<=PRI (signed)
1085 stgwrite("\txchg\n");
1086 stgwrite("\tsleq\n");
1087 code_idx += opcodes(2);
1091 * test ALT>PRI (signed)
1096 stgwrite("\txchg\n");
1097 stgwrite("\tsgrtr\n");
1098 code_idx += opcodes(2);
1102 * test ALT>=PRI (signed)
1107 stgwrite("\txchg\n");
1108 stgwrite("\tsgeq\n");
1109 code_idx += opcodes(2);
1113 * logical negation of primary register
1118 stgwrite("\tnot\n");
1119 code_idx += opcodes(1);
1123 * two's complement primary register
1128 stgwrite("\tneg\n");
1129 code_idx += opcodes(1);
1133 * one's complement of primary register
1138 stgwrite("\tinvert\n");
1139 code_idx += opcodes(1);
1148 stgwrite("\tnop\n");
1149 code_idx += opcodes(1);
1160 if (lval->ident == iARRAYCELL)
1162 /* indirect increment, address already in PRI */
1163 stgwrite("\tinc.i\n");
1164 code_idx += opcodes(1);
1166 else if (lval->ident == iARRAYCHAR)
1168 /* indirect increment of single character, address already in PRI */
1169 stgwrite("\tpush.pri\n");
1170 stgwrite("\tpush.alt\n");
1171 stgwrite("\tmove.alt\n"); /* copy address */
1172 stgwrite("\tlodb.i "); /* read from PRI into PRI */
1173 outval(charbits / 8, TRUE); /* read one or two bytes */
1174 stgwrite("\tinc.pri\n");
1175 stgwrite("\tstrb.i "); /* write PRI to ALT */
1176 outval(charbits / 8, TRUE); /* write one or two bytes */
1177 stgwrite("\tpop.alt\n");
1178 stgwrite("\tpop.pri\n");
1179 code_idx += opcodes(8) + opargs(2);
1181 else if (lval->ident == iREFERENCE)
1183 assert(sym != NULL);
1184 stgwrite("\tpush.pri\n");
1185 /* load dereferenced value */
1186 assert(sym->vclass == sLOCAL); /* global references don't exist in Small */
1187 if (sym->vclass == sLOCAL)
1188 stgwrite("\tlref.s.pri ");
1190 stgwrite("\tlref.pri ");
1191 outval(sym->addr, TRUE);
1193 stgwrite("\tinc.pri\n");
1194 /* store dereferenced value */
1195 if (sym->vclass == sLOCAL)
1196 stgwrite("\tsref.s.pri ");
1198 stgwrite("\tsref.pri ");
1199 outval(sym->addr, TRUE);
1200 stgwrite("\tpop.pri\n");
1201 code_idx += opcodes(5) + opargs(2);
1205 /* local or global variable */
1206 assert(sym != NULL);
1207 if (sym->vclass == sLOCAL)
1208 stgwrite("\tinc.s ");
1211 outval(sym->addr, TRUE);
1212 code_idx += opcodes(1) + opargs(1);
1218 * in case of an integer pointer, the symbol must be incremented by 2.
1226 if (lval->ident == iARRAYCELL)
1228 /* indirect decrement, address already in PRI */
1229 stgwrite("\tdec.i\n");
1230 code_idx += opcodes(1);
1232 else if (lval->ident == iARRAYCHAR)
1234 /* indirect decrement of single character, address already in PRI */
1235 stgwrite("\tpush.pri\n");
1236 stgwrite("\tpush.alt\n");
1237 stgwrite("\tmove.alt\n"); /* copy address */
1238 stgwrite("\tlodb.i "); /* read from PRI into PRI */
1239 outval(charbits / 8, TRUE); /* read one or two bytes */
1240 stgwrite("\tdec.pri\n");
1241 stgwrite("\tstrb.i "); /* write PRI to ALT */
1242 outval(charbits / 8, TRUE); /* write one or two bytes */
1243 stgwrite("\tpop.alt\n");
1244 stgwrite("\tpop.pri\n");
1245 code_idx += opcodes(8) + opargs(2);
1247 else if (lval->ident == iREFERENCE)
1249 assert(sym != NULL);
1250 stgwrite("\tpush.pri\n");
1251 /* load dereferenced value */
1252 assert(sym->vclass == sLOCAL); /* global references don't exist in Small */
1253 if (sym->vclass == sLOCAL)
1254 stgwrite("\tlref.s.pri ");
1256 stgwrite("\tlref.pri ");
1257 outval(sym->addr, TRUE);
1259 stgwrite("\tdec.pri\n");
1260 /* store dereferenced value */
1261 if (sym->vclass == sLOCAL)
1262 stgwrite("\tsref.s.pri ");
1264 stgwrite("\tsref.pri ");
1265 outval(sym->addr, TRUE);
1266 stgwrite("\tpop.pri\n");
1267 code_idx += opcodes(5) + opargs(2);
1271 /* local or global variable */
1272 assert(sym != NULL);
1273 if (sym->vclass == sLOCAL)
1274 stgwrite("\tdec.s ");
1277 outval(sym->addr, TRUE);
1278 code_idx += opcodes(1) + opargs(1);
1283 * Jumps to "label" if PRI != 0
1289 outval(number, TRUE);
1290 code_idx += opcodes(1) + opargs(1);
1294 * Jumps to "label" if PRI == 0
1299 stgwrite("\tjzer ");
1300 outval(number, TRUE);
1301 code_idx += opcodes(1) + opargs(1);
1304 /* write a value in hexadecimal; optionally adds a newline */
1306 outval(cell val, int newline)
1308 stgwrite(itoh(val));