# all sections are mandatory so no need for a full LALR parser.
l = lines.pop(0).rstrip() # get first line
- prefix_lines = 0
while lines:
if self.verbose:
print(l)
if l.strip().startswith('<!--'):
# print ("skipping comment", l)
l = lines.pop(0).rstrip() # get next line
- prefix_lines += 1
continue
# Ignore blank lines before the first #
if len(l) == 0:
l = lines.pop(0).rstrip() # get next line
- prefix_lines += 1
continue
# expect get heading
# whitespace expected
l = lines.pop(0).strip()
- prefix_lines += 1
if self.verbose:
print(repr(l))
assert len(l) == 0, ("blank line not found %s" % l)
# Form expected
l = lines.pop(0).strip()
- prefix_lines += 1
assert l.endswith('-Form'), ("line with -Form expected %s" % l)
d['form'] = l.split('-')[0]
# whitespace expected
l = lines.pop(0).strip()
- prefix_lines += 1
assert len(l) == 0, ("blank line not found %s" % l)
# get list of opcodes
opcodes = []
while True:
l = lines.pop(0).strip()
- prefix_lines += 1
if len(l) == 0:
break
assert l.startswith('*'), ("* not found in line %s" % l)
# "Pseudocode" expected
l = lines.pop(0).rstrip()
- prefix_lines += 1
assert l.startswith("Pseudo-code:"), ("pseudocode found %s" % l)
# whitespace expected
l = lines.pop(0).strip()
- prefix_lines += 1
if self.verbose:
print(repr(l))
assert len(l) == 0, ("blank line not found %s" % l)
extra_uninit_regs = OrderedSet()
# get pseudocode
-
- # fix parser line numbers by prepending the right number of
- # blank lines to the parser input
- li = [""] * prefix_lines
- li += [l[4:]] # first line detected with 4-space
+ li = []
while True:
l = lines.pop(0).rstrip()
- prefix_lines += 1
- if len(l) == 0:
- li.append(l)
- break
re_match = re.fullmatch(r" *<!-- EXTRA_UNINIT_REGS:(.*)-->", l)
if re_match:
for i in re_match[1].split(' '):
li.append("")
continue
if l.strip().startswith('<!--'):
- li.append("")
continue
+ if len(l) == 0:
+ break
assert l.startswith(' '), ("4spcs not found in line %s" % l)
l = l[4:] # lose 4 spaces
li.append(l)
# "Special Registers Altered" expected
l = lines.pop(0).rstrip()
- prefix_lines += 1
assert l.startswith("Special"), ("special not found %s" % l)
# whitespace expected
l = lines.pop(0).strip()
- prefix_lines += 1
assert len(l) == 0, ("blank line not found %s" % l)
# get special regs
li = []
while lines:
l = lines.pop(0).rstrip()
- prefix_lines += 1
if len(l) == 0:
break
assert l.startswith(' '), ("4spcs not found in line %s" % l)
# expect and drop whitespace and comments
while lines:
l = lines.pop(0).rstrip()
- prefix_lines += 1
if len(l) != 0 and not l.strip().startswith('<!--'):
break
for k, v in self.instr.items():
print("# %s %s" % (v.opcode, v.desc))
print("Form: %s Regs: %s" % (v.form, v.regs))
- pcode = filter(lambda x : len(x.strip()), v.pcode) # skip blank
- print('\n'.join(map(lambda x: " %s" % x, pcode)))
+ print('\n'.join(map(lambda x: " %s" % x, v.pcode)))
print("Specials")
print('\n'.join(map(lambda x: " %s" % x, v.sregs)))
print()