arch: Switch to a new state to process macrocoop headers.

The "header" of a macroop definition is the part after "def rom" but
before the "{". This is pretty minimal now, but will be more complex
once macros are introduced.

Change-Id: I002d6501a015f46be6ae28b8d2a5e6064438da32
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56328
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2022-01-29 22:16:10 -08:00
parent 8beab79f19
commit 2eb3ac3880

View File

@@ -197,6 +197,7 @@ tokens = reserved + (
states = (
('asm', 'exclusive'),
('params', 'exclusive'),
('header', 'exclusive'),
)
reserved_map = { }
@@ -244,17 +245,27 @@ def t_asm_ID(t):
t.lexer.push_state('params')
return t
def t_header_ID(t):
r'[A-Za-z_]\w*'
return t
# If there is a label and you're -not- in the assembler (which would be caught
# above), don't start looking for parameters.
def t_ANY_ID(t):
r'[A-Za-z_]\w*'
t.type = reserved_map.get(t.value, 'ID')
if t.type == 'MACROOP':
t.lexer.push_state('asm')
t.lexer.push_state('header')
elif t.type == 'ROM':
t.lexer.push_state('asm')
t.lexer.push_state('header')
return t
# Braces enter and exit micro assembly
def t_INITIAL_LBRACE(t):
def t_header_LBRACE(t):
r'\{'
t.lexer.push_state('asm')
t.lexer.pop_state()
return t
def t_asm_RBRACE(t):
@@ -262,11 +273,6 @@ def t_asm_RBRACE(t):
t.lexer.pop_state()
return t
# At the top level, keep track of newlines only for line counting.
def t_INITIAL_NEWLINE(t):
r'\n+'
t.lineno += t.value.count('\n')
# In the micro assembler, do line counting but also return a token. The
# token is needed by the parser to detect the end of a statement.
def t_asm_NEWLINE(t):
@@ -287,6 +293,11 @@ def t_params_SEMI(t):
t.lexer.pop_state()
return t
# Unless handled specially above, track newlines only for line counting.
def t_ANY_NEWLINE(t):
r'\n+'
t.lineno += t.value.count('\n')
# Basic regular expressions to pick out simple tokens
t_ANY_LPAREN = r'\('
t_ANY_RPAREN = r'\)'