/* common */
#include "check.h"
+#include "strbuf.h"
#include "version.h"
#include "xmalloc.h"
#include "xsprintf.h"
/* cc65 */
#include "asmcode.h"
#include "asmlabel.h"
+#include "casenode.h"
#include "codeseg.h"
#include "cpu.h"
#include "dataseg.h"
AddTextLine ("\t.debuginfo\t%s", (DebugInfo != 0)? "on" : "off");
/* Import the stack pointer for direct auto variable access */
- AddTextLine ("\t.importzp\tsp, sreg, regsave, regbank, tmp1, ptr1");
+ AddTextLine ("\t.importzp\tsp, sreg, regsave, regbank, tmp1, ptr1, ptr2");
/* Define long branch macros */
AddTextLine ("\t.macpack\tlongbranch");
if (B2 == B4) {
AddCodeLine ("stx sreg+1");
Done |= 0x08;
- }
+ }
if ((Done & 0x04) == 0 && B1 != B3) {
AddCodeLine ("lda #$%02X", B3);
AddCodeLine ("sta sreg");
case CF_CHAR:
if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
- if (CPU == CPU_65C02 && offs == 0) {
- AddCodeLine ("lda (sp)");
- } else {
- ldyconst (offs);
- AddCodeLine ("lda (sp),y");
- }
+ ldyconst (offs);
+ AddCodeLine ("lda (sp),y");
} else {
ldyconst (offs);
AddCodeLine ("ldx #$00");
AddCodeLine ("dey");
AddCodeLine ("lda (sp),y");
} else {
- if (offs) {
- ldyconst (offs+1);
- AddCodeLine ("jsr ldaxysp");
- } else {
- AddCodeLine ("jsr ldax0sp");
- }
+ ldyconst (offs+1);
+ AddCodeLine ("jsr ldaxysp");
}
}
break;
case CF_LONG:
- if (offs) {
- ldyconst (offs+3);
- AddCodeLine ("jsr ldeaxysp");
- } else {
- AddCodeLine ("jsr ldeax0sp");
- }
+ ldyconst (offs+3);
+ AddCodeLine ("jsr ldeaxysp");
break;
default:
AddCodeLine ("iny");
AddCodeLine ("ora (ptr1),y");
} else {
- if (offs == 0) {
- AddCodeLine ("jsr ldaxi");
- } else {
- ldyconst (offs+1);
- AddCodeLine ("jsr ldaxidx");
- }
+ ldyconst (offs+1);
+ AddCodeLine ("jsr ldaxidx");
}
break;
case CF_LONG:
- if (offs == 0) {
- AddCodeLine ("jsr ldeaxi");
- } else {
- ldyconst (offs+3);
- AddCodeLine ("jsr ldeaxidx");
- }
+ ldyconst (offs+3);
+ AddCodeLine ("jsr ldeaxidx");
if (flags & CF_TEST) {
AddCodeLine ("jsr tsteax");
}
CheckLocalOffs (ArgSizeOffs);
/* Get the size of all parameters. */
- if (ArgSizeOffs == 0 && CPU == CPU_65C02) {
- AddCodeLine ("lda (sp)");
- } else {
- ldyconst (ArgSizeOffs);
- AddCodeLine ("lda (sp),y");
- }
+ ldyconst (ArgSizeOffs);
+ AddCodeLine ("lda (sp),y");
/* Add the value of the stackpointer */
if (CodeSizeFactor > 250) {
if (Flags & CF_CONST) {
AddCodeLine ("lda #$%02X", (unsigned char) Val);
}
- if (CPU == CPU_65C02 && Offs == 0) {
- AddCodeLine ("sta (sp)");
- } else {
- ldyconst (Offs);
- AddCodeLine ("sta (sp),y");
- }
+ ldyconst (Offs);
+ AddCodeLine ("sta (sp),y");
break;
case CF_INT:
/* Place high byte into X */
AddCodeLine ("tax");
}
- if (CPU == CPU_65C02 && Offs == 0) {
- AddCodeLine ("lda #$%02X", (unsigned char) Val);
- AddCodeLine ("sta (sp)");
+ if ((Val & 0xFF) == Offs+1) {
+ /* The value we need is already in Y */
+ AddCodeLine ("tya");
+ AddCodeLine ("dey");
} else {
- if ((Val & 0xFF) == Offs+1) {
- /* The value we need is already in Y */
- AddCodeLine ("tya");
- AddCodeLine ("dey");
- } else {
- AddCodeLine ("dey");
- AddCodeLine ("lda #$%02X", (unsigned char) Val);
- }
- AddCodeLine ("sta (sp),y");
+ AddCodeLine ("dey");
+ AddCodeLine ("lda #$%02X", (unsigned char) Val);
}
+ AddCodeLine ("sta (sp),y");
} else {
if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) {
- if (Offs) {
- ldyconst (Offs);
- AddCodeLine ("jsr staxysp");
- } else {
- AddCodeLine ("jsr stax0sp");
- }
+ ldyconst (Offs);
+ AddCodeLine ("jsr staxysp");
} else {
- if (CPU == CPU_65C02 && Offs == 0) {
- AddCodeLine ("sta (sp)");
- ldyconst (1);
- AddCodeLine ("txa");
- AddCodeLine ("sta (sp),y");
- } else {
- ldyconst (Offs);
- AddCodeLine ("sta (sp),y");
- AddCodeLine ("iny");
- AddCodeLine ("txa");
- AddCodeLine ("sta (sp),y");
- }
+ ldyconst (Offs);
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("iny");
+ AddCodeLine ("txa");
+ AddCodeLine ("sta (sp),y");
}
}
break;
if (Flags & CF_CONST) {
g_getimmed (Flags, Val, 0);
}
- if (Offs) {
- ldyconst (Offs);
- AddCodeLine ("jsr steaxysp");
- } else {
- AddCodeLine ("jsr steax0sp");
- }
+ ldyconst (Offs);
+ AddCodeLine ("jsr steaxysp");
break;
default:
-/*****************************************************************************/
-/* Compares of ax with a variable with fixed address */
-/*****************************************************************************/
-
-
-
-void g_cmplocal (unsigned flags, int offs)
-/* Compare a local variable to ax */
-{
- Internal ("g_cmplocal not implemented");
-}
-
-
-
-void g_cmpstatic (unsigned flags, unsigned label, unsigned offs)
-/* Compare a static variable to ax */
-{
- Internal ("g_cmpstatic not implemented");
-}
-
-
-
/*****************************************************************************/
/* Special op= functions */
/*****************************************************************************/
/* FALLTHROUGH */
case CF_INT:
- if (flags & CF_CONST) {
- g_getimmed (flags, val, 0);
- }
ldyconst (offs);
- AddCodeLine ("jsr addeqysp");
+ if (flags & CF_CONST) {
+ if (CodeSizeFactor >= 400) {
+ AddCodeLine ("clc");
+ AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda #$%02X", (int) ((val >> 8) & 0xFF));
+ AddCodeLine ("adc (sp),y");
+ AddCodeLine ("sta (sp),y");
+ AddCodeLine ("tax");
+ AddCodeLine ("dey");
+ AddCodeLine ("lda (sp),y");
+ } else {
+ g_getimmed (flags, val, 0);
+ AddCodeLine ("jsr addeqysp");
+ }
+ } else {
+ AddCodeLine ("jsr addeqysp");
+ }
break;
case CF_LONG:
if (flags & CF_CONST) {
g_getimmed (flags, val, 0);
}
- if (offs == 0) {
- AddCodeLine ("jsr laddeq0sp");
- } else {
- ldyconst (offs);
- AddCodeLine ("jsr laddeqysp");
- }
+ ldyconst (offs);
+ AddCodeLine ("jsr laddeqysp");
break;
default:
AddCodeLine ("ldy #<(%s)", lbuf);
AddCodeLine ("sty ptr1");
AddCodeLine ("ldy #>(%s+1)", lbuf);
- if (val == 1) {
- AddCodeLine ("jsr lsubeq1");
- } else {
- AddCodeLine ("lda #$%02X", (unsigned char)val);
- AddCodeLine ("jsr lsubeqa");
- }
+ AddCodeLine ("lda #$%02X", (unsigned char)val);
+ AddCodeLine ("jsr lsubeqa");
} else {
g_getstatic (flags, label, offs);
g_dec (flags, val);
if (flags & CF_CONST) {
g_getimmed (flags, val, 0);
}
- if (offs == 0) {
- AddCodeLine ("jsr subeq0sp");
- } else {
- ldyconst (offs);
- AddCodeLine ("jsr subeqysp");
- }
+ ldyconst (offs);
+ AddCodeLine ("jsr subeqysp");
break;
case CF_LONG:
if (flags & CF_CONST) {
g_getimmed (flags, val, 0);
}
- if (offs == 0) {
- AddCodeLine ("jsr lsubeq0sp");
- } else {
- ldyconst (offs);
- AddCodeLine ("jsr lsubeqysp");
- }
+ ldyconst (offs);
+ AddCodeLine ("jsr lsubeqysp");
break;
default:
-void g_addaddr_local (unsigned flags, int offs)
+void g_addaddr_local (unsigned flags attribute ((unused)), int offs)
/* Add the address of a local variable to ax */
{
unsigned L = 0;
void g_push (unsigned flags, unsigned long val)
/* Push the primary register or a constant value onto the stack */
{
- unsigned char hi;
-
if (flags & CF_CONST && (flags & CF_TYPE) != CF_LONG) {
/* We have a constant 8 or 16 bit value */
if ((flags & CF_TYPE) == CF_CHAR && (flags & CF_FORCECHAR)) {
/* Handle as 8 bit value */
- if (CodeSizeFactor >= 165 || val > 2) {
- ldaconst (val);
- AddCodeLine ("jsr pusha");
- } else {
- AddCodeLine ("jsr pushc%d", (int) val);
- }
+ ldaconst (val);
+ AddCodeLine ("jsr pusha");
} else {
/* Handle as 16 bit value */
- hi = (unsigned char) (val >> 8);
- if (val <= 7) {
- AddCodeLine ("jsr push%u", (unsigned) val);
- } else if (hi == 0 || hi == 0xFF) {
- /* Use special function */
- ldaconst (val);
- AddCodeLine ("jsr %s", (hi == 0)? "pusha0" : "pushaFF");
- } else {
- /* Long way ... */
- g_getimmed (flags, val, 0);
- AddCodeLine ("jsr pushax");
- }
+ g_getimmed (flags, val, 0);
+ AddCodeLine ("jsr pushax");
}
} else {
-void g_callind (unsigned Flags, unsigned ArgSize)
-/* Call subroutine with address in AX */
+void g_callind (unsigned Flags, unsigned ArgSize, int Offs)
+/* Call subroutine indirect */
{
- if ((Flags & CF_FIXARGC) == 0) {
- /* Pass arg count */
- ldyconst (ArgSize);
+ if ((Flags & CF_LOCAL) == 0) {
+ /* Address is in a/x */
+ if ((Flags & CF_FIXARGC) == 0) {
+ /* Pass arg count */
+ ldyconst (ArgSize);
+ }
+ AddCodeLine ("jsr callax");
+ } else {
+ /* The address is on stack, offset is on Val */
+ Offs -= oursp;
+ CheckLocalOffs (Offs);
+ AddCodeLine ("pha");
+ AddCodeLine ("ldy #$%02X", Offs);
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta jmpvec+1");
+ AddCodeLine ("iny");
+ AddCodeLine ("lda (sp),y");
+ AddCodeLine ("sta jmpvec+2");
+ AddCodeLine ("pla");
+ AddCodeLine ("jsr jmpvec");
}
- AddCodeLine ("jsr callax"); /* do the call */
- oursp += ArgSize; /* callee pops args */
+
+ /* Callee pops args */
+ oursp += ArgSize;
}
-void g_switch (unsigned Flags)
-/* Output switch statement preamble */
-{
- switch (Flags & CF_TYPE) {
-
- case CF_CHAR:
- case CF_INT:
- AddCodeLine ("jsr switch");
- break;
-
- case CF_LONG:
- AddCodeLine ("jsr lswitch");
- break;
-
- default:
- typeerror (Flags);
-
- }
-}
-
-
-
-void g_case (unsigned flags, unsigned label, unsigned long val)
-/* Create table code for one case selector */
-{
- switch (flags & CF_TYPE) {
-
- case CF_CHAR:
- case CF_INT:
- AddCodeLine (".word $%04X, %s",
- (unsigned)(val & 0xFFFF),
- LocalLabelName (label));
- break;
-
- case CF_LONG:
- AddCodeLine (".dword $%08lX", val);
- AddCodeLine (".word %s", LocalLabelName (label));
- break;
-
- default:
- typeerror (flags);
-
- }
-}
-
-
-
-void g_truejump (unsigned flags, unsigned label)
+void g_truejump (unsigned flags attribute ((unused)), unsigned label)
/* Jump to label if zero flag clear */
{
AddCodeLine ("jne %s", LocalLabelName (label));
-void g_falsejump (unsigned flags, unsigned label)
+void g_falsejump (unsigned flags attribute ((unused)), unsigned label)
/* Jump to label if zero flag set */
{
AddCodeLine ("jeq %s", LocalLabelName (label));
if (flags & CF_CONST && (p2 = powerof2 (val)) >= 0) {
/* Generate a shift instead */
g_asl (flags, p2);
- return;
+ return;
}
/* If the right hand side is const, the lhs is not on stack but still
case CF_CHAR:
if (flags & CF_FORCECHAR) {
- /* Handle some special cases */
- switch (val) {
-
- case 3:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- return;
-
- case 5:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
+ /* Handle some special cases */
+ switch (val) {
+
+ case 3:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
AddCodeLine ("adc tmp1");
- return;
-
- case 10:
- AddCodeLine ("sta tmp1");
- AddCodeLine ("asl a");
- AddCodeLine ("asl a");
- AddCodeLine ("clc");
- AddCodeLine ("adc tmp1");
- AddCodeLine ("asl a");
- return;
- }
+ return;
+
+ case 5:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ return;
+
+ case 10:
+ AddCodeLine ("sta tmp1");
+ AddCodeLine ("asl a");
+ AddCodeLine ("asl a");
+ AddCodeLine ("clc");
+ AddCodeLine ("adc tmp1");
+ AddCodeLine ("asl a");
+ return;
+ }
}
/* FALLTHROUGH */
- case CF_INT:
- break;
+ case CF_INT:
+ switch (val) {
+ case 3:
+ AddCodeLine ("jsr mulax3");
+ return;
+ case 5:
+ AddCodeLine ("jsr mulax5");
+ return;
+ case 10:
+ AddCodeLine ("jsr mulax10");
+ return;
+ }
+ break;
- case CF_LONG:
- break;
+ case CF_LONG:
+ break;
- default:
- typeerror (flags);
- }
+ default:
+ typeerror (flags);
+ }
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
- * into the normal, non-optimized stuff.
- */
- flags &= ~CF_FORCECHAR; /* Handle chars as ints */
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ * into the normal, non-optimized stuff.
+ */
+ flags &= ~CF_FORCECHAR; /* Handle chars as ints */
g_push (flags & ~CF_CONST, 0);
}
AddCodeLine ("and #$%02X", (unsigned char)(val >> 8));
AddCodeLine ("tax");
ldaconst (0);
- } else {
+ } else {
AddCodeLine ("tay");
AddCodeLine ("txa");
AddCodeLine ("and #$%02X", (unsigned char)(val >> 8));
AddCodeLine ("tax");
AddCodeLine ("tya");
if ((val & 0x00FF) != 0x00FF) {
- AddCodeLine ("and #$%02X", (unsigned char)val);
+ AddCodeLine ("and #$%02X", (unsigned char)val);
}
}
}
/* Primary = TOS >> Primary */
{
static char* ops [12] = {
- 0, "tosasra0", "tosasrax",
- 0, "tosshra0", "tosshrax",
- 0, 0, "tosasreax",
- 0, 0, "tosshreax",
+ 0, "tosasra0", "tosasrax",
+ 0, "tosshra0", "tosshrax",
+ 0, 0, "tosasreax",
+ 0, 0, "tosshreax",
};
/* If the right hand side is const, the lhs is not on stack but still
case CF_CHAR:
case CF_INT:
- if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shrax%ld", val);
- } else {
- AddCodeLine ("jsr asrax%ld", val);
- }
- return;
- } else if (val == 8 && (flags & CF_UNSIGNED)) {
+ if (val >= 8 && (flags & CF_UNSIGNED)) {
AddCodeLine ("txa");
ldxconst (0);
+ val -= 8;
+ }
+ if (val == 0) {
+ /* Done */
return;
- }
- break;
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shrax%ld", val);
+ } else {
+ AddCodeLine ("jsr asrax%ld", val);
+ }
+ return;
+ }
+ break;
- case CF_LONG:
- if (val >= 1 && val <= 4) {
- if (flags & CF_UNSIGNED) {
- AddCodeLine ("jsr shreax%ld", val);
- } else {
- AddCodeLine ("jsr asreax%ld", val);
- }
+ case CF_LONG:
+ if (val == 0) {
+ /* Nothing to do */
return;
- } else if (val == 8 && (flags & CF_UNSIGNED)) {
- AddCodeLine ("txa");
- AddCodeLine ("ldx sreg");
- AddCodeLine ("ldy sreg+1");
- AddCodeLine ("sty sreg");
- AddCodeLine ("ldy #$00");
+ } else if (val >= 1 && val <= 4) {
+ if (flags & CF_UNSIGNED) {
+ AddCodeLine ("jsr shreax%ld", val);
+ } else {
+ AddCodeLine ("jsr asreax%ld", val);
+ }
+ return;
+ } else if (val == 8 && (flags & CF_UNSIGNED)) {
+ AddCodeLine ("txa");
+ AddCodeLine ("ldx sreg");
+ AddCodeLine ("ldy sreg+1");
+ AddCodeLine ("sty sreg");
+ AddCodeLine ("ldy #$00");
AddCodeLine ("sty sreg+1");
- return;
+ return;
} else if (val == 16) {
- AddCodeLine ("ldy #$00");
- AddCodeLine ("ldx sreg+1");
- if ((flags & CF_UNSIGNED) == 0) {
- unsigned L = GetLocalLabel();
- AddCodeLine ("bpl %s", LocalLabelName (L));
- AddCodeLine ("dey");
- g_defcodelabel (L);
- }
+ AddCodeLine ("ldy #$00");
+ AddCodeLine ("ldx sreg+1");
+ if ((flags & CF_UNSIGNED) == 0) {
+ unsigned L = GetLocalLabel();
+ AddCodeLine ("bpl %s", LocalLabelName (L));
+ AddCodeLine ("dey");
+ g_defcodelabel (L);
+ }
AddCodeLine ("lda sreg");
- AddCodeLine ("sty sreg+1");
- AddCodeLine ("sty sreg");
- return;
- }
- break;
+ AddCodeLine ("sty sreg+1");
+ AddCodeLine ("sty sreg");
+ return;
+ }
+ break;
- default:
- typeerror (flags);
- }
+ default:
+ typeerror (flags);
+ }
- /* If we go here, we didn't emit code. Push the lhs on stack and fall
+ /* If we go here, we didn't emit code. Push the lhs on stack and fall
* into the normal, non-optimized stuff.
- */
- g_push (flags & ~CF_CONST, 0);
+ */
+ g_push (flags & ~CF_CONST, 0);
}
/* Primary = TOS << Primary */
{
static char* ops [12] = {
- 0, "tosasla0", "tosaslax",
- 0, "tosshla0", "tosshlax",
- 0, 0, "tosasleax",
- 0, 0, "tosshleax",
+ 0, "tosasla0", "tosaslax",
+ 0, "tosshla0", "tosshlax",
+ 0, 0, "tosasleax",
+ 0, 0, "tosshleax",
};
case CF_CHAR:
case CF_INT:
- if (val >= 1 && val <= 4) {
+ if (val >= 8) {
+ AddCodeLine ("tax");
+ AddCodeLine ("lda #$00");
+ val -= 8;
+ }
+ if (val == 0) {
+ /* Done */
+ return;
+ } else if (val >= 1 && val <= 4) {
if (flags & CF_UNSIGNED) {
AddCodeLine ("jsr shlax%ld", val);
} else {
- AddCodeLine ("jsr aslax%ld", val);
+ AddCodeLine ("jsr aslax%ld", val);
}
return;
- } else if (val == 8) {
- AddCodeLine ("tax");
- AddCodeLine ("lda #$00");
- return;
- }
+ }
break;
case CF_LONG:
- if (val >= 1 && val <= 4) {
+ if (val == 0) {
+ /* Nothing to do */
+ return;
+ } else if (val >= 1 && val <= 4) {
if (flags & CF_UNSIGNED) {
AddCodeLine ("jsr shleax%ld", val);
} else {
}
return;
} else if (val == 8) {
- AddCodeLine ("ldy sreg");
+ AddCodeLine ("ldy sreg");
AddCodeLine ("sty sreg+1");
AddCodeLine ("stx sreg");
AddCodeLine ("tax");
break;
case CF_LONG:
- AddCodeLine ("jsr negeax");
+ AddCodeLine ("jsr negeax");
break;
default:
if (flags & CF_FORCECHAR) {
if (CPU == CPU_65C02 && val <= 2) {
while (val--) {
- AddCodeLine ("ina");
+ AddCodeLine ("ina");
}
} else {
AddCodeLine ("clc");
}
} else {
/* Inline the code */
- if (val < 0x300) {
+ if (val <= 0x300) {
if ((val & 0xFF) != 0) {
- unsigned L = GetLocalLabel();
+ unsigned L = GetLocalLabel();
AddCodeLine ("clc");
AddCodeLine ("adc #$%02X", (unsigned char) val);
AddCodeLine ("bcc %s", LocalLabelName (L));
AddCodeLine ("inx");
- g_defcodelabel (L);
+ g_defcodelabel (L);
}
if (val >= 0x100) {
AddCodeLine ("inx");
if (val >= 0x200) {
AddCodeLine ("inx");
}
+ if (val >= 0x300) {
+ AddCodeLine ("inx");
+ }
} else {
AddCodeLine ("clc");
if ((val & 0xFF) != 0) {
const char* Label = GetLabelName (flags, val, offs);
/* Labels are always 16 bit */
- AddDataLine ("\t.word\t%s", Label);
+ AddDataLine ("\t.addr\t%s", Label);
}
}
/*****************************************************************************/
-/* User supplied assembler code */
+/* Switch statement */
/*****************************************************************************/
-void g_asmcode (const char* Line, int Len)
-/* Output one line of assembler code. If Len is greater than zero, it is used
- * as the maximum number of characters to use from Line.
- */
+void g_switch (Collection* Nodes, unsigned DefaultLabel, unsigned Depth)
+/* Generate code for a switch statement */
{
- if (Len >= 0) {
- AddCodeLine ("%.*s", Len, Line);
- } else {
- AddCodeLine ("%s", Line);
+ unsigned NextLabel = 0;
+ unsigned I;
+
+ /* Setup registers and determine which compare insn to use */
+ const char* Compare;
+ switch (Depth) {
+ case 1:
+ Compare = "cmp #$%02X";
+ break;
+ case 2:
+ Compare = "cpx #$%02X";
+ break;
+ case 3:
+ AddCodeLine ("ldy sreg");
+ Compare = "cpy #$%02X";
+ break;
+ case 4:
+ AddCodeLine ("ldy sreg+1");
+ Compare = "cpy #$%02X";
+ break;
+ default:
+ Internal ("Invalid depth in g_switch: %u", Depth);
}
+
+ /* Walk over all nodes */
+ for (I = 0; I < CollCount (Nodes); ++I) {
+
+ /* Get the next case node */
+ CaseNode* N = CollAtUnchecked (Nodes, I);
+
+ /* If we have a next label, define it */
+ if (NextLabel) {
+ g_defcodelabel (NextLabel);
+ NextLabel = 0;
+ }
+
+ /* Do the compare */
+ AddCodeLine (Compare, CN_GetValue (N));
+
+ /* If this is the last level, jump directly to the case code if found */
+ if (Depth == 1) {
+
+ /* Branch if equal */
+ g_falsejump (0, CN_GetLabel (N));
+
+ } else {
+
+ /* Determine the next label */
+ if (I == CollCount (Nodes) - 1) {
+ /* Last node means not found */
+ g_truejump (0, DefaultLabel);
+ } else {
+ /* Jump to the next check */
+ NextLabel = GetLocalLabel ();
+ g_truejump (0, NextLabel);
+ }
+
+ /* Check the next level */
+ g_switch (N->Nodes, DefaultLabel, Depth-1);
+
+ }
+ }
+
+ /* If we go here, we haven't found the label */
+ g_jump (DefaultLabel);
+}
+
+
+
+/*****************************************************************************/
+/* User supplied assembler code */
+/*****************************************************************************/
+
+
+
+void g_asmcode (struct StrBuf* B)
+/* Output one line of assembler code. */
+{
+ AddCodeLine ("%.*s", SB_GetLen (B), SB_GetConstBuf (B));
}
/*****************************************************************************/
-/* Inlined known functions */
+/* Inlined known functions */
/*****************************************************************************/