Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/56333 )
Change subject: arch: Simplify the handle_statement function in
micro_asm.py.
......................................................................
arch: Simplify the handle_statement function in micro_asm.py.
Change-Id: If05a2398ee79b6e825f85ef5b4ea3232e5b95745
---
M src/arch/micro_asm.py
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/src/arch/micro_asm.py b/src/arch/micro_asm.py
index b169f96..0bf9caa 100644
--- a/src/arch/micro_asm.py
+++ b/src/arch/micro_asm.py
@@ -48,8 +48,8 @@
self.micro_classes = {}
self.labels = {}
- def add_microop(self, mnemonic, microop):
- microop.mnemonic = mnemonic
+ def add_microop(self, name, microop):
+ microop.mnemonic = name
microop.micropc = len(self.microops)
self.microops.append(microop)
@@ -94,12 +94,12 @@
def __init__(self):
self.is_microop = False
self.is_directive = False
+ self.name = ""
self.params = ""
class Microop(Statement):
def __init__(self):
super().__init__()
- self.mnemonic = ""
self.labels = []
self.is_microop = True
@@ -121,44 +121,36 @@
print()
def handle_statement(parser, container, statement):
+ name = statement.name
+ params = statement.params
+
if statement.is_microop:
- if statement.mnemonic not in parser.microops.keys():
- raise Exception("Unrecognized mnemonic: {}".format(
- statement.mnemonic))
- parser.symbols["__microopClassFromInsideTheAssembler"] = \
- parser.microops[statement.mnemonic]
+ if name not in parser.microops:
+ raise Exception(f'Unrecognized mnemonic: "{name}"')
+ local = {'_cls': parser.microops[name]}
try:
- microop = eval('__microopClassFromInsideTheAssembler(%s)' %
- statement.params, {}, parser.symbols)
+ microop = eval(f'_cls({params})', local, parser.symbols)
except:
- print_error("Error creating microop object with
mnemonic %s." % \
- statement.mnemonic)
+ print_error(f'Error creating "{name}" microop object.')
raise
- try:
- for label in statement.labels:
- container.labels[label.text] = microop
- if label.is_extern:
- container.externs[label.text] = microop
- container.add_microop(statement.mnemonic, microop)
- except:
- print_error("Error adding microop.")
- raise
+
+ for label in statement.labels:
+ container.labels[label.text] = microop
+ if label.is_extern:
+ container.externs[label.text] = microop
+ container.add_microop(name, microop)
+
elif statement.is_directive:
- if statement.name not in container.directives.keys():
- raise Exception("Unrecognized directive: {}".format(
- statement.name))
- parser.symbols["__directiveFunctionFromInsideTheAssembler"] = \
- container.directives[statement.name]
+ if name not in container.directives:
+ raise Exception(f'Unrecognized directive: "{name}"')
+ local = {'_dir': container.directives[name]}
try:
- eval('__directiveFunctionFromInsideTheAssembler(%s)' %
- statement.params, {}, parser.symbols)
+ eval(f'_dir({params})', local, parser.symbols)
except:
- print_error("Error executing directive.")
- print(container.directives)
+ print_error(f'Error executing directive "{name}".')
raise
else:
- raise Exception("Didn't recognize the type of statement {}".format(
- statement))
+ raise Exception(f"Didn't recognize the type of statement
{statement}")
##########################################################################
#
@@ -419,27 +411,27 @@
'microop : labels ID'
microop = Microop()
microop.labels = t[1]
- microop.mnemonic = t[2]
+ microop.name = t[2]
t[0] = microop
def p_microop_1(t):
'microop : ID'
microop = Microop()
- microop.mnemonic = t[1]
+ microop.name = t[1]
t[0] = microop
def p_microop_2(t):
'microop : labels ID PARAMS'
microop = Microop()
microop.labels = t[1]
- microop.mnemonic = t[2]
+ microop.name = t[2]
microop.params = t[3]
t[0] = microop
def p_microop_3(t):
'microop : ID PARAMS'
microop = Microop()
- microop.mnemonic = t[1]
+ microop.name = t[1]
microop.params = t[2]
t[0] = microop
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56333
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If05a2398ee79b6e825f85ef5b4ea3232e5b95745
Gerrit-Change-Number: 56333
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s