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