diff --git a/src/cc65/asmlabel.c b/src/cc65/asmlabel.c index a18cf1c76..3587fefbb 100644 --- a/src/cc65/asmlabel.c +++ b/src/cc65/asmlabel.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@musoftware.de */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -33,17 +33,20 @@ +#include + +/* cc65 */ #include "asmlabel.h" /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ -unsigned GetLabel (void) +unsigned GetLocalLabel (void) /* Get an unused label. Will never return zero. */ { /* Number to generate unique labels */ @@ -53,3 +56,16 @@ unsigned GetLabel (void) +const char* LocalLabelName (unsigned L) +/* Make a label name from the given label number. The label name will be + * created in static storage and overwritten when calling the function + * again. + */ +{ + static char Buf[64]; + sprintf (Buf, "L%04X", L); + return Buf; +} + + + diff --git a/src/cc65/asmlabel.h b/src/cc65/asmlabel.h index 9dbc6f989..71002d017 100644 --- a/src/cc65/asmlabel.h +++ b/src/cc65/asmlabel.h @@ -44,9 +44,15 @@ -unsigned GetLabel (void); +unsigned GetLocalLabel (void); /* Get an unused assembler label. Will never return zero. */ +const char* LocalLabelName (unsigned L); +/* Make a label name from the given label number. The label name will be + * created in static storage and overwritten when calling the function + * again. + */ + /* End of asmlabel.h */ diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index a67cde071..a24ac6b73 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -581,7 +581,7 @@ void g_save_regvars (int RegOffs, unsigned Bytes) } else { /* More than two bytes - loop */ - unsigned Label = GetLabel (); + unsigned Label = GetLocalLabel (); g_space (Bytes); ldyconst (Bytes - 1); ldxconst (Bytes); @@ -626,7 +626,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) } else { /* More than two bytes - loop */ - unsigned Label = GetLabel (); + unsigned Label = GetLocalLabel (); ldyconst (StackOffs+Bytes-1); ldxconst (Bytes); g_defloclabel (Label); @@ -1693,7 +1693,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, case CF_INT: if (flags & CF_CONST) { if (val == 1) { - label = GetLabel (); + label = GetLocalLabel (); AddCodeLine ("\tinc\t%s", lbuf); AddCodeLine ("\tbne\tL%04X", (int)label); AddCodeLine ("\tinc\t%s+1", lbuf); @@ -1706,7 +1706,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, AddCodeLine ("\tadc\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf); if (val < 0x100) { - label = GetLabel (); + label = GetLocalLabel (); AddCodeLine ("\tbcc\tL%04X", (int)label); AddCodeLine ("\tinc\t%s+1", lbuf); g_defloclabel (label); @@ -1954,7 +1954,7 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs, AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val); AddCodeLine ("\tsta\t%s", lbuf); if (val < 0x100) { - label = GetLabel (); + label = GetLocalLabel (); AddCodeLine ("\tbcs\tL%04X", (unsigned)label); AddCodeLine ("\tdec\t%s+1", lbuf); g_defloclabel (label); @@ -3927,7 +3927,7 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs) /* Inline the strlen() function */ { /* We need a label in both cases */ - unsigned label = GetLabel (); + unsigned label = GetLocalLabel (); /* Two different encodings */ if (flags & CF_CONST) { diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 6d805f95c..2d04142bc 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -675,11 +675,11 @@ static unsigned FunctionParamList (FuncDesc* Func) } /* The function returns the size of all parameters pushed onto the stack. - * However, if there are parameters missing (which is an error and was + * However, if there are parameters missing (which is an error and was * flagged by the compiler) AND a stack frame was preallocated above, * we would loose track of the stackpointer and generate an internal error * later. So we correct the value by the parameters that should have been - * pushed to avoid an internal compiler error. Since an error was + * pushed to avoid an internal compiler error. Since an error was * generated before, no code will be output anyway. */ return ParamSize + FrameSize; @@ -2397,7 +2397,7 @@ static int hieAnd (struct expent* lval, unsigned TrueLab, int* BoolOp) *BoolOp = 1; /* Get a label that we will use for false expressions */ - lab = GetLabel (); + lab = GetLocalLabel (); /* If the expr hasn't set condition codes, set the force-test flag */ if ((lval->e_test & E_CC) == 0) { @@ -2456,7 +2456,7 @@ static int hieOr (struct expent *lval) unsigned DoneLab; /* Get a label */ - TrueLab = GetLabel (); + TrueLab = GetLocalLabel (); /* Call the next level parser */ k = hieAnd (lval, TrueLab, &BoolOp); @@ -2516,7 +2516,7 @@ static int hieOr (struct expent *lval) /* If we really had boolean ops, generate the end sequence */ if (BoolOp) { - DoneLab = GetLabel (); + DoneLab = GetLocalLabel (); g_getimmed (CF_INT | CF_CONST, 0, 0); /* Load FALSE */ g_falsejump (CF_NONE, DoneLab); g_defloclabel (TrueLab); @@ -2552,12 +2552,12 @@ static int hieQuest (struct expent *lval) lval->e_test |= E_FORCETEST; } exprhs (CF_NONE, k, lval); - labf = GetLabel (); + labf = GetLocalLabel (); g_falsejump (CF_NONE, labf); /* Parse second and third expression */ expression1 (&lval2); - labt = GetLabel (); + labt = GetLocalLabel (); ConsumeColon (); g_jump (labt); g_defloclabel (labf); @@ -2587,7 +2587,7 @@ static int hieQuest (struct expent *lval) /* Setup a new label so that the expr3 code will jump around * the type cast code for expr2. */ - labf = GetLabel (); /* Get new label */ + labf = GetLocalLabel (); /* Get new label */ Mark1 = GetCodePos (); /* Remember current position */ g_jump (labf); /* Jump around code */ diff --git a/src/cc65/function.c b/src/cc65/function.c index f6d64ffab..5165d48c0 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -91,7 +91,7 @@ static Function* NewFunction (struct SymEntry* Sym) F->ReturnType = Sym->Type + 1 + DECODE_SIZE; F->Desc = (FuncDesc*) DecodePtr (Sym->Type + 1); F->Reserved = 0; - F->RetLab = GetLabel (); + F->RetLab = GetLocalLabel (); F->TopLevelSP = 0; /* Return the new structure */ diff --git a/src/cc65/litpool.c b/src/cc65/litpool.c index e47ae2c94..2ba2d7456 100644 --- a/src/cc65/litpool.c +++ b/src/cc65/litpool.c @@ -72,7 +72,7 @@ void InitLiteralPool (void) /* Initialize the literal pool */ { /* Get the pool label */ - LiteralPoolLabel = GetLabel (); + LiteralPoolLabel = GetLocalLabel (); } diff --git a/src/cc65/locals.c b/src/cc65/locals.c index c10083ec4..6e29f3ab7 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -229,7 +229,7 @@ static void ParseOneDecl (const DeclSpec* Spec) g_usebss (); /* Define the variable label */ - SymData = GetLabel (); + SymData = GetLocalLabel (); g_defloclabel (SymData); /* Reserve space for the data */ @@ -279,7 +279,7 @@ static void ParseOneDecl (const DeclSpec* Spec) } /* Define the variable label */ - SymData = GetLabel (); + SymData = GetLocalLabel (); g_defloclabel (SymData); /* Skip the '=' */ @@ -297,7 +297,7 @@ static void ParseOneDecl (const DeclSpec* Spec) g_usebss (); /* Define the variable label */ - SymData = GetLabel (); + SymData = GetLocalLabel (); g_defloclabel (SymData); /* Reserve space for the data */ diff --git a/src/cc65/optimize.c b/src/cc65/optimize.c index bf4dc15bb..2c6a588e7 100644 --- a/src/cc65/optimize.c +++ b/src/cc65/optimize.c @@ -910,8 +910,8 @@ static void CreateLabelList (void) /* Get the next label number. This is also the current label count. * Make some room for more labels when optimizing code. - */ - LabelCount = GetLabel () + 100; + */ + LabelCount = GetLocalLabel () + 100; /* Allocate memory for the array and clear it */ Labels = xmalloc (LabelCount * sizeof (Line*)); diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index d3479ab1f..64ab2aa2b 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -62,7 +62,7 @@ static int doif (void) NextToken (); /* Generate a jump label and parse the condition */ - flab1 = GetLabel (); + flab1 = GetLocalLabel (); test (flab1, 0); /* Parse the if body */ @@ -87,7 +87,7 @@ static int doif (void) * clause, since the jump is never reached. */ if (!gotbreak) { - flab2 = GetLabel (); + flab2 = GetLocalLabel (); g_jump (flab2); } else { /* Mark the label as unused */ @@ -115,8 +115,8 @@ static void dowhile (char wtype) int lab; NextToken (); - loop = GetLabel (); - lab = GetLabel (); + loop = GetLocalLabel (); + lab = GetLocalLabel (); AddLoop (oursp, loop, lab, 0, 0); g_defloclabel (loop); if (wtype == 'w') { @@ -269,7 +269,7 @@ static void cascadeswitch (struct expent* eval) /* Create a loop so we may break out, init labels */ - ExitLab = GetLabel (); + ExitLab = GetLocalLabel (); AddLoop (oursp, 0, ExitLab, 0, 0); /* Setup some variables needed in the loop below */ @@ -290,7 +290,7 @@ static void cascadeswitch (struct expent* eval) if (!HaveBreak) { /* Define a label for the code */ if (CodeLab == 0) { - CodeLab = GetLabel (); + CodeLab = GetLocalLabel (); } g_jump (CodeLab); } @@ -363,13 +363,13 @@ static void cascadeswitch (struct expent* eval) if (curtok == TOK_CASE) { /* Create a code label if needed */ if (CodeLab == 0) { - CodeLab = GetLabel (); + CodeLab = GetLocalLabel (); } g_falsejump (CF_NONE, CodeLab); } else if (curtok != TOK_DEFAULT) { /* No case follows, jump to next selector */ if (NextLab == 0) { - NextLab = GetLabel (); + NextLab = GetLocalLabel (); } g_truejump (CF_NONE, NextLab); } @@ -385,7 +385,7 @@ static void cascadeswitch (struct expent* eval) /* Handle the pathologic case: DEFAULT followed by CASE */ if (curtok == TOK_CASE) { if (CodeLab == 0) { - CodeLab = GetLabel (); + CodeLab = GetLocalLabel (); } g_jump (CodeLab); } @@ -460,19 +460,19 @@ static void tableswitch (struct expent* eval) HaveBreak = 0; /* Keep gcc silent */ HaveDefault = 0; /* No default case until now */ dlabel = 0; /* init */ - lab = GetLabel (); /* get exit */ + lab = GetLocalLabel (); /* get exit */ p = swtab; AddLoop (oursp, 0, lab, 0, 0); /* Jump behind the code for the CASE labels */ - g_jump (lcase = GetLabel ()); + g_jump (lcase = GetLocalLabel ()); lcount = 0; while (curtok != TOK_RCURLY) { if (curtok == TOK_CASE || curtok == TOK_DEFAULT) { if (lcount >= CASE_MAX) { Fatal ("Too many case labels"); } - label = GetLabel (); + label = GetLocalLabel (); do { if (curtok == TOK_CASE) { NextToken (); @@ -581,10 +581,10 @@ static void dofor (void) struct expent lval3; NextToken (); - loop = GetLabel (); - lab = GetLabel (); - linc = GetLabel (); - lstat = GetLabel (); + loop = GetLocalLabel (); + lab = GetLocalLabel (); + linc = GetLocalLabel (); + lstat = GetLocalLabel (); AddLoop (oursp, loop, lab, linc, lstat); ConsumeLParen (); if (curtok != TOK_SEMI) { /* exp1 */ diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 16889c54a..459802b69 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -618,7 +618,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags) Entry = NewSymEntry (Name, SC_LABEL | Flags); /* Set a new label number */ - Entry->V.Label = GetLabel (); + Entry->V.Label = GetLocalLabel (); /* Add the entry to the label table */ AddSymEntry (LabelTab, Entry);