char data[PERMTS_SIZE]; /* ... the data block itself */
};
-extern int global_offset_changed; /* defined in nasm.c */
+extern bool global_offset_changed; /* defined in nasm.c */
static struct hash_table *ltab; /* labels hash table */
static union label *ldata; /* all label data blocks */
static char *prevlabel;
-static int initialized = false;
+static bool initialized = false;
char lprefix[PREFIX_MAX] = { 0 };
char lpostfix[PREFIX_MAX] = { 0 };
return lfree++;
}
-int lookup_label(char *label, int32_t *segment, int32_t *offset)
+bool lookup_label(char *label, int32_t *segment, int32_t *offset)
{
union label *lptr;
if (!initialized)
- return 0;
+ return false;
lptr = find_label(label, 0);
if (lptr && (lptr->defn.is_global & DEFINED_BIT)) {
*segment = lptr->defn.segment;
*offset = lptr->defn.offset;
- return 1;
+ return true;
} else
- return 0;
+ return false;
}
-int is_extern(char *label)
+bool is_extern(char *label)
{
union label *lptr;
if (!initialized)
- return 0;
+ return false;
lptr = find_label(label, 0);
- if (lptr && (lptr->defn.is_global & EXTERN_BIT))
- return 1;
- else
- return 0;
+ return (lptr && (lptr->defn.is_global & EXTERN_BIT));
}
void redefine_label(char *label, int32_t segment, int32_t offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt,
+ bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error)
{
union label *lptr;
}
void define_label(char *label, int32_t segment, int32_t offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt, efunc error)
+ bool is_norm, bool isextrn, struct ofmt *ofmt, efunc error)
{
union label *lptr;
int exi;
* distributed in the NASM archive.
*/
+#ifndef LABELS_H
+#define LABELS_H
+
extern char lprefix[PREFIX_MAX];
extern char lpostfix[PREFIX_MAX];
-int lookup_label(char *label, int32_t *segment, int32_t *offset);
-int is_extern(char *label);
+bool lookup_label(char *label, int32_t *segment, int32_t *offset);
+bool is_extern(char *label);
void define_label(char *label, int32_t segment, int32_t offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt,
+ bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error);
void redefine_label(char *label, int32_t segment, int32_t offset, char *special,
- int is_norm, int isextrn, struct ofmt *ofmt,
+ bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error);
void define_common(char *label, int32_t segment, int32_t size, char *special,
struct ofmt *ofmt, efunc error);
void declare_as_global(char *label, char *special, efunc error);
int init_labels(void);
void cleanup_labels(void);
+
+#endif /* LABELS_H */
static uint32_t get_cpu(char *cpu_str);
static void parse_cmdline(int, char **);
static void assemble_file(char *);
-static int getkw(char **directive, char **value);
static void register_output_formats(void);
static void report_error_gnu(int severity, const char *fmt, ...);
static void report_error_vc(int severity, const char *fmt, ...);
static int sb, cmd_sb = 16; /* by default */
static uint32_t cmd_cpu = IF_PLEVEL; /* highest level by default */
static uint32_t cpu = IF_PLEVEL; /* passed to insn_size & assemble.c */
-int global_offset_changed; /* referenced in labels.c */
+bool global_offset_changed; /* referenced in labels.c */
static struct location location;
int in_abs_seg; /* Flag we are in ABSOLUTE seg */
}
/* List of directives */
-enum {
+enum directives {
D_NONE, D_ABSOLUTE, D_BITS, D_COMMON, D_CPU, D_DEBUG, D_DEFAULT,
D_EXTERN, D_GLOBAL, D_LIST, D_SECTION, D_SEGMENT, D_WARNING
};
"", "absolute", "bits", "common", "cpu", "debug", "default",
"extern", "global", "list", "section", "segment", "warning"
};
+static enum directives getkw(char **directive, char **value);
static void assemble_file(char *fname)
{
char *directive, *value, *p, *q, *special, *line, debugid[80];
insn output_ins;
- int i, rn_error, validid;
+ int i, validid;
+ bool rn_error;
int32_t seg, offs;
struct tokenval tokval;
expr *e;
location.offset = offs = GET_CURR_OFFS;
while ((line = preproc->getline())) {
+ enum directives d;
globallineno++;
/* here we parse our directives; this is not handled by the 'real'
* parser. */
directive = line;
- i = getkw(&directive, &value);
- if (i) {
+ d = getkw(&directive, &value);
+ if (d) {
int err = 0;
- switch (i) {
+ switch (d) {
case D_SEGMENT: /* [SEGMENT n] */
case D_SECTION:
seg = ofmt->section(value, pass2, &sb);
#endif
} /* exit from assemble_file (...) */
-static int getkw(char **directive, char **value)
+static enum directives getkw(char **directive, char **value)
{
char *p, *q, *buf;
/*
* A label-lookup function should look like this.
*/
-typedef int (*lfunc) (char *label, int32_t *segment, int32_t *offset);
+typedef bool (*lfunc) (char *label, int32_t *segment, int32_t *offset);
/*
* And a label-definition function like this. The boolean parameter
* an EQU or a segment-base symbol, which shouldn't.
*/
typedef void (*ldfunc) (char *label, int32_t segment, int32_t offset,
- char *special, int is_norm, int isextrn,
+ char *special, bool is_norm, bool isextrn,
struct ofmt * ofmt, efunc error);
/*
* been an EXTERN, a COMMON or a GLOBAL. The distinction should
* be obvious to the output format from the other parameters.
*/
- void (*symdef) (char *name, int32_t segment, int32_t offset, int is_global,
- char *special);
+ void (*symdef) (char *name, int32_t segment, int32_t offset,
+ int is_global, char *special);
/*
* This procedure is called when the source code requests a
#define lib_isnumchar(c) ( isalnum(c) || (c) == '$')
#define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
-int64_t readnum(char *str, int *error)
+int64_t readnum(char *str, bool *error)
{
char *r = str, *q;
int32_t radix;
uint64_t result, checklimit;
int digit, last;
- int warn = false;
+ bool warn = false;
int sign = 1;
*error = false;
return result * sign;
}
-int64_t readstrnum(char *str, int length, int *warn)
+int64_t readstrnum(char *str, int length, bool *warn)
{
int64_t charconst = 0;
int i;
* Convert a string into a number, using NASM number rules. Sets
* `*error' to true if an error occurs, and false otherwise.
*/
-int64_t readnum(char *str, int *error);
+int64_t readnum(char *str, bool *error);
/*
* Convert a character constant into a number. Sets
* str points to and length covers the middle of the string,
* without the quotes.
*/
-int64_t readstrnum(char *str, int length, int *warn);
+int64_t readstrnum(char *str, int length, bool *warn);
/*
* seg_init: Initialise the segment-number allocator.
int bits = 16, b;
bool eof = false;
uint32_t prefer = 0;
- int rn_error;
+ bool rn_error;
int32_t offset;
FILE *fp;
} *relocs, **reloctail;
extern char *stdscan_bufptr;
-extern int lookup_label(char *label, int32_t *segment, int32_t *offset);
static uint8_t format_mode; /* 0 = original bin, 1 = extended bin */
static int32_t current_section; /* only really needed if format_mode = 0 */
static struct ELF_SECTDATA {
void *data;
int32_t len;
- int is_saa;
+ bool is_saa;
} *elf_sects;
static int elf_nsect;
static int32_t elf_foffs;
* as the alignment for the common variable.
*/
if (special) {
- int err;
+ bool err;
sym->value = readnum(special, &err);
if (err)
error(ERR_NONFATAL, "alignment constraint `%s' is not a"
error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
elf_sect_write(s, data, realbytes);
} else if (type == OUT_ADDRESS) {
- int gnu16 = 0;
+ bool gnu16 = false;
addr = *(int32_t *)data;
if (segment != NO_SEG) {
if (segment % 2) {
} else {
if (wrt == NO_SEG) {
if (realbytes == 2) {
- gnu16 = 1;
+ gnu16 = true;
elf_add_reloc(s, segment, R_386_16);
} else {
elf_add_reloc(s, segment, R_386_32);
R_386_GOT32, true);
} else if (wrt == elf_sym_sect + 1) {
if (realbytes == 2) {
- gnu16 = 1;
+ gnu16 = true;
addr = elf_add_gsym_reloc(s, segment, addr,
R_386_16, false);
} else {
static struct ELF_SECTDATA {
void *data;
int32_t len;
- int is_saa;
+ bool is_saa;
} *elf_sects;
static int elf_nsect;
static int32_t elf_foffs;
* as the alignment for the common variable.
*/
if (special) {
- int err;
+ bool err;
sym->value = readnum(special, &err);
if (err)
error(ERR_NONFATAL, "alignment constraint `%s' is not a"
error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
elf_sect_write(s, data, realbytes);
} else if (type == OUT_ADDRESS) {
- int gnu16 = 0;
+ bool gnu16 = false;
addr = *(int64_t *)data;
if (segment != NO_SEG) {
if (segment % 2) {
} else if (wrt == elf_sym_sect + 1) {
switch (realbytes) {
case 2:
- gnu16 = 1;
+ gnu16 = true;
addr = elf_add_gsym_reloc(s, segment, addr,
R_X86_64_16, false);
break;
struct Segment *seg;
struct Group *grp;
struct External **extp;
- int obj_idx, i, attrs, rn_error;
+ int obj_idx, i, attrs;
+ bool rn_error;
char *p;
/*
" and library name");
else {
struct ImpDef *imp;
- int err = false;
+ bool err = false;
imp = *imptail = nasm_malloc(sizeof(struct ImpDef));
imptail = &imp->next;
else if (!nasm_stricmp(v, "nodata"))
flags |= EXPDEF_FLAG_NODATA;
else if (!nasm_strnicmp(v, "parm=", 5)) {
- int err = false;
+ bool err = false;
flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err);
if (err) {
error(ERR_NONFATAL,
return 1;
}
} else {
- int err = false;
+ bool err = false;
ordinal = readnum(v, &err);
if (err) {
error(ERR_NONFATAL,
static int32_t rdf2_section_names(char *name, int pass, int *bits)
{
int i;
+ bool err;
char *p, *q;
int code = -1;
int reserved = 0;
if ((q = strchr(p, ','))) {
*q++ = '\0';
- reserved = readnum(q, &i);
- if (i) {
+ reserved = readnum(q, &err);
+ if (err) {
error(ERR_NONFATAL,
"value following comma must be numeric");
reserved = 0;
break;
}
if (code == -1) { /* didn't find anything */
- code = readnum(p, &i);
- if (i) {
+ code = readnum(p, &err);
+ if (err) {
error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
p);
code = 3;
* of two; if so, store it as the alignment for the common variable.
*/
if (special) {
- int err;
+ bool err;
ci.align = readnum(special, &err);
if (err)
error(ERR_NONFATAL, "alignment constraint `%s' is not a"
struct SMacro {
SMacro *next;
char *name;
- int casesense;
- unsigned int nparam;
+ bool casesense;
int in_progress;
+ unsigned int nparam;
Token *expansion;
};
}
if (tline->type == TOK_NUMBER) {
- int rn_error;
+ bool rn_error;
tokval->t_integer = readnum(tline->text, &rn_error);
if (rn_error)
* simple wrapper which calls either strcmp or nasm_stricmp
* depending on the value of the `casesense' parameter.
*/
-static int mstrcmp(char *p, char *q, int casesense)
+static int mstrcmp(char *p, char *q, bool casesense)
{
return casesense ? strcmp(p, q) : nasm_stricmp(p, q);
}
*
* We must free the tline we get passed.
*/
-static int if_condition(Token * tline, enum preproc_token ct)
+static bool if_condition(Token * tline, enum preproc_token ct)
{
enum pp_conditional i = PP_COND(ct);
- int j;
+ bool j;
Token *t, *tt, **tptr, *origline;
struct tokenval tokval;
expr *evalresult;
{
enum preproc_token i;
int j;
- int nparam, nolist;
+ bool err;
+ int nparam;
+ bool nolist;
int k, m;
int offset;
char *p, *mname;
defining->nparam_min = defining->nparam_max = 0;
} else {
defining->nparam_min = defining->nparam_max =
- readnum(tline->text, &j);
- if (j)
+ readnum(tline->text, &err);
+ if (err)
error(ERR_NONFATAL,
"unable to parse parameter count `%s'", tline->text);
}
"`%%%smacro' expects a parameter count after `-'",
(i == PP_IMACRO ? "i" : ""));
else {
- defining->nparam_max = readnum(tline->text, &j);
- if (j)
+ defining->nparam_max = readnum(tline->text, &err);
+ if (err)
error(ERR_NONFATAL,
"unable to parse parameter count `%s'",
tline->text);
tmp_defining = defining;
defining = nasm_malloc(sizeof(MMacro));
defining->name = NULL; /* flags this macro as a %rep block */
- defining->casesense = 0;
+ defining->casesense = false;
defining->plus = false;
defining->nolist = nolist;
defining->in_progress = i;
free_tlist(origline);
return DIRECTIVE_FOUND;
}
- k = readnum(tline->text, &j);
+ k = readnum(tline->text, &err);
m = 1;
tline = tline->next;
if (tok_is_(tline, "+")) {
free_tlist(origline);
return DIRECTIVE_FOUND;
}
- m = readnum(tline->text, &j);
+ m = readnum(tline->text, &err);
tline = tline->next;
}
skip_white_(tline);
}
return tv->t_type = TOKEN_HERE;
} else if (isnumstart(*stdscan_bufptr)) { /* now we've got a number */
- int rn_error;
+ bool rn_error;
r = stdscan_bufptr++;
while (isnumchar(*stdscan_bufptr))