From: Gabe Black Date: Thu, 31 May 2007 22:21:19 +0000 (+0000) Subject: Do something with ROM based macroops X-Git-Tag: m5_2.0_beta4~389 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=287446396cceadec0f758ecde8dca268b9a60cd5;p=gem5.git Do something with ROM based macroops --HG-- extra : convert_revision : 3a14c683ab89217c083c58e8c374607dd04b66c4 --- diff --git a/src/arch/micro_asm.py b/src/arch/micro_asm.py index e36daf862..d9d9d1b21 100644 --- a/src/arch/micro_asm.py +++ b/src/arch/micro_asm.py @@ -64,9 +64,14 @@ class Micro_Container(object): string += " %s\n" % microop return string -class Macroop(Micro_Container): +class Combinational_Macroop(Micro_Container): pass +class Rom_Macroop(object): + def __init__(self, name, target): + self.name = name + self.target = target + class Rom(Micro_Container): def __init__(self, name): super(Rom, self).__init__(name) @@ -310,6 +315,9 @@ def p_block(t): # Defines a section of microcode that should go in the current ROM def p_rom_block(t): 'rom_block : DEF ROM block SEMI' + if not t.parser.rom: + print_error("Rom block found, but no Rom object specified.") + raise TypeError, "Rom block found, but no Rom object was specified." for statement in t[3].statements: handle_statement(t.parser, t.parser.rom, statement) t[0] = t.parser.rom @@ -317,7 +325,12 @@ def p_rom_block(t): # Defines a macroop that jumps to an external label in the ROM def p_macroop_def_0(t): 'macroop_def : DEF MACROOP ID LPAREN ID RPAREN SEMI' - t[0] = t[4] + if not t.parser.rom_macroop_type: + print_error("ROM based macroop found, but no ROM macroop class was specified.") + raise TypeError, "ROM based macroop found, but no ROM macroop class was specified." + macroop = t.parser.rom_macroop_type(t[3], t[5]) + t[0] = macroop + # Defines a macroop that is combinationally generated def p_macroop_def_1(t): @@ -438,13 +451,15 @@ def p_error(t): class MicroAssembler(object): - def __init__(self, macro_type, microops, rom): + def __init__(self, macro_type, microops, + rom = None, rom_macroop_type = None): self.lexer = lex.lex() self.parser = yacc.yacc() self.parser.macro_type = macro_type self.parser.macroops = {} self.parser.microops = microops self.parser.rom = rom + self.parser.rom_macroop_type = rom_macroop_type def assemble(self, asm): self.parser.parse(asm, lexer=self.lexer) diff --git a/src/arch/micro_asm_test.py b/src/arch/micro_asm_test.py index 858ac511e..f0aebe2b2 100755 --- a/src/arch/micro_asm_test.py +++ b/src/arch/micro_asm_test.py @@ -26,7 +26,7 @@ # # Authors: Gabe Black -from micro_asm import MicroAssembler, Macroop, Rom +from micro_asm import MicroAssembler, Combinational_Macroop, Rom_Macroop, Rom class Bah(object): def __init__(self): @@ -52,7 +52,7 @@ microops = { "dah": Dah } -class TestMacroop(Macroop): +class TestMacroop(Combinational_Macroop): def tweak(self): microops["bah"] = Bah_Tweaked def untweak(self): @@ -68,7 +68,7 @@ class TestMacroop(Macroop): "print": self.print_debug } -assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM')) +assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'), Rom_Macroop) testAssembly = ''' # Single line comment