source: buchla-68k/util/asm.py@ 9bf0f86

Last change on this file since 9bf0f86 was 4f508e6, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Converted assembly language files.

  • Property mode set to 100755
File size: 1.1 KB
Line 
1#!/usr/bin/env python3
2
3import sys
4import re
5
6def convert_line(line):
7 if line == "*":
8 return ""
9
10 # |foo .equ *| -> |foo:|
11
12 m = re.match(r"^([a-z0-9_]+)\t+.equ\t+\*(.*)$", line)
13
14 if m != None:
15 lab = m.group(1) + ":"
16 com = m.group(2).strip()
17 line = lab + "\t\t\t\t\t"[len(lab) // 8:] + com
18
19 # |foo: dc.b '(...)'| -> |foo: dc.b "(...)"|
20
21 m = re.match(r"((?:^[a-z0-9]+:)?\t+dc.b\t+)'([^']+)'(.*)$", line)
22
23 if m != None:
24 line = m.group(1) + "\"" + m.group(2) + "\"" + m.group(3)
25
26 line = line.replace("*", "|")
27 line = line.replace("$", "0x")
28 line = line.replace(".equ", "=")
29 return line
30
31def convert(in_path, out_path):
32 lines = []
33
34 with open(in_path, "r") as f:
35 for line in f:
36 line = line.rstrip()
37 line = convert_line(line)
38 lines.append(line)
39
40 with open(out_path, "w") as f:
41 for line in lines:
42 print(line, file = f)
43
44if len(sys.argv) != 3:
45 raise Exception("usage: asm.py in-path out-path")
46
47convert(sys.argv[1], sys.argv[2])
Note: See TracBrowser for help on using the repository browser.