from nmigen import Module, Signal
from soc.decoder.pseudo.parser import GardenSnakeCompiler
-from soc.decoder.selectable_int import SelectableInt
+from soc.decoder.selectable_int import SelectableInt, selectconcat
####### Test code #######
print ("args", args)
print ("-->", " ".join(map(str,args)))
- def listconcat(l1, l2):
- return l1 + l2
-
from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
d = {}
d["print"] = print_
d["EXTS64"] = EXTS64
d["EXTZ64"] = EXTZ64
- d["concat"] = listconcat
+ d["SelectableInt"] = SelectableInt
+ d["concat"] = selectconcat
d["GPR"] = gsc.gpr
form = 'X'
# Modifications for inclusion in PLY distribution
from copy import copy
from ply import lex
-
+from soc.decoder.selectable_int import SelectableInt
## I implemented INDENT / DEDENT generation as a post-processing filter
def t_BINARY(self, t):
r"""0b[01]+"""
- t.value = int(t.value, 2)
+ t.value = SelectableInt(int(t.value, 2), len(t.value)-2)
return t
#t_NUMBER = r'\d+'
print (node)
if not isinstance(node, ast.Call):
return [node]
- if node[0].id != 'concat':
- return node
+ print (node.func.id)
+ if node.func.id != 'concat':
+ return [node]
return node[1]
import unittest
+from copy import copy
class SelectableInt:
return "SelectableInt(value={:x}, bits={})".format(self.value,
self.bits)
+def selectconcat(*args):
+ res = copy(args[0])
+ for i in args[1:]:
+ assert isinstance(i, SelectableInt), "can only concat SIs, sorry"
+ res.bits += i.bits
+ res.value = (res.value << i.bits) | i.value
+ return res
+
class SelectableIntTestCase(unittest.TestCase):
def test_arith(self):