micro_asm_test.py
来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· Python 代码 · 共 80 行
PY
80 行
from micro_asm import MicroAssembler, Combinational_Macroop, Rom_Macroop, Romclass Bah(object): def __init__(self): self.mnemonic = "bah"class Bah_Tweaked(object): def __init__(self): self.mnemonic = "bah_tweaked"class Hoop(object): def __init__(self, first_param, second_param): self.mnemonic = "hoop_%s_%s" % (first_param, second_param) def __str__(self): return "%s" % self.mnemonicclass Dah(object): def __init__(self): self.mnemonic = "dah"microops = { "bah": Bah, "hoop": Hoop, "dah": Dah}class TestMacroop(Combinational_Macroop): def tweak(self): microops["bah"] = Bah_Tweaked def untweak(self): microops["bah"] = Bah def print_debug(self, message): print message def __init__(self, name): super(TestMacroop, self).__init__(name) self.directives = { "tweak": self.tweak, "untweak": self.untweak, "print": self.print_debug }assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'), Rom_Macroop)testAssembly = '''# Single line commentdef rom { goo: bah extern la: hoop 4*8, "a"}; /* multiline comment on one line *//* multi line comment across lines to make sure they work */def macroop squishy { .tweak bah .untweak .print "In the midst" bah dah # single line comment after something .tweak};#Extending the rom...def rom{ #Here's more stuff for the rom bah};def macroop squashy { bah};def macroop jumper (bar);'''assembler.assemble(testAssembly)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?