|
|
|
@ -44,9 +44,7 @@ class VerilogTransformer(Transformer):
@@ -44,9 +44,7 @@ class VerilogTransformer(Transformer):
|
|
|
|
|
@staticmethod |
|
|
|
|
def name(args): |
|
|
|
|
s = args[0].value |
|
|
|
|
if s[0] == '\\': |
|
|
|
|
s = s[1:].replace(' ','') |
|
|
|
|
return s |
|
|
|
|
return s[1:-1] if s[0] == '\\' else s |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def instantiation(args): |
|
|
|
@ -56,9 +54,25 @@ class VerilogTransformer(Transformer):
@@ -56,9 +54,25 @@ class VerilogTransformer(Transformer):
|
|
|
|
|
|
|
|
|
|
def range(self, args): |
|
|
|
|
left = int(args[0].value) |
|
|
|
|
right = int(args[1].value) |
|
|
|
|
right = int(args[1].value) if len(args) > 1 else left |
|
|
|
|
return range(left, right+1) if left <= right else range(left, right-1, -1) |
|
|
|
|
|
|
|
|
|
def sigsel(self, args): |
|
|
|
|
if len(args) > 1 and isinstance(args[1], range): |
|
|
|
|
l = [f'{args[0]}[{i}]' for i in args[1]] |
|
|
|
|
return l if len(l) > 1 else l[0] |
|
|
|
|
else: |
|
|
|
|
return args[0] |
|
|
|
|
|
|
|
|
|
def concat(self, args): |
|
|
|
|
sigs = [] |
|
|
|
|
for a in args: |
|
|
|
|
if isinstance(a, list): |
|
|
|
|
sigs += a |
|
|
|
|
else: |
|
|
|
|
sigs.append(a) |
|
|
|
|
return sigs |
|
|
|
|
|
|
|
|
|
def declaration(self, kind, args): |
|
|
|
|
rnge = None |
|
|
|
|
if isinstance(args[0], range): |
|
|
|
@ -110,12 +124,23 @@ class VerilogTransformer(Transformer):
@@ -110,12 +124,23 @@ class VerilogTransformer(Transformer):
|
|
|
|
|
cnode = Node(c, f'__const{s2[3]}_{const_count}__', f'__const{s2[3]}__') |
|
|
|
|
const_count += 1 |
|
|
|
|
Line(c, cnode, Node(c, s1)) |
|
|
|
|
for s1, s2 in assignments: # pass 1.5: process signal assignments |
|
|
|
|
if isinstance(s2, Tree) and s2.data == 'concatenation': |
|
|
|
|
for target, source in zip(self._signal_declarations[s1].names, s2.children): |
|
|
|
|
assign_wire(target, source) |
|
|
|
|
else: |
|
|
|
|
assign_wire(s1, s2) |
|
|
|
|
for target, source in assignments: # pass 1.5: process signal assignments |
|
|
|
|
target_sigs = [] |
|
|
|
|
if not isinstance(target, list): target = [target] |
|
|
|
|
for s in target: |
|
|
|
|
if s in self._signal_declarations: |
|
|
|
|
target_sigs += self._signal_declarations[s].names |
|
|
|
|
else: |
|
|
|
|
target_sigs.append(s) |
|
|
|
|
source_sigs = [] |
|
|
|
|
if not isinstance(source, list): source = [source] |
|
|
|
|
for s in source: |
|
|
|
|
if s in self._signal_declarations: |
|
|
|
|
source_sigs += self._signal_declarations[s].names |
|
|
|
|
else: |
|
|
|
|
source_sigs.append(s) |
|
|
|
|
for t, s in zip(target_sigs, source_sigs): |
|
|
|
|
assign_wire(t, s) |
|
|
|
|
for stmt in args[2:]: # pass 2: connect signals to readers |
|
|
|
|
if isinstance(stmt, Instantiation): |
|
|
|
|
for p, s in stmt.pins.items(): |
|
|
|
@ -159,15 +184,14 @@ GRAMMAR = r"""
@@ -159,15 +184,14 @@ GRAMMAR = r"""
|
|
|
|
|
inout: "inout" range? _namelist ";" |
|
|
|
|
tri: "tri" range? _namelist ";" |
|
|
|
|
wire: "wire" range? _namelist ";" |
|
|
|
|
assign: "assign" lvalue "=" _expression ";" |
|
|
|
|
assign: "assign" sigsel "=" sigsel ";" |
|
|
|
|
instantiation: name name "(" [ pin ( "," pin )* ] ")" ";" |
|
|
|
|
pin: "." name "(" name? ")" |
|
|
|
|
pin: "." name "(" sigsel? ")" |
|
|
|
|
range: "[" /[0-9]+/ (":" /[0-9]+/)? "]" |
|
|
|
|
?lvalue: name range? |
|
|
|
|
_expression: name | concatenation |
|
|
|
|
concatenation: "{" _namelist "}" |
|
|
|
|
sigsel: name range? | concat |
|
|
|
|
concat: "{" sigsel ( "," sigsel )* "}" |
|
|
|
|
_namelist: name ( "," name )* |
|
|
|
|
name: ( /[a-z_][a-z0-9_\[\]]*/i | /\\[^\t \r\n]+[\t \r\n](\[[0-9]+\])?/i | /1'b0/i | /1'b1/i ) |
|
|
|
|
name: ( /[a-z_][a-z0-9_]*/i | /\\[^\t \r\n]+[\t \r\n]/i | /1'b0/i | /1'b1/i ) |
|
|
|
|
%import common.NEWLINE |
|
|
|
|
COMMENT: /\/\*(\*(?!\/)|[^*])*\*\// | /\(\*(\*(?!\))|[^*])*\*\)/ | "//" /(.)*/ NEWLINE |
|
|
|
|
%ignore ( /\r?\n/ | COMMENT )+ |
|
|
|
|