from ply import lex, yacc
import astor
-from soc.decoder.power_fieldsn import create_sigdecode
+from soc.decoder.power_decoder import create_pdecode
# I use the Python AST
def __init__(self):
self.gprs = {}
- for rname in ['RA', 'RB', 'RC', 'RT']:
+ for rname in ['RA', 'RB', 'RC', 'RT', 'RS']:
self.gprs[rname] = None
# The grammar comments come from Python's Grammar/Grammar file
def p_atom_tuple(self, p):
"""atom : LPAR testlist RPAR"""
+ print ("tuple", p[2])
+ if isinstance(p[2], ast.Name):
+ print ("tuple name", p[2].id)
+ if p[2].id in self.gprs:
+ #p[0] = ast.Call(ast.Name("GPR"), [p[2]], [])
+ #idx = ast.Slice(ast.Constant(0), ast.Constant(-1), None)
+ #idx = ast.Subscript(p[2], idx)
+ #idx = ast.Subscript(p[2], idx)
+ p[0] = ast.Subscript(ast.Name("GPR"), ast.Str(p[2].id))
+ return
p[0] = p[2]
# trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
class GardenSnakeParser(PowerParser):
def __init__(self, lexer = None):
+ PowerParser.__init__(self)
if lexer is None:
lexer = IndentLexer(debug=1)
self.lexer = lexer
self.parser = yacc.yacc(module=self, start="file_input_end",
debug=False, write_tables=False)
- self.sd = create_sigdecode()
+ self.sd = create_pdecode()
def parse(self, code):
self.lexer.input(code)
####### Test code #######
-from soc.decoder.power_fieldsn import create_sigdecode
-
bpermd = r"""
perm <- [0] * 8
if index < 64:
RA <- EXTZ64(n)
"""
+testreg = """
+x <- (RS)
+"""
+
+#code = testreg
code = cnttzd
#code = bpermd
#sys.exit(0)
-sd = create_sigdecode()
-print ("forms", sd.df.forms)
-for f in sd.df.FormX:
- print (f)
+sd = create_pdecode()
+print ("forms", sd.sigforms)
+for f in sd.FormX:
+ print ("field", f)
gsc = GardenSnakeCompiler()
_compile = gsc.compile
def listconcat(l1, l2):
return l1 + l2
+from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
+
+class GPR(dict):
+ def __init__(self):
+ for rname in ['RA', 'RS']:
+ self[rname] = [0]*64
+
+
d = {}
d["print"] = print_
+d["EXTS64"] = EXTS64
+d["EXTZ64"] = EXTZ64
d["concat"] = listconcat
+d["GPR"] = GPR()
form = 'X'
-getform = getattr(gsc.parser.sd.df, "Form%s" % form)
-print (getform)
-for k, f in sd.df.instrs[form].items():
+getform = gsc.parser.sd.sigforms[form]
+print (getform._asdict())
+for k, f in getform._asdict().items():
d[k] = getattr(getform, k)
compiled_code = compile(source, mode="exec", filename="<string>")