|
@ -82,6 +82,7 @@ class Tokenizer: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tok = Tokenizer(sys.stdin.read()) |
|
|
tok = Tokenizer(sys.stdin.read()) |
|
|
|
|
|
global_names = set() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def processExpression(): |
|
|
def processExpression(): |
|
@ -177,9 +178,13 @@ while tok: |
|
|
elif start.isA("COMMENT"): |
|
|
elif start.isA("COMMENT"): |
|
|
print(start.value) |
|
|
print(start.value) |
|
|
elif start.isA("DIRECTIVE"): |
|
|
elif start.isA("DIRECTIVE"): |
|
|
if start.value in {".module", ".optsdcc", ".globl"}: |
|
|
|
|
|
|
|
|
if start.value in {".module", ".optsdcc"}: |
|
|
while not tok.pop().isA("NEWLINE"): |
|
|
while not tok.pop().isA("NEWLINE"): |
|
|
pass |
|
|
pass |
|
|
|
|
|
elif start.value == ".globl": |
|
|
|
|
|
global_name = tok.pop().value |
|
|
|
|
|
global_names.add(global_name) |
|
|
|
|
|
assert tok.pop().isA("NEWLINE") |
|
|
elif start.value == ".area": |
|
|
elif start.value == ".area": |
|
|
area_name = tok.pop().value |
|
|
area_name = tok.pop().value |
|
|
if area_name == "_DATA": |
|
|
if area_name == "_DATA": |
|
@ -251,7 +256,10 @@ while tok: |
|
|
processExpression() |
|
|
processExpression() |
|
|
sys.stdout.write("\n") |
|
|
sys.stdout.write("\n") |
|
|
elif tok.peek().isA("LABEL"): |
|
|
elif tok.peek().isA("LABEL"): |
|
|
print("%s%s" % (start.value, tok.pop().value)) |
|
|
|
|
|
|
|
|
label_suffix = tok.pop().value |
|
|
|
|
|
if label_suffix == ":" and start.value in global_names: |
|
|
|
|
|
label_suffix = "::" |
|
|
|
|
|
print("%s%s" % (start.value, label_suffix)) |
|
|
elif start.isA("ID", "ldhl"): |
|
|
elif start.isA("ID", "ldhl"): |
|
|
tok.expect("ID", "sp") |
|
|
tok.expect("ID", "sp") |
|
|
tok.expect("OP", ",") |
|
|
tok.expect("OP", ",") |
|
|