-Subproject commit 03177977f70255421290a59caa3db84658e7f3e5
+Subproject commit 620efa218f922eba23b19189109bec785a624a82
from copy import copy
from ply import lex, yacc
import astor
+import ast
from soc.decoder.power_decoder import create_pdecode
from nmigen.back.pysim import Simulator, Delay
return self.regfile[rnum]
+def convert_to_python(pcode):
+
+ gsc = GardenSnakeCompiler()
+
+ tree = gsc.compile(pcode, mode="exec", filename="string")
+ tree = ast.fix_missing_locations(tree)
+ return astor.to_source(tree)
+
+
def test():
gsc = GardenSnakeCompiler()
_compile = gsc.compile
tree = _compile(code, mode="single", filename="string")
- import ast
tree = ast.fix_missing_locations(tree)
print ( ast.dump(tree) )
depth = 0
prev_was_ws = False
for token in tokens:
- if 1:
+ if 0:
print ("Process", depth, token.indent, token,)
if token.at_line_start:
print ("at_line_start",)
print ("Skipping", repr(t.value[0]))
t.lexer.skip(1)
+
# Combine Ply and my filters into a new lexer
class IndentLexer(PowerLexer):
self.build(debug=debug, optimize=optimize,
lextab=lextab, reflags=reflags)
self.token_stream = None
+
def input(self, s, add_endmarker=True):
self.lexer.paren_count = 0
self.lexer.brack_count = 0
def __init__(self):
self.instr = OrderedDict()
self.forms = {}
+ self.page = {}
for pth in os.listdir(os.path.join(get_isa_dir())):
print (get_isa_dir(), pth)
assert pth.endswith(".mdwn"), "only %s in isa dir" % pth
fl = self.forms.get(form, [])
self.forms[form] = fl + [opcode]
+ # create list of instructions by page
+ page = op['page']
+ pl = self.page.get(page, [])
+ self.page[page] = pl + [opcode]
+
def pprint_ops(self):
for k, v in self.instr.items():
print ("# %s %s" % (v.opcode, v.desc))
def __init__(self, lexer = None):
PowerParser.__init__(self)
if lexer is None:
- lexer = IndentLexer(debug=1)
+ lexer = IndentLexer(debug=0)
self.lexer = lexer
self.tokens = lexer.tokens
self.parser = yacc.yacc(module=self, start="file_input_end",
self.sd = create_pdecode()
def parse(self, code):
- self.lexer.input(code)
- result = self.parser.parse(lexer = self.lexer, debug=False)
+ #self.lexer.input(code)
+ result = self.parser.parse(code, lexer=self.lexer, debug=False)
return ast.Module(result)
class GardenSnakeCompiler(object):
def __init__(self):
self.parser = GardenSnakeParser()
+
def compile(self, code, mode="exec", filename="<string>"):
tree = self.parser.parse(code)
print ("snake")