/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
static const char* MakeLabelName (unsigned Addr)
/* Make the default label name from the given address and return it in a
- * static buffer.
- */
+** static buffer.
+*/
{
static char LabelBuf [32];
xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr);
/* Must not have two symbols for one address */
if (ExistingAttr != atNoLabel) {
- /* Allow redefinition if identical. Beware: Unnamed labels don't
- * have a name (you guessed that, didn't you?).
- */
- if (ExistingAttr == Attr &&
+ /* Allow redefinition if identical. Beware: Unnamed labels don't
+ ** have a name (you guessed that, didn't you?).
+ */
+ if (ExistingAttr == Attr &&
((Name == 0 && SymTab[Addr] == 0) || strcmp (SymTab[Addr], Name) == 0)) {
- return;
- }
- Error ("Duplicate label for address $%04X: %s/%s", Addr, SymTab[Addr], Name);
+ return;
+ }
+ Error ("Duplicate label for address $%04X: %s/%s", Addr, SymTab[Addr], Name);
}
/* Create a new label (xstrdup will return NULL if input NULL) */
void AddDepLabel (unsigned Addr, attr_t Attr, const char* BaseName, unsigned Offs)
/* Add a dependent label at the given address using "basename+Offs" as the new
- * name.
- */
+** name.
+*/
{
/* Allocate memory for the dependent label name */
unsigned NameLen = strlen (BaseName);
- char* DepName = xmalloc (NameLen + 7); /* "+$ABCD\0" */
+ char* DepName = xmalloc (NameLen + 7); /* "+$ABCD\0" */
/* Create the new name in the buffer */
if (UseHexOffs) {
- sprintf (DepName, "%s+$%02X", BaseName, Offs);
+ sprintf (DepName, "%s+$%02X", BaseName, Offs);
} else {
- sprintf (DepName, "%s+%u", BaseName, Offs);
+ sprintf (DepName, "%s+%u", BaseName, Offs);
}
/* Define the labels */
static void AddLabelRange (unsigned Addr, attr_t Attr,
const char* Name, unsigned Count)
/* Add a label for a range. The first entry gets the label "Name" while the
- * others get "Name+offs".
- */
+** others get "Name+offs".
+*/
{
/* Define the label */
AddLabel (Addr, Attr, Name);
/* Define dependent labels if necessary */
if (Count > 1) {
- unsigned Offs;
+ unsigned Offs;
/* Setup the format string */
const char* Format = UseHexOffs? "$%02X" : "%u";
- /* Allocate memory for the dependent label names */
- unsigned NameLen = strlen (Name);
- char* DepName = xmalloc (NameLen + 7); /* "+$ABCD" */
- char* DepOffs = DepName + NameLen + 1;
+ /* Allocate memory for the dependent label names */
+ unsigned NameLen = strlen (Name);
+ char* DepName = xmalloc (NameLen + 7); /* "+$ABCD" */
+ char* DepOffs = DepName + NameLen + 1;
- /* Copy the original name into the buffer */
- memcpy (DepName, Name, NameLen);
- DepName[NameLen] = '+';
+ /* Copy the original name into the buffer */
+ memcpy (DepName, Name, NameLen);
+ DepName[NameLen] = '+';
- /* Define the labels */
- for (Offs = 1; Offs < Count; ++Offs) {
- sprintf (DepOffs, Format, Offs);
- AddLabel (Addr + Offs, Attr | atDepLabel, DepName);
- }
+ /* Define the labels */
+ for (Offs = 1; Offs < Count; ++Offs) {
+ sprintf (DepOffs, Format, Offs);
+ AddLabel (Addr + Offs, Attr | atDepLabel, DepName);
+ }
- /* Free the name buffer */
- xfree (DepName);
+ /* Free the name buffer */
+ xfree (DepName);
}
}
void AddIntLabelRange (unsigned Addr, const char* Name, unsigned Count)
/* Add an internal label for a range. The first entry gets the label "Name"
- * while the others get "Name+offs".
- */
+** while the others get "Name+offs".
+*/
{
/* Define the label range */
AddLabelRange (Addr, atIntLabel, Name, Count);
void AddExtLabelRange (unsigned Addr, const char* Name, unsigned Count)
/* Add an external label for a range. The first entry gets the label "Name"
- * while the others get "Name+offs".
- */
+** while the others get "Name+offs".
+*/
{
/* Define the label range */
AddLabelRange (Addr, atExtLabel, Name, Count);
int MustDefLabel (unsigned Addr)
/* Return true if we must define a label for this address, that is, if there
- * is a label at this address, and it is an external or internal label.
- */
+** is a label at this address, and it is an external or internal label.
+*/
{
/* Get the label attribute */
attr_t A = GetLabelAttr (Addr);
attr_t A = GetLabelAttr (Addr);
/* Special case unnamed labels, because these don't have a named stored in
- * the symbol table to save space.
- */
+ ** the symbol table to save space.
+ */
if (A == atUnnamedLabel) {
return "";
} else {
const char* GetLabel (unsigned Addr, unsigned RefFrom)
/* Return the label name for an address, as it is used in a label reference.
- * RefFrom is the address the label is referenced from. This is needed in case
- * of unnamed labels, to determine the name.
- */
+** RefFrom is the address the label is referenced from. This is needed in case
+** of unnamed labels, to determine the name.
+*/
{
static const char* FwdLabels[] = {
":+", ":++", ":+++", ":++++", ":+++++", ":++++++", ":+++++++",
attr_t A = GetLabelAttr (Addr);
/* Special case unnamed labels, because these don't have a named stored in
- * the symbol table to save space.
- */
+ ** the symbol table to save space.
+ */
if (A == atUnnamedLabel) {
unsigned Count = 0;
/* Search forward or backward depending in which direction the label
- * is.
- */
+ ** is.
+ */
if (Addr <= RefFrom) {
/* Search backwards */
unsigned I = RefFrom;
void ForwardLabel (unsigned Offs)
/* If necessary, output a forward label, one that is within the next few
- * bytes and is therefore output as "label = * + x".
- */
+** bytes and is therefore output as "label = * + x".
+*/
{
/* Calculate the actual address */
unsigned long Addr = PC + Offs;
}
/* An unnamed label cannot be output as a forward declaration, so this is
- * an error.
- */
+ ** an error.
+ */
if (A == atUnnamedLabel) {
Error ("Cannot define unnamed label at address $%04lX", Addr);
}
SeparatorLine ();
}
-
-
-