[PATCH 05/11] gas: pre-init the scrubber's lex[]
Jan Beulich
jbeulich@suse.com
Fri Jun 28 13:19:34 GMT 2024
While we can't - unlike an old comment suggests - do this fully, we can
certainly do part of this at compile time.
Since it's adjacent, also drop the unnecessary forward declaration of
process_escape().
---
Assumptions on certain ordering between characters exists elsewhere
already, so I assume leveraging this here as well isn't going to be a
problem.
--- a/gas/app.c
+++ b/gas/app.c
@@ -58,10 +58,6 @@ static const char * symver_state;
static char last_char;
-static char lex[256];
-static const char symbol_chars[] =
-"$._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-
#define LEX_IS_SYMBOL_COMPONENT 1
#define LEX_IS_WHITESPACE 2
#define LEX_IS_LINE_SEPARATOR 3
@@ -93,23 +89,25 @@ static const char symbol_chars[] =
#define IS_LINE_COMMENT(c) (lex[c] == LEX_IS_LINE_COMMENT_START)
#define IS_NEWLINE(c) (lex[c] == LEX_IS_NEWLINE)
-static int process_escape (int);
-
-/* FIXME-soon: The entire lexer/parser thingy should be
- built statically at compile time rather than dynamically
- each and every time the assembler is run. xoxorich. */
+static char lex[256] = {
+ [' '] = LEX_IS_WHITESPACE,
+ ['\t'] = LEX_IS_WHITESPACE,
+ ['\r'] = LEX_IS_WHITESPACE,
+ ['\n'] = LEX_IS_NEWLINE,
+ [':'] = LEX_IS_COLON,
+ ['$'] = LEX_IS_SYMBOL_COMPONENT,
+ ['.'] = LEX_IS_SYMBOL_COMPONENT,
+ ['_'] = LEX_IS_SYMBOL_COMPONENT,
+ ['A' ... 'Z'] = LEX_IS_SYMBOL_COMPONENT,
+ ['a' ... 'z'] = LEX_IS_SYMBOL_COMPONENT,
+ ['0' ... '9'] = LEX_IS_SYMBOL_COMPONENT,
+ [128 ... 255] = LEX_IS_SYMBOL_COMPONENT,
+};
void
do_scrub_begin (int m68k_mri ATTRIBUTE_UNUSED)
{
const char *p;
- int c;
-
- lex[' '] = LEX_IS_WHITESPACE;
- lex['\t'] = LEX_IS_WHITESPACE;
- lex['\r'] = LEX_IS_WHITESPACE;
- lex['\n'] = LEX_IS_NEWLINE;
- lex[':'] = LEX_IS_COLON;
#ifdef TC_M68K
scrub_m68k_mri = m68k_mri;
@@ -133,11 +131,6 @@ do_scrub_begin (int m68k_mri ATTRIBUTE_U
/* Note that these override the previous defaults, e.g. if ';' is a
comment char, then it isn't a line separator. */
- for (p = symbol_chars; *p; ++p)
- lex[(unsigned char) *p] = LEX_IS_SYMBOL_COMPONENT;
-
- for (c = 128; c < 256; ++c)
- lex[c] = LEX_IS_SYMBOL_COMPONENT;
#ifdef tc_symbol_chars
/* This macro permits the processor to specify all characters which
More information about the Binutils
mailing list