summaryrefslogtreecommitdiff
path: root/labels.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2005-01-15 22:15:51 +0000
committerH. Peter Anvin <hpa@zytor.com>2005-01-15 22:15:51 +0000
commite2c80181b6a6338f0381fc9c44fae32d8b8a20fc (patch)
treef9919ba3c0489d886c9a79e73257ef6a4584aafc /labels.c
parent5180bc8a598aa5bff7bfb3726771e5bf348e61a2 (diff)
downloadnasm-e2c80181b6a6338f0381fc9c44fae32d8b8a20fc.tar.gz
nasm-e2c80181b6a6338f0381fc9c44fae32d8b8a20fc.tar.bz2
nasm-e2c80181b6a6338f0381fc9c44fae32d8b8a20fc.zip
Apply Nindent to all .c and .h files
Diffstat (limited to 'labels.c')
-rw-r--r--labels.c310
1 files changed, 161 insertions, 149 deletions
diff --git a/labels.c b/labels.c
index 833ad84..4d2c347 100644
--- a/labels.c
+++ b/labels.c
@@ -29,17 +29,17 @@
((c) == '.' || (c) == '@') : \
((c) == '.'))
-#define LABEL_BLOCK 32 /* no. of labels/block */
+#define LABEL_BLOCK 32 /* no. of labels/block */
#define LBLK_SIZE (LABEL_BLOCK*sizeof(union label))
-#define LABEL_HASHES 37 /* no. of hash table entries */
+#define LABEL_HASHES 37 /* no. of hash table entries */
-#define END_LIST -3 /* don't clash with NO_SEG! */
+#define END_LIST -3 /* don't clash with NO_SEG! */
#define END_BLOCK -2
#define BOGUS_VALUE -4
-#define PERMTS_SIZE 4096 /* size of text blocks */
+#define PERMTS_SIZE 4096 /* size of text blocks */
#if (PERMTS_SIZE > IDLEN_MAX)
-#error "IPERMTS_SIZE must be less than or equal to IDLEN_MAX"
+#error "IPERMTS_SIZE must be less than or equal to IDLEN_MAX"
#endif
/* values for label.defn.is_global */
@@ -53,7 +53,7 @@
#define GLOBAL_PLACEHOLDER (GLOBAL_BIT)
#define GLOBAL_SYMBOL (DEFINED_BIT|GLOBAL_BIT)
-union label { /* actual label structures */
+union label { /* actual label structures */
struct {
long segment, offset;
char *label, *special;
@@ -65,35 +65,35 @@ union label { /* actual label structures */
} admin;
};
-struct permts { /* permanent text storage */
- struct permts *next; /* for the linked list */
- int size, usage; /* size and used space in ... */
- char data[PERMTS_SIZE]; /* ... the data block itself */
+struct permts { /* permanent text storage */
+ struct permts *next; /* for the linked list */
+ int size, usage; /* size and used space in ... */
+ char data[PERMTS_SIZE]; /* ... the data block itself */
};
-extern int global_offset_changed; /* defined in nasm.c */
+extern int global_offset_changed; /* defined in nasm.c */
-static union label *ltab[LABEL_HASHES];/* using a hash table */
-static union label *lfree[LABEL_HASHES];/* pointer into the above */
-static struct permts *perm_head; /* start of perm. text storage */
-static struct permts *perm_tail; /* end of perm. text storage */
+static union label *ltab[LABEL_HASHES]; /* using a hash table */
+static union label *lfree[LABEL_HASHES]; /* pointer into the above */
+static struct permts *perm_head; /* start of perm. text storage */
+static struct permts *perm_tail; /* end of perm. text storage */
-static void init_block (union label *blk);
-static char *perm_copy (char *string1, char *string2);
+static void init_block(union label *blk);
+static char *perm_copy(char *string1, char *string2);
static char *prevlabel;
static int initialised = FALSE;
-char lprefix[PREFIX_MAX] = {0};
-char lpostfix[PREFIX_MAX] = {0};
+char lprefix[PREFIX_MAX] = { 0 };
+char lpostfix[PREFIX_MAX] = { 0 };
/*
* Internal routine: finds the `union label' corresponding to the
* given label name. Creates a new one, if it isn't found, and if
* `create' is TRUE.
*/
-static union label *find_label (char *label, int create)
+static union label *find_label(char *label, int create)
{
int hash = 0;
char *p, *prev;
@@ -106,9 +106,11 @@ static union label *find_label (char *label, int create)
prev = "";
prevlen = strlen(prev);
p = prev;
- while (*p) hash += *p++;
+ while (*p)
+ hash += *p++;
p = label;
- while (*p) hash += *p++;
+ while (*p)
+ hash += *p++;
hash %= LABEL_HASHES;
lptr = ltab[hash];
while (lptr->admin.movingon != END_LIST) {
@@ -118,7 +120,7 @@ static union label *find_label (char *label, int create)
break;
}
if (!strncmp(lptr->defn.label, prev, prevlen) &&
- !strcmp(lptr->defn.label+prevlen, label))
+ !strcmp(lptr->defn.label + prevlen, label))
return lptr;
lptr++;
}
@@ -127,123 +129,126 @@ static union label *find_label (char *label, int create)
/*
* must allocate a new block
*/
- lfree[hash]->admin.next = (union label *) nasm_malloc (LBLK_SIZE);
+ lfree[hash]->admin.next =
+ (union label *)nasm_malloc(LBLK_SIZE);
lfree[hash] = lfree[hash]->admin.next;
init_block(lfree[hash]);
}
lfree[hash]->admin.movingon = BOGUS_VALUE;
- lfree[hash]->defn.label = perm_copy (prev, label);
+ lfree[hash]->defn.label = perm_copy(prev, label);
lfree[hash]->defn.special = NULL;
lfree[hash]->defn.is_global = NOT_DEFINED_YET;
return lfree[hash]++;
- }
- else
+ } else
return NULL;
}
-int lookup_label (char *label, long *segment, long *offset)
+int lookup_label(char *label, long *segment, long *offset)
{
union label *lptr;
if (!initialised)
return 0;
- lptr = find_label (label, 0);
+ lptr = find_label(label, 0);
if (lptr && (lptr->defn.is_global & DEFINED_BIT)) {
*segment = lptr->defn.segment;
*offset = lptr->defn.offset;
return 1;
- }
- else
+ } else
return 0;
}
-int is_extern (char *label)
+int is_extern(char *label)
{
union label *lptr;
if (!initialised)
return 0;
- lptr = find_label (label, 0);
+ lptr = find_label(label, 0);
if (lptr && (lptr->defn.is_global & EXTERN_BIT))
return 1;
else
return 0;
}
-void redefine_label (char *label, long segment, long offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt, efunc error)
+void redefine_label(char *label, long segment, long offset, char *special,
+ int is_norm, int isextrn, struct ofmt *ofmt,
+ efunc error)
{
union label *lptr;
int exi;
-
+
/* This routine possibly ought to check for phase errors. Most assemblers
* check for phase errors at this point. I don't know whether phase errors
* are even possible, nor whether they are checked somewhere else
*/
- (void) segment; /* Don't warn that this parameter is unused */
- (void) special; /* Don't warn that this parameter is unused */
- (void) is_norm; /* Don't warn that this parameter is unused */
- (void) isextrn; /* Don't warn that this parameter is unused */
- (void) ofmt; /* Don't warn that this parameter is unused */
+ (void)segment; /* Don't warn that this parameter is unused */
+ (void)special; /* Don't warn that this parameter is unused */
+ (void)is_norm; /* Don't warn that this parameter is unused */
+ (void)isextrn; /* Don't warn that this parameter is unused */
+ (void)ofmt; /* Don't warn that this parameter is unused */
#ifdef DEBUG
#if DEBUG<3
if (!strncmp(label, "debugdump", 9))
#endif
error(ERR_DEBUG, "redefine_label (%s, %ld, %08lx, %s, %d, %d)",
- label, segment, offset, special, is_norm, isextrn);
+ label, segment, offset, special, is_norm, isextrn);
#endif
- lptr = find_label (label, 1);
+ lptr = find_label(label, 1);
if (!lptr)
- error (ERR_PANIC, "can't find label `%s' on pass two", label);
-
+ error(ERR_PANIC, "can't find label `%s' on pass two", label);
+
if (!islocal(label)) {
- if (!islocalchar(*label) && lptr->defn.is_norm)
+ if (!islocalchar(*label) && lptr->defn.is_norm)
prevlabel = lptr->defn.label;
}
global_offset_changed |= (lptr->defn.offset != offset);
lptr->defn.offset = offset;
-
-if (pass0 == 1) {
- exi = !!(lptr->defn.is_global & GLOBAL_BIT);
- if (exi)
- {
- char *xsymbol;
- int slen;
- slen = strlen(lprefix);
- slen += strlen(lptr->defn.label);
- slen += strlen(lpostfix);
- slen++; /* room for that null char */
- xsymbol = nasm_malloc(slen);
- snprintf(xsymbol,slen,"%s%s%s",lprefix,lptr->defn.label,lpostfix);
-
- ofmt->symdef (xsymbol, segment, offset, exi,
- special ? special : lptr->defn.special);
- ofmt->current_dfmt->debug_deflabel (xsymbol, segment, offset, exi,
- special ? special : lptr->defn.special);
+
+ if (pass0 == 1) {
+ exi = !!(lptr->defn.is_global & GLOBAL_BIT);
+ if (exi) {
+ char *xsymbol;
+ int slen;
+ slen = strlen(lprefix);
+ slen += strlen(lptr->defn.label);
+ slen += strlen(lpostfix);
+ slen++; /* room for that null char */
+ xsymbol = nasm_malloc(slen);
+ snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label,
+ lpostfix);
+
+ ofmt->symdef(xsymbol, segment, offset, exi,
+ special ? special : lptr->defn.special);
+ ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset,
+ exi,
+ special ? special : lptr->
+ defn.special);
/** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/
+ } else {
+ if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) !=
+ EXTERN_BIT) {
+ ofmt->symdef(lptr->defn.label, segment, offset, exi,
+ special ? special : lptr->defn.special);
+ ofmt->current_dfmt->debug_deflabel(label, segment, offset,
+ exi,
+ special ? special :
+ lptr->defn.special);
+ }
+ }
}
- else
- {
- if ( (lptr->defn.is_global & (GLOBAL_BIT|EXTERN_BIT)) != EXTERN_BIT ) {
- ofmt->symdef (lptr->defn.label, segment, offset, exi,
- special ? special : lptr->defn.special);
- ofmt->current_dfmt->debug_deflabel (label, segment, offset, exi,
- special ? special : lptr->defn.special);
- }
- }
-} /* if (pass0 == 1) */
-
+ /* if (pass0 == 1) */
}
-void define_label (char *label, long segment, long offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt, efunc error)
+void define_label(char *label, long segment, long offset, char *special,
+ int is_norm, int isextrn, struct ofmt *ofmt, efunc error)
{
union label *lptr;
int exi;
@@ -253,72 +258,75 @@ void define_label (char *label, long segment, long offset, char *special,
if (!strncmp(label, "debugdump", 9))
#endif
error(ERR_DEBUG, "define_label (%s, %ld, %08lx, %s, %d, %d)",
- label, segment, offset, special, is_norm, isextrn);
+ label, segment, offset, special, is_norm, isextrn);
#endif
- lptr = find_label (label, 1);
+ lptr = find_label(label, 1);
if (lptr->defn.is_global & DEFINED_BIT) {
error(ERR_NONFATAL, "symbol `%s' redefined", label);
return;
}
lptr->defn.is_global |= DEFINED_BIT;
if (isextrn)
- lptr->defn.is_global |= EXTERN_BIT;
+ lptr->defn.is_global |= EXTERN_BIT;
- if (!islocalchar(label[0]) && is_norm) /* not local, but not special either */
- prevlabel = lptr->defn.label;
+ if (!islocalchar(label[0]) && is_norm) /* not local, but not special either */
+ prevlabel = lptr->defn.label;
else if (islocal(label) && !*prevlabel) {
- error(ERR_NONFATAL, "attempt to define a local label before any"
- " non-local labels");
- }
+ error(ERR_NONFATAL, "attempt to define a local label before any"
+ " non-local labels");
+ }
lptr->defn.segment = segment;
lptr->defn.offset = offset;
lptr->defn.is_norm = (!islocalchar(label[0]) && is_norm);
-if (pass0 == 1 || (!is_norm && !isextrn && (segment&1))) {
- exi = !!(lptr->defn.is_global & GLOBAL_BIT);
- if (exi)
- {
- char *xsymbol;
- int slen;
- slen = strlen(lprefix);
- slen += strlen(lptr->defn.label);
- slen += strlen(lpostfix);
- slen++; /* room for that null char */
- xsymbol = nasm_malloc(slen);
- snprintf(xsymbol,slen,"%s%s%s",lprefix,lptr->defn.label,lpostfix);
-
- ofmt->symdef (xsymbol, segment, offset, exi,
- special ? special : lptr->defn.special);
- ofmt->current_dfmt->debug_deflabel (xsymbol, segment, offset, exi,
- special ? special : lptr->defn.special);
+ if (pass0 == 1 || (!is_norm && !isextrn && (segment & 1))) {
+ exi = !!(lptr->defn.is_global & GLOBAL_BIT);
+ if (exi) {
+ char *xsymbol;
+ int slen;
+ slen = strlen(lprefix);
+ slen += strlen(lptr->defn.label);
+ slen += strlen(lpostfix);
+ slen++; /* room for that null char */
+ xsymbol = nasm_malloc(slen);
+ snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label,
+ lpostfix);
+
+ ofmt->symdef(xsymbol, segment, offset, exi,
+ special ? special : lptr->defn.special);
+ ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset,
+ exi,
+ special ? special : lptr->
+ defn.special);
/** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/
- }
- else
- {
- if ( (lptr->defn.is_global & (GLOBAL_BIT|EXTERN_BIT)) != EXTERN_BIT ) {
- ofmt->symdef (lptr->defn.label, segment, offset, exi,
- special ? special : lptr->defn.special);
- ofmt->current_dfmt->debug_deflabel (label, segment, offset, exi,
- special ? special : lptr->defn.special);
- }
- }
-} /* if (pass0 == 1) */
+ } else {
+ if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) !=
+ EXTERN_BIT) {
+ ofmt->symdef(lptr->defn.label, segment, offset, exi,
+ special ? special : lptr->defn.special);
+ ofmt->current_dfmt->debug_deflabel(label, segment, offset,
+ exi,
+ special ? special :
+ lptr->defn.special);
+ }
+ }
+ } /* if (pass0 == 1) */
}
-void define_common (char *label, long segment, long size, char *special,
- struct ofmt *ofmt, efunc error)
+void define_common(char *label, long segment, long size, char *special,
+ struct ofmt *ofmt, efunc error)
{
union label *lptr;
- lptr = find_label (label, 1);
+ lptr = find_label(label, 1);
if (lptr->defn.is_global & DEFINED_BIT) {
error(ERR_NONFATAL, "symbol `%s' redefined", label);
return;
}
lptr->defn.is_global |= DEFINED_BIT;
- if (!islocalchar(label[0])) /* not local, but not special either */
+ if (!islocalchar(label[0])) /* not local, but not special either */
prevlabel = lptr->defn.label;
else
error(ERR_NONFATAL, "attempt to define a local label as a "
@@ -327,13 +335,14 @@ void define_common (char *label, long segment, long size, char *special,
lptr->defn.segment = segment;
lptr->defn.offset = 0;
- ofmt->symdef (lptr->defn.label, segment, size, 2,
- special ? special : lptr->defn.special);
+ ofmt->symdef(lptr->defn.label, segment, size, 2,
+ special ? special : lptr->defn.special);
ofmt->current_dfmt->debug_deflabel(lptr->defn.label, segment, size, 2,
- special ? special : lptr->defn.special);
+ special ? special : lptr->defn.
+ special);
}
-void declare_as_global (char *label, char *special, efunc error)
+void declare_as_global(char *label, char *special, efunc error)
{
union label *lptr;
@@ -342,16 +351,16 @@ void declare_as_global (char *label, char *special, efunc error)
" global", label);
return;
}
- lptr = find_label (label, 1);
+ lptr = find_label(label, 1);
switch (lptr->defn.is_global & TYPE_MASK) {
- case NOT_DEFINED_YET:
+ case NOT_DEFINED_YET:
lptr->defn.is_global = GLOBAL_PLACEHOLDER;
lptr->defn.special = special ? perm_copy(special, "") : NULL;
break;
- case GLOBAL_PLACEHOLDER: /* already done: silently ignore */
- case GLOBAL_SYMBOL:
+ case GLOBAL_PLACEHOLDER: /* already done: silently ignore */
+ case GLOBAL_SYMBOL:
break;
- case LOCAL_SYMBOL:
+ case LOCAL_SYMBOL:
if (!lptr->defn.is_global & EXTERN_BIT)
error(ERR_NONFATAL, "symbol `%s': GLOBAL directive must"
" appear before symbol definition", label);
@@ -359,23 +368,23 @@ void declare_as_global (char *label, char *special, efunc error)
}
}
-int init_labels (void)
+int init_labels(void)
{
int i;
- for (i=0; i<LABEL_HASHES; i++) {
- ltab[i] = (union label *) nasm_malloc (LBLK_SIZE);
+ for (i = 0; i < LABEL_HASHES; i++) {
+ ltab[i] = (union label *)nasm_malloc(LBLK_SIZE);
if (!ltab[i])
- return -1; /* can't initialise, panic */
- init_block (ltab[i]);
+ return -1; /* can't initialise, panic */
+ init_block(ltab[i]);
lfree[i] = ltab[i];
}
- perm_head =
- perm_tail = (struct permts *) nasm_malloc (sizeof(struct permts));
+ perm_head =
+ perm_tail = (struct permts *)nasm_malloc(sizeof(struct permts));
if (!perm_head)
- return -1;
+ return -1;
perm_head->next = NULL;
perm_head->size = PERMTS_SIZE;
@@ -388,21 +397,22 @@ int init_labels (void)
return 0;
}
-void cleanup_labels (void)
+void cleanup_labels(void)
{
int i;
initialised = FALSE;
- for (i=0; i<LABEL_HASHES; i++) {
+ for (i = 0; i < LABEL_HASHES; i++) {
union label *lptr, *lhold;
lptr = lhold = ltab[i];
while (lptr) {
- while (lptr->admin.movingon != END_BLOCK) lptr++;
+ while (lptr->admin.movingon != END_BLOCK)
+ lptr++;
lptr = lptr->admin.next;
- nasm_free (lhold);
+ nasm_free(lhold);
lhold = lptr;
}
}
@@ -410,35 +420,37 @@ void cleanup_labels (void)
while (perm_head) {
perm_tail = perm_head;
perm_head = perm_head->next;
- nasm_free (perm_tail);
+ nasm_free(perm_tail);
}
}
-static void init_block (union label *blk)
+static void init_block(union label *blk)
{
int j;
- for (j=0; j<LABEL_BLOCK-1; j++)
- blk[j].admin.movingon = END_LIST;
- blk[LABEL_BLOCK-1].admin.movingon = END_BLOCK;
- blk[LABEL_BLOCK-1].admin.next = NULL;
+ for (j = 0; j < LABEL_BLOCK - 1; j++)
+ blk[j].admin.movingon = END_LIST;
+ blk[LABEL_BLOCK - 1].admin.movingon = END_BLOCK;
+ blk[LABEL_BLOCK - 1].admin.next = NULL;
}
-static char *perm_copy (char *string1, char *string2)
+static char *perm_copy(char *string1, char *string2)
{
char *p, *q;
- int len = strlen(string1)+strlen(string2)+1;
+ int len = strlen(string1) + strlen(string2) + 1;
if (perm_tail->size - perm_tail->usage < len) {
- perm_tail->next = (struct permts *)nasm_malloc(sizeof(struct permts));
+ perm_tail->next =
+ (struct permts *)nasm_malloc(sizeof(struct permts));
perm_tail = perm_tail->next;
perm_tail->next = NULL;
perm_tail->size = PERMTS_SIZE;
perm_tail->usage = 0;
}
p = q = perm_tail->data + perm_tail->usage;
- while ( (*q = *string1++) ) q++;
- while ( (*q++ = *string2++) ) ;
+ while ((*q = *string1++))
+ q++;
+ while ((*q++ = *string2++)) ;
perm_tail->usage = q - perm_tail->data;
return p;