0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

Avoid magic values; we have more than 124 registers now

There was a magic hard-coded constant that register numbers were between
1 and 124.  Well, we have about 150 registers now, and that broke.
This commit is contained in:
H. Peter Anvin 2007-05-30 04:28:50 +00:00
parent 34539fb1ed
commit a1abb32004
2 changed files with 11 additions and 10 deletions

17
nasm.h
View File

@ -284,17 +284,14 @@ typedef expr *(*evalfunc) (scanner sc, void *scprivate,
efunc error, struct eval_hints * hints);
/*
* Special values for expr->type. ASSUMPTION MADE HERE: the number
* of distinct register names (i.e. possible "type" fields for an
* expr structure) does not exceed 124 (EXPR_REG_START through
* EXPR_REG_END).
* Special values for expr->type. These come after EXPR_REG_END
* as defined in regs.h.
*/
#define EXPR_REG_START 1
#define EXPR_REG_END 124
#define EXPR_UNKNOWN 125L /* for forward references */
#define EXPR_SIMPLE 126L
#define EXPR_WRT 127L
#define EXPR_SEGBASE 128L
#define EXPR_UNKNOWN (EXPR_REG_END+1) /* forward references */
#define EXPR_SIMPLE (EXPR_REG_END+2)
#define EXPR_WRT (EXPR_REG_END+3)
#define EXPR_SEGBASE (EXPR_REG_END+4)
/*
* Preprocessors ought to look like this:

View File

@ -72,14 +72,18 @@ close(REGS);
if ( $fmt eq 'h' ) {
# Output regs.h
print "/* automatically generated from $file - do not edit */\n";
$expr_regs = 1;
printf "#define EXPR_REG_START %d\n", $expr_regs;
print "enum reg_enum {\n";
$attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
foreach $reg ( sort(keys(%regs)) ) {
print " R_\U${reg}\E${attach},\n";
$attach = ''; $ch = ',';
$expr_regs++;
}
print " REG_ENUM_LIMIT\n";
print "};\n\n";
printf "#define EXPR_REG_END %d\n", $expr_regs-1;
foreach $reg ( sort(keys(%regs)) ) {
printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
}