From a1abb32004a55a0a543350f607ae40d49f6337e1 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 30 May 2007 04:28:50 +0000 Subject: [PATCH] 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. --- nasm.h | 19 ++++++++----------- regs.pl | 4 ++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nasm.h b/nasm.h index 8a110aed..4dd8dd5a 100644 --- a/nasm.h +++ b/nasm.h @@ -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). - */ -#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 + * Special values for expr->type. These come after EXPR_REG_END + * as defined in regs.h. + */ + +#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: diff --git a/regs.pl b/regs.pl index fc27a9d1..d8f53bc4 100755 --- a/regs.pl +++ b/regs.pl @@ -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}; } -- 2.11.4.GIT