diff options
author | Peter Wu <lekensteyn@gmail.com> | 2011-12-02 18:43:48 +0000 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2011-12-02 18:43:48 +0000 |
commit | a6f9617bd891074bba20cc1fc220e60a226e7fb4 (patch) | |
tree | d5634a2db32c64275aa593d8a13ca066270c3ba9 /Asm.py | |
parent | 45f82a1acf465c8420690a578192cdabf4bc7c04 (diff) | |
download | pp2cc-a6f9617bd891074bba20cc1fc220e60a226e7fb4.tar.gz |
WIP for supporting ASM parsing and initialization of variables in @DATA
Diffstat (limited to 'Asm.py')
-rw-r--r-- | Asm.py | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -21,13 +21,29 @@ __email__ = "uwretep@gmail.com" import re class Asm(object): + id_re = "[a-zA-Z_][0-9a-zA-Z_]*" + re_identifier = re.compile("^" + id_re + "$") + re_label = re.compile("^\s*" + id_re + "\s*:") + # these instructions accept a label name + operators_branch = ("BEQ", "BNE", "BCS", "BCC", "BLS", "BHI", "BVC", "BVS", + "BPL", "BMI", "BLT", "BGE", "BLE", "BGT", "BRA", "BRS") + # these instructions are weird. + operators_unary = ("JMP", "JSR", "CLRI", "SETI", "PSEM", "VSEM") + # these instructions accept a register (arg 1) and addressing mode (arg 2) + operators_binary = ("LOAD", "ADD", "SUB", "CMP", "MULS", "MULL", "CHCK", + "DIV", "MOD", "DVMD", "AND", "OR", "XOR", "STOR") + # these operators accept a register + operators_misc_reg = ("PUSH", "PULL") + # these instructions accept no args + operators_misc_noreg = ("RTS", "RTE") + operators_misc = operators_misc_reg + operators_misc_noreg + # all available operators + operators_all = operators_branch + operators_unary + operators_binary + operators_all += operators_misc def __init__(self): self.level = 0 - re_id = "[0-9a-zA-Z_][0-9a-zA-Z_]*" - self.re_identifier = re.compile("^" + re_id + "$") - self.re_label = re.compile("^\s*" + re_id + "\s*:") def is_identifier(self, text): - return self.re_identifier.match(text) + return self.re_identifier.match(text) is not None def format_line(self, line, label="", indent_size=-1): """Returns an indented line optionally prefixed with label""" if indent_size < 0: |