1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 00:07:21 +00:00

Renamed GetLabel to GetLocalLabel

git-svn-id: svn://svn.cc65.org/cc65/trunk@692 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-04-19 06:49:08 +00:00
parent 71e40d42f5
commit 9cb63b679c
10 changed files with 67 additions and 45 deletions

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
@ -33,6 +33,9 @@
#include <stdio.h>
/* cc65 */
#include "asmlabel.h" #include "asmlabel.h"
@ -43,7 +46,7 @@
unsigned GetLabel (void) unsigned GetLocalLabel (void)
/* Get an unused label. Will never return zero. */ /* Get an unused label. Will never return zero. */
{ {
/* Number to generate unique labels */ /* 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;
}

View File

@ -44,9 +44,15 @@
unsigned GetLabel (void); unsigned GetLocalLabel (void);
/* Get an unused assembler label. Will never return zero. */ /* 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 */ /* End of asmlabel.h */

View File

@ -581,7 +581,7 @@ void g_save_regvars (int RegOffs, unsigned Bytes)
} else { } else {
/* More than two bytes - loop */ /* More than two bytes - loop */
unsigned Label = GetLabel (); unsigned Label = GetLocalLabel ();
g_space (Bytes); g_space (Bytes);
ldyconst (Bytes - 1); ldyconst (Bytes - 1);
ldxconst (Bytes); ldxconst (Bytes);
@ -626,7 +626,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
} else { } else {
/* More than two bytes - loop */ /* More than two bytes - loop */
unsigned Label = GetLabel (); unsigned Label = GetLocalLabel ();
ldyconst (StackOffs+Bytes-1); ldyconst (StackOffs+Bytes-1);
ldxconst (Bytes); ldxconst (Bytes);
g_defloclabel (Label); g_defloclabel (Label);
@ -1693,7 +1693,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
case CF_INT: case CF_INT:
if (flags & CF_CONST) { if (flags & CF_CONST) {
if (val == 1) { if (val == 1) {
label = GetLabel (); label = GetLocalLabel ();
AddCodeLine ("\tinc\t%s", lbuf); AddCodeLine ("\tinc\t%s", lbuf);
AddCodeLine ("\tbne\tL%04X", (int)label); AddCodeLine ("\tbne\tL%04X", (int)label);
AddCodeLine ("\tinc\t%s+1", lbuf); 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 ("\tadc\t%s", lbuf);
AddCodeLine ("\tsta\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf);
if (val < 0x100) { if (val < 0x100) {
label = GetLabel (); label = GetLocalLabel ();
AddCodeLine ("\tbcc\tL%04X", (int)label); AddCodeLine ("\tbcc\tL%04X", (int)label);
AddCodeLine ("\tinc\t%s+1", lbuf); AddCodeLine ("\tinc\t%s+1", lbuf);
g_defloclabel (label); 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 ("\tsbc\t#$%02X", (unsigned char)val);
AddCodeLine ("\tsta\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf);
if (val < 0x100) { if (val < 0x100) {
label = GetLabel (); label = GetLocalLabel ();
AddCodeLine ("\tbcs\tL%04X", (unsigned)label); AddCodeLine ("\tbcs\tL%04X", (unsigned)label);
AddCodeLine ("\tdec\t%s+1", lbuf); AddCodeLine ("\tdec\t%s+1", lbuf);
g_defloclabel (label); g_defloclabel (label);
@ -3927,7 +3927,7 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
/* Inline the strlen() function */ /* Inline the strlen() function */
{ {
/* We need a label in both cases */ /* We need a label in both cases */
unsigned label = GetLabel (); unsigned label = GetLocalLabel ();
/* Two different encodings */ /* Two different encodings */
if (flags & CF_CONST) { if (flags & CF_CONST) {

View File

@ -2397,7 +2397,7 @@ static int hieAnd (struct expent* lval, unsigned TrueLab, int* BoolOp)
*BoolOp = 1; *BoolOp = 1;
/* Get a label that we will use for false expressions */ /* 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 the expr hasn't set condition codes, set the force-test flag */
if ((lval->e_test & E_CC) == 0) { if ((lval->e_test & E_CC) == 0) {
@ -2456,7 +2456,7 @@ static int hieOr (struct expent *lval)
unsigned DoneLab; unsigned DoneLab;
/* Get a label */ /* Get a label */
TrueLab = GetLabel (); TrueLab = GetLocalLabel ();
/* Call the next level parser */ /* Call the next level parser */
k = hieAnd (lval, TrueLab, &BoolOp); 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 we really had boolean ops, generate the end sequence */
if (BoolOp) { if (BoolOp) {
DoneLab = GetLabel (); DoneLab = GetLocalLabel ();
g_getimmed (CF_INT | CF_CONST, 0, 0); /* Load FALSE */ g_getimmed (CF_INT | CF_CONST, 0, 0); /* Load FALSE */
g_falsejump (CF_NONE, DoneLab); g_falsejump (CF_NONE, DoneLab);
g_defloclabel (TrueLab); g_defloclabel (TrueLab);
@ -2552,12 +2552,12 @@ static int hieQuest (struct expent *lval)
lval->e_test |= E_FORCETEST; lval->e_test |= E_FORCETEST;
} }
exprhs (CF_NONE, k, lval); exprhs (CF_NONE, k, lval);
labf = GetLabel (); labf = GetLocalLabel ();
g_falsejump (CF_NONE, labf); g_falsejump (CF_NONE, labf);
/* Parse second and third expression */ /* Parse second and third expression */
expression1 (&lval2); expression1 (&lval2);
labt = GetLabel (); labt = GetLocalLabel ();
ConsumeColon (); ConsumeColon ();
g_jump (labt); g_jump (labt);
g_defloclabel (labf); 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 /* Setup a new label so that the expr3 code will jump around
* the type cast code for expr2. * the type cast code for expr2.
*/ */
labf = GetLabel (); /* Get new label */ labf = GetLocalLabel (); /* Get new label */
Mark1 = GetCodePos (); /* Remember current position */ Mark1 = GetCodePos (); /* Remember current position */
g_jump (labf); /* Jump around code */ g_jump (labf); /* Jump around code */

View File

@ -91,7 +91,7 @@ static Function* NewFunction (struct SymEntry* Sym)
F->ReturnType = Sym->Type + 1 + DECODE_SIZE; F->ReturnType = Sym->Type + 1 + DECODE_SIZE;
F->Desc = (FuncDesc*) DecodePtr (Sym->Type + 1); F->Desc = (FuncDesc*) DecodePtr (Sym->Type + 1);
F->Reserved = 0; F->Reserved = 0;
F->RetLab = GetLabel (); F->RetLab = GetLocalLabel ();
F->TopLevelSP = 0; F->TopLevelSP = 0;
/* Return the new structure */ /* Return the new structure */

View File

@ -72,7 +72,7 @@ void InitLiteralPool (void)
/* Initialize the literal pool */ /* Initialize the literal pool */
{ {
/* Get the pool label */ /* Get the pool label */
LiteralPoolLabel = GetLabel (); LiteralPoolLabel = GetLocalLabel ();
} }

View File

@ -229,7 +229,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
g_usebss (); g_usebss ();
/* Define the variable label */ /* Define the variable label */
SymData = GetLabel (); SymData = GetLocalLabel ();
g_defloclabel (SymData); g_defloclabel (SymData);
/* Reserve space for the data */ /* Reserve space for the data */
@ -279,7 +279,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
} }
/* Define the variable label */ /* Define the variable label */
SymData = GetLabel (); SymData = GetLocalLabel ();
g_defloclabel (SymData); g_defloclabel (SymData);
/* Skip the '=' */ /* Skip the '=' */
@ -297,7 +297,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
g_usebss (); g_usebss ();
/* Define the variable label */ /* Define the variable label */
SymData = GetLabel (); SymData = GetLocalLabel ();
g_defloclabel (SymData); g_defloclabel (SymData);
/* Reserve space for the data */ /* Reserve space for the data */

View File

@ -911,7 +911,7 @@ static void CreateLabelList (void)
/* Get the next label number. This is also the current label count. /* Get the next label number. This is also the current label count.
* Make some room for more labels when optimizing code. * Make some room for more labels when optimizing code.
*/ */
LabelCount = GetLabel () + 100; LabelCount = GetLocalLabel () + 100;
/* Allocate memory for the array and clear it */ /* Allocate memory for the array and clear it */
Labels = xmalloc (LabelCount * sizeof (Line*)); Labels = xmalloc (LabelCount * sizeof (Line*));

View File

@ -62,7 +62,7 @@ static int doif (void)
NextToken (); NextToken ();
/* Generate a jump label and parse the condition */ /* Generate a jump label and parse the condition */
flab1 = GetLabel (); flab1 = GetLocalLabel ();
test (flab1, 0); test (flab1, 0);
/* Parse the if body */ /* Parse the if body */
@ -87,7 +87,7 @@ static int doif (void)
* clause, since the jump is never reached. * clause, since the jump is never reached.
*/ */
if (!gotbreak) { if (!gotbreak) {
flab2 = GetLabel (); flab2 = GetLocalLabel ();
g_jump (flab2); g_jump (flab2);
} else { } else {
/* Mark the label as unused */ /* Mark the label as unused */
@ -115,8 +115,8 @@ static void dowhile (char wtype)
int lab; int lab;
NextToken (); NextToken ();
loop = GetLabel (); loop = GetLocalLabel ();
lab = GetLabel (); lab = GetLocalLabel ();
AddLoop (oursp, loop, lab, 0, 0); AddLoop (oursp, loop, lab, 0, 0);
g_defloclabel (loop); g_defloclabel (loop);
if (wtype == 'w') { if (wtype == 'w') {
@ -269,7 +269,7 @@ static void cascadeswitch (struct expent* eval)
/* Create a loop so we may break out, init labels */ /* Create a loop so we may break out, init labels */
ExitLab = GetLabel (); ExitLab = GetLocalLabel ();
AddLoop (oursp, 0, ExitLab, 0, 0); AddLoop (oursp, 0, ExitLab, 0, 0);
/* Setup some variables needed in the loop below */ /* Setup some variables needed in the loop below */
@ -290,7 +290,7 @@ static void cascadeswitch (struct expent* eval)
if (!HaveBreak) { if (!HaveBreak) {
/* Define a label for the code */ /* Define a label for the code */
if (CodeLab == 0) { if (CodeLab == 0) {
CodeLab = GetLabel (); CodeLab = GetLocalLabel ();
} }
g_jump (CodeLab); g_jump (CodeLab);
} }
@ -363,13 +363,13 @@ static void cascadeswitch (struct expent* eval)
if (curtok == TOK_CASE) { if (curtok == TOK_CASE) {
/* Create a code label if needed */ /* Create a code label if needed */
if (CodeLab == 0) { if (CodeLab == 0) {
CodeLab = GetLabel (); CodeLab = GetLocalLabel ();
} }
g_falsejump (CF_NONE, CodeLab); g_falsejump (CF_NONE, CodeLab);
} else if (curtok != TOK_DEFAULT) { } else if (curtok != TOK_DEFAULT) {
/* No case follows, jump to next selector */ /* No case follows, jump to next selector */
if (NextLab == 0) { if (NextLab == 0) {
NextLab = GetLabel (); NextLab = GetLocalLabel ();
} }
g_truejump (CF_NONE, NextLab); g_truejump (CF_NONE, NextLab);
} }
@ -385,7 +385,7 @@ static void cascadeswitch (struct expent* eval)
/* Handle the pathologic case: DEFAULT followed by CASE */ /* Handle the pathologic case: DEFAULT followed by CASE */
if (curtok == TOK_CASE) { if (curtok == TOK_CASE) {
if (CodeLab == 0) { if (CodeLab == 0) {
CodeLab = GetLabel (); CodeLab = GetLocalLabel ();
} }
g_jump (CodeLab); g_jump (CodeLab);
} }
@ -460,19 +460,19 @@ static void tableswitch (struct expent* eval)
HaveBreak = 0; /* Keep gcc silent */ HaveBreak = 0; /* Keep gcc silent */
HaveDefault = 0; /* No default case until now */ HaveDefault = 0; /* No default case until now */
dlabel = 0; /* init */ dlabel = 0; /* init */
lab = GetLabel (); /* get exit */ lab = GetLocalLabel (); /* get exit */
p = swtab; p = swtab;
AddLoop (oursp, 0, lab, 0, 0); AddLoop (oursp, 0, lab, 0, 0);
/* Jump behind the code for the CASE labels */ /* Jump behind the code for the CASE labels */
g_jump (lcase = GetLabel ()); g_jump (lcase = GetLocalLabel ());
lcount = 0; lcount = 0;
while (curtok != TOK_RCURLY) { while (curtok != TOK_RCURLY) {
if (curtok == TOK_CASE || curtok == TOK_DEFAULT) { if (curtok == TOK_CASE || curtok == TOK_DEFAULT) {
if (lcount >= CASE_MAX) { if (lcount >= CASE_MAX) {
Fatal ("Too many case labels"); Fatal ("Too many case labels");
} }
label = GetLabel (); label = GetLocalLabel ();
do { do {
if (curtok == TOK_CASE) { if (curtok == TOK_CASE) {
NextToken (); NextToken ();
@ -581,10 +581,10 @@ static void dofor (void)
struct expent lval3; struct expent lval3;
NextToken (); NextToken ();
loop = GetLabel (); loop = GetLocalLabel ();
lab = GetLabel (); lab = GetLocalLabel ();
linc = GetLabel (); linc = GetLocalLabel ();
lstat = GetLabel (); lstat = GetLocalLabel ();
AddLoop (oursp, loop, lab, linc, lstat); AddLoop (oursp, loop, lab, linc, lstat);
ConsumeLParen (); ConsumeLParen ();
if (curtok != TOK_SEMI) { /* exp1 */ if (curtok != TOK_SEMI) { /* exp1 */

View File

@ -618,7 +618,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags)
Entry = NewSymEntry (Name, SC_LABEL | Flags); Entry = NewSymEntry (Name, SC_LABEL | Flags);
/* Set a new label number */ /* Set a new label number */
Entry->V.Label = GetLabel (); Entry->V.Label = GetLocalLabel ();
/* Add the entry to the label table */ /* Add the entry to the label table */
AddSymEntry (LabelTab, Entry); AddSymEntry (LabelTab, Entry);