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:
@@ -123,6 +123,10 @@ void CL_Output (const CodeLabel* L, FILE* F)
|
|||||||
/* Output the code label to a file */
|
/* Output the code label to a file */
|
||||||
{
|
{
|
||||||
fprintf (F, "%s:", L->Name);
|
fprintf (F, "%s:", L->Name);
|
||||||
|
if (strlen (L->Name) > 6) {
|
||||||
|
/* Label is too long, add a linefeed */
|
||||||
|
fputc ('\n', F);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -230,8 +230,14 @@ static const char* ReadToken (const char* L, const char* Term,
|
|||||||
unsigned ParenCount = 0;
|
unsigned ParenCount = 0;
|
||||||
while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
|
while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
|
||||||
if (I < BufSize-1) {
|
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 == ')') {
|
if (*L == ')') {
|
||||||
--ParenCount;
|
--ParenCount;
|
||||||
} else if (*L == '(') {
|
} else if (*L == '(') {
|
||||||
@@ -257,7 +263,7 @@ static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
|
|||||||
* white space, for example.
|
* white space, for example.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char Mnemo[16];
|
char Mnemo[64];
|
||||||
const OPCDesc* OPC;
|
const OPCDesc* OPC;
|
||||||
am_t AM = 0; /* Initialize to keep gcc silent */
|
am_t AM = 0; /* Initialize to keep gcc silent */
|
||||||
char Arg[64];
|
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 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;
|
Label = 0;
|
||||||
if (AM == AM65_BRA && Arg[0] == 'L') {
|
if (AM == AM65_BRA) {
|
||||||
|
|
||||||
/* Generate the hash over the label, then search for the label */
|
/* Generate the hash over the label, then search for the label */
|
||||||
unsigned Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
|
unsigned Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
|
||||||
@@ -806,6 +814,30 @@ void CS_MergeLabels (CodeSeg* S)
|
|||||||
{
|
{
|
||||||
unsigned I;
|
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 */
|
/* Walk over all code entries */
|
||||||
for (I = 0; I < CS_GetEntryCount (S); ++I) {
|
for (I = 0; I < CS_GetEntryCount (S); ++I) {
|
||||||
|
|
||||||
|
|||||||
@@ -867,7 +867,8 @@ unsigned OptCmp7 (CodeSeg* S)
|
|||||||
CS_DelEntry (S, I+1);
|
CS_DelEntry (S, I+1);
|
||||||
} else {
|
} else {
|
||||||
CodeLabel* L = N->JumpTo;
|
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_InsertEntry (S, X, I+2);
|
||||||
CS_DelEntry (S, I+1);
|
CS_DelEntry (S, I+1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user