diff options
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: |