/* */
/* */
/* */
-/* (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 */
+#include <stdio.h>
+
+/* 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 */
+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;
+}
+
+
+
-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 */
} else {
/* More than two bytes - loop */
- unsigned Label = GetLabel ();
+ unsigned Label = GetLocalLabel ();
g_space (Bytes);
ldyconst (Bytes - 1);
ldxconst (Bytes);
} else {
/* More than two bytes - loop */
- unsigned Label = GetLabel ();
+ unsigned Label = GetLocalLabel ();
ldyconst (StackOffs+Bytes-1);
ldxconst (Bytes);
g_defloclabel (Label);
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);
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);
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);
/* Inline the strlen() function */
{
/* We need a label in both cases */
- unsigned label = GetLabel ();
+ unsigned label = GetLocalLabel ();
/* Two different encodings */
if (flags & CF_CONST) {
}
/* 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;
*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) {
unsigned DoneLab;
/* Get a label */
- TrueLab = GetLabel ();
+ TrueLab = GetLocalLabel ();
/* Call the next level parser */
k = hieAnd (lval, TrueLab, &BoolOp);
/* 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);
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);
/* 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 */
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 */
/* Initialize the literal pool */
{
/* Get the pool label */
- LiteralPoolLabel = GetLabel ();
+ LiteralPoolLabel = GetLocalLabel ();
}
g_usebss ();
/* Define the variable label */
- SymData = GetLabel ();
+ SymData = GetLocalLabel ();
g_defloclabel (SymData);
/* Reserve space for the data */
}
/* Define the variable label */
- SymData = GetLabel ();
+ SymData = GetLocalLabel ();
g_defloclabel (SymData);
/* Skip the '=' */
g_usebss ();
/* Define the variable label */
- SymData = GetLabel ();
+ SymData = GetLocalLabel ();
g_defloclabel (SymData);
/* Reserve space for the data */
/* 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*));
NextToken ();
/* Generate a jump label and parse the condition */
- flab1 = GetLabel ();
+ flab1 = GetLocalLabel ();
test (flab1, 0);
/* Parse the if body */
* clause, since the jump is never reached.
*/
if (!gotbreak) {
- flab2 = GetLabel ();
+ flab2 = GetLocalLabel ();
g_jump (flab2);
} else {
/* Mark the label as unused */
int lab;
NextToken ();
- loop = GetLabel ();
- lab = GetLabel ();
+ loop = GetLocalLabel ();
+ lab = GetLocalLabel ();
AddLoop (oursp, loop, lab, 0, 0);
g_defloclabel (loop);
if (wtype == 'w') {
/* 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 */
if (!HaveBreak) {
/* Define a label for the code */
if (CodeLab == 0) {
- CodeLab = GetLabel ();
+ CodeLab = GetLocalLabel ();
}
g_jump (CodeLab);
}
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);
}
/* Handle the pathologic case: DEFAULT followed by CASE */
if (curtok == TOK_CASE) {
if (CodeLab == 0) {
- CodeLab = GetLabel ();
+ CodeLab = GetLocalLabel ();
}
g_jump (CodeLab);
}
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 ();
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 */
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);