1
0
mirror of https://github.com/cc65/cc65.git synced 2025-02-26 23:30:03 +00:00

More work to make user asm labels work

git-svn-id: svn://svn.cc65.org/cc65/trunk@1043 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-10-12 07:58:11 +00:00
parent b892d4b3d3
commit 9552efc1e4
3 changed files with 68 additions and 31 deletions

View File

@ -123,6 +123,10 @@ void CL_Output (const CodeLabel* L, FILE* F)
/* Output the code label to a file */
{
fprintf (F, "%s:", L->Name);
if (strlen (L->Name) > 6) {
/* Label is too long, add a linefeed */
fputc ('\n', F);
}
}

View File

@ -230,8 +230,14 @@ static const char* ReadToken (const char* L, const char* Term,
unsigned ParenCount = 0;
while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
if (I < BufSize-1) {
Buf[I++] = *L;
Buf[I] = *L;
} else if (I == BufSize-1) {
/* Cannot store this character, this is an input error (maybe
* identifier too long or similar).
*/
Error ("ASM code error: syntax error");
}
++I;
if (*L == ')') {
--ParenCount;
} else if (*L == '(') {
@ -257,7 +263,7 @@ static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
* white space, for example.
*/
{
char Mnemo[16];
char Mnemo[64];
const OPCDesc* OPC;
am_t AM = 0; /* Initialize to keep gcc silent */
char Arg[64];
@ -418,10 +424,12 @@ static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
}
/* If the instruction is a branch, check for the label and generate it
* if it does not exist. Ignore anything but local labels here.
* if it does not exist. This may lead to unused labels (if the label
* is actually an external one) which are removed by the CS_MergeLabels
* function later.
*/
Label = 0;
if (AM == AM65_BRA && Arg[0] == 'L') {
if (AM == AM65_BRA) {
/* Generate the hash over the label, then search for the label */
unsigned Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
@ -806,6 +814,30 @@ void CS_MergeLabels (CodeSeg* S)
{
unsigned I;
/* First, remove all labels from the label symbol table that don't have an
* owner (this means that they are actually external labels but we didn't
* know that previously since they may have also been forward references).
*/
for (I = 0; I < CS_LABEL_HASH_SIZE; ++I) {
/* Get the first label in this hash chain */
CodeLabel** L = &S->LabelHash[I];
while (*L) {
if ((*L)->Owner == 0) {
/* The label does not have an owner, remove it from the chain */
CodeLabel* X = *L;
*L = X->Next;
if (Debug) {
printf ("Removing unused global label `%s'", X->Name);
}
FreeCodeLabel (X);
} else {
/* Label is owned, point to next code label pointer */
L = &((*L)->Next);
}
}
}
/* Walk over all code entries */
for (I = 0; I < CS_GetEntryCount (S); ++I) {

View File

@ -867,7 +867,8 @@ unsigned OptCmp7 (CodeSeg* S)
CS_DelEntry (S, I+1);
} else {
CodeLabel* L = N->JumpTo;
CodeEntry* X = NewCodeEntry (OP65_JMP, AM65_BRA, L->Name, L, N->LI);
const char* LabelName = L? L->Name : N->Arg;
CodeEntry* X = NewCodeEntry (OP65_JMP, AM65_BRA, LabelName, L, N->LI);
CS_InsertEntry (S, X, I+2);
CS_DelEntry (S, I+1);
}