The overall intent is to make writing a decompiler require less code duplication. "bits.hpp" and "stmt_enum.hpp" are replaced with "stmt_ins.hpp" which is generated directly from dsp-notes.csv.
25 lines
534 B
Python
25 lines
534 B
Python
import io
|
|
|
|
def _render(out, lines):
|
|
indent = " "
|
|
level = 0
|
|
for l in lines:
|
|
if l and (l[0] == "}" or l[0] == ")"):
|
|
level -= 2
|
|
assert level >= 0, out.getvalue()
|
|
|
|
out.write(indent * level + l + "\n")
|
|
|
|
if l and (l[-1] == "{" or l[-1] == "("):
|
|
level += 2
|
|
|
|
if level == 0 and l and l[-1] == ";":
|
|
out.write("\n")
|
|
return out
|
|
|
|
def renderer():
|
|
out = io.StringIO()
|
|
def render(lines):
|
|
return _render(out, lines)
|
|
return render, out
|