Added a new CS_RangeHasLabel function
git-svn-id: svn://svn.cc65.org/cc65/trunk@1058 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -161,7 +161,7 @@ static void CS_RemoveLabelFromHash (CodeSeg* S, CodeLabel* L)
|
|||||||
|
|
||||||
|
|
||||||
static CodeLabel* CS_AddLabelInternal (CodeSeg* S, const char* Name,
|
static CodeLabel* CS_AddLabelInternal (CodeSeg* S, const char* Name,
|
||||||
void (*ErrorFunc) (const char*, ...))
|
void (*ErrorFunc) (const char*, ...))
|
||||||
/* Add a code label for the next instruction to follow */
|
/* Add a code label for the next instruction to follow */
|
||||||
{
|
{
|
||||||
/* Calculate the hash from the name */
|
/* Calculate the hash from the name */
|
||||||
@@ -725,6 +725,36 @@ unsigned CS_GetEntryIndex (CodeSeg* S, struct CodeEntry* E)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int CS_RangeHasLabel (CodeSeg* S, unsigned Start, unsigned Count)
|
||||||
|
/* Return true if any of the code entries in the given range has a label
|
||||||
|
* attached. If the code segment does not span the given range, check the
|
||||||
|
* possible span instead.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
unsigned EntryCount = CS_GetEntryCount(S);
|
||||||
|
|
||||||
|
/* Adjust count. We expect at least Start to be valid. */
|
||||||
|
CHECK (Start < EntryCount);
|
||||||
|
if (Start + Count > EntryCount) {
|
||||||
|
Count = EntryCount - Start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check each entry. Since we have validated the index above, we may
|
||||||
|
* use the unchecked access function in the loop which is faster.
|
||||||
|
*/
|
||||||
|
while (Count--) {
|
||||||
|
const CodeEntry* E = CollAtUnchecked (&S->Entries, Start++);
|
||||||
|
if (CE_HasLabel (E)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No label in the complete range */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name)
|
CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name)
|
||||||
/* Add a code label for the next instruction to follow */
|
/* Add a code label for the next instruction to follow */
|
||||||
{
|
{
|
||||||
@@ -806,6 +836,7 @@ void CS_MergeLabels (CodeSeg* S)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
unsigned J;
|
||||||
|
|
||||||
/* First, remove all labels from the label symbol table that don't have an
|
/* 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
|
* owner (this means that they are actually external labels but we didn't
|
||||||
@@ -817,12 +848,25 @@ void CS_MergeLabels (CodeSeg* S)
|
|||||||
CodeLabel** L = &S->LabelHash[I];
|
CodeLabel** L = &S->LabelHash[I];
|
||||||
while (*L) {
|
while (*L) {
|
||||||
if ((*L)->Owner == 0) {
|
if ((*L)->Owner == 0) {
|
||||||
/* The label does not have an owner, remove it from the chain */
|
|
||||||
|
/* The label does not have an owner, remove it from the chain */
|
||||||
CodeLabel* X = *L;
|
CodeLabel* X = *L;
|
||||||
*L = X->Next;
|
*L = X->Next;
|
||||||
|
|
||||||
|
/* Cleanup any entries jumping to this label */
|
||||||
|
for (J = 0; J < CL_GetRefCount (X); ++J) {
|
||||||
|
/* Get the entry referencing this label */
|
||||||
|
CodeEntry* E = CL_GetRef (X, J);
|
||||||
|
/* And remove the reference */
|
||||||
|
E->JumpTo = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print some debugging output */
|
||||||
if (Debug) {
|
if (Debug) {
|
||||||
printf ("Removing unused global label `%s'", X->Name);
|
printf ("Removing unused global label `%s'", X->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* And free the label */
|
||||||
FreeCodeLabel (X);
|
FreeCodeLabel (X);
|
||||||
} else {
|
} else {
|
||||||
/* Label is owned, point to next code label pointer */
|
/* Label is owned, point to next code label pointer */
|
||||||
|
|||||||
@@ -171,6 +171,12 @@ int CS_GetEntries (CodeSeg* S, struct CodeEntry** List,
|
|||||||
unsigned CS_GetEntryIndex (CodeSeg* S, struct CodeEntry* E);
|
unsigned CS_GetEntryIndex (CodeSeg* S, struct CodeEntry* E);
|
||||||
/* Return the index of a code entry */
|
/* Return the index of a code entry */
|
||||||
|
|
||||||
|
int CS_RangeHasLabel (CodeSeg* S, unsigned Start, unsigned Count);
|
||||||
|
/* Return true if any of the code entries in the given range has a label
|
||||||
|
* attached. If the code segment does not span the given range, check the
|
||||||
|
* possible span instead.
|
||||||
|
*/
|
||||||
|
|
||||||
CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name);
|
CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name);
|
||||||
/* Add a code label for the next instruction to follow */
|
/* Add a code label for the next instruction to follow */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user