Fix a problem where part of a microops parameters might be interpretted as an "ID", and also added support for symbols.

--HG--
extra : convert_revision : 60d1ef677a6a59a9d897086893843ec1ec368148
This commit is contained in:
Gabe Black 2007-06-21 15:26:01 +00:00
parent efce09e958
commit 7e7d3ee0aa

View file

@ -127,9 +127,13 @@ def print_error(message):
def handle_statement(parser, container, statement): def handle_statement(parser, container, statement):
if statement.is_microop: if statement.is_microop:
if statement.mnemonic not in parser.microops.keys():
raise Exception, "Unrecognized mnemonic: %s" % statement.mnemonic
parser.symbols["__microopClassFromInsideTheAssembler"] = \
parser.microops[statement.mnemonic]
try: try:
microop = eval('parser.microops[statement.mnemonic](%s)' % microop = eval('__microopClassFromInsideTheAssembler(%s)' %
statement.params) statement.params, {}, parser.symbols)
except: except:
print_error("Error creating microop object with mnemonic %s." % \ print_error("Error creating microop object with mnemonic %s." % \
statement.mnemonic) statement.mnemonic)
@ -144,8 +148,13 @@ def handle_statement(parser, container, statement):
print_error("Error adding microop.") print_error("Error adding microop.")
raise raise
elif statement.is_directive: elif statement.is_directive:
if statement.name not in container.directives.keys():
raise Exception, "Unrecognized directive: %s" % statement.name
parser.symbols["__directiveFunctionFromInsideTheAssembler"] = \
container.directives[statement.name]
try: try:
eval('container.directives[statement.name](%s)' % statement.params) eval('__directiveFunctionFromInsideTheAssembler(%s)' %
statement.params, {}, parser.symbols)
except: except:
print_error("Error executing directive.") print_error("Error executing directive.")
print container.directives print container.directives
@ -213,23 +222,6 @@ def t_params_COLON(t):
t.lexer.begin('asm') t.lexer.begin('asm')
return t return t
# An "ID" in the micro assembler is either a label, directive, or mnemonic
# If it's either a directive or a mnemonic, it will be optionally followed by
# parameters. If it's a label, the following colon will make the lexer stop
# looking for parameters.
def t_asm_ID(t):
r'[A-Za-z_]\w*'
t.type = reserved_map.get(t.value, 'ID')
t.lexer.begin('params')
return t
# If there is a label and you're -not- in the assember (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')
return t
# Parameters are a string of text which don't contain an unescaped statement # Parameters are a string of text which don't contain an unescaped statement
# statement terminator, ie a newline or semi colon. # statement terminator, ie a newline or semi colon.
def t_params_PARAMS(t): def t_params_PARAMS(t):
@ -243,6 +235,23 @@ def t_params_PARAMS(t):
t.lexer.begin('asm') t.lexer.begin('asm')
return t return t
# An "ID" in the micro assembler is either a label, directive, or mnemonic
# If it's either a directive or a mnemonic, it will be optionally followed by
# parameters. If it's a label, the following colon will make the lexer stop
# looking for parameters.
def t_asm_ID(t):
r'[A-Za-z_]\w*'
t.type = reserved_map.get(t.value, 'ID')
t.lexer.begin('params')
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')
return t
# Braces enter and exit micro assembly # Braces enter and exit micro assembly
def t_INITIAL_LBRACE(t): def t_INITIAL_LBRACE(t):
r'\{' r'\{'
@ -477,14 +486,11 @@ class MicroAssembler(object):
self.parser.microops = microops self.parser.microops = microops
self.parser.rom = rom self.parser.rom = rom
self.parser.rom_macroop_type = rom_macroop_type self.parser.rom_macroop_type = rom_macroop_type
self.parser.symbols = {}
self.symbols = self.parser.symbols
def assemble(self, asm): def assemble(self, asm):
self.parser.parse(asm, lexer=self.lexer) self.parser.parse(asm, lexer=self.lexer)
# Begin debug printing
#for macroop in self.parser.macroops.values():
# print macroop
#print self.parser.rom
# End debug printing
macroops = self.parser.macroops macroops = self.parser.macroops
self.parser.macroops = {} self.parser.macroops = {}
return macroops return macroops