Skip to content

Commit ede3155

Browse files
committed
Add uniquecase
1 parent 5701a9a commit ede3155

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

pyverilog/vparser/ast.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
class Node(object):
1616
'''Abstact class for every element in parser'''
17-
17+
1818
def children(self):
1919
pass
20-
20+
2121
def show(self, buf=sys.stdout, offset=0, attrnames=False, showlineno=True):
2222
indent = 2
2323
lead = ' ' * offset
@@ -35,7 +35,7 @@ def show(self, buf=sys.stdout, offset=0, attrnames=False, showlineno=True):
3535
buf.write('\n')
3636
for c in self.children():
3737
c.show(buf, offset + indent, attrnames, showlineno)
38-
38+
3939
def __eq__(self, other):
4040
if type(self) != type(other): return False
4141
self_attrs = tuple( [ getattr(self, a) for a in self.attr_names ] )
@@ -45,10 +45,10 @@ def __eq__(self, other):
4545
for i, c in enumerate(self.children()):
4646
if c != other_children[i]: return False
4747
return True
48-
48+
4949
def __ne__(self, other):
5050
return not self.__eq__(other)
51-
51+
5252
def __hash__(self):
5353
s = hash(tuple([getattr(self, a) for a in self.attr_names]))
5454
c = hash(self.children())
@@ -559,6 +559,8 @@ def children(self):
559559

560560
class CasexStatement(CaseStatement): pass
561561

562+
class UniqueCaseStatement(CaseStatement): pass
563+
562564
class Case(Node):
563565
attr_names = ()
564566
def __init__(self, cond, statement, lineno=0):

pyverilog/vparser/lexer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def token(self):
4646
'INPUT', 'INOUT', 'OUTPUT', 'TRI', 'REG', 'LOGIC', 'WIRE', 'INTEGER', 'REAL', 'SIGNED',
4747
'PARAMETER', 'LOCALPARAM', 'SUPPLY0', 'SUPPLY1',
4848
'ASSIGN', 'ALWAYS', 'ALWAYS_FF', 'ALWAYS_COMB', 'SENS_OR', 'POSEDGE', 'NEGEDGE', 'INITIAL',
49-
'IF', 'ELSE', 'FOR', 'WHILE', 'CASE', 'CASEX', 'ENDCASE', 'DEFAULT',
49+
'IF', 'ELSE', 'FOR', 'WHILE', 'CASE', 'CASEX', 'UNIQUE', 'ENDCASE', 'DEFAULT',
5050
'WAIT', 'FOREVER', 'DISABLE', 'FORK', 'JOIN',
5151
)
5252

@@ -266,18 +266,18 @@ def dump_tokens(text):
266266
def my_error_func(msg, a, b):
267267
sys.write(msg + "\n")
268268
sys.exit()
269-
269+
270270
lexer = VerilogLexer(error_func=my_error_func)
271271
lexer.build()
272272
lexer.input(text)
273273

274274
ret = []
275-
275+
276276
# Tokenize
277277
while True:
278278
tok = lexer.token()
279279
if not tok: break # No more input
280280
ret.append("%s %s %d %s %d\n" %
281281
(tok.value, tok.type, tok.lineno, lexer.filename, tok.lexpos))
282-
282+
283283
return ''.join(ret)

pyverilog/vparser/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ def p_basic_statement(self, p):
13721372
"""basic_statement : if_statement
13731373
| case_statement
13741374
| casex_statement
1375+
| unique_case_statement
13751376
| for_statement
13761377
| while_statement
13771378
| event_statement
@@ -1614,6 +1615,12 @@ def p_casex_statement(self, p):
16141615
p[0] = CasexStatement(p[3], p[5], lineno=p.lineno(1))
16151616
p.set_lineno(0, p.lineno(1))
16161617

1618+
def p_unique_case_statement(self, p):
1619+
'unique_case_statement : UNIQUE CASE LPAREN case_comp RPAREN casecontent_statements ENDCASE'
1620+
p[0] = UniqueCaseStatement(p[3], p[5], lineno=p.lineno(1))
1621+
p.set_lineno(0, p.lineno(1))
1622+
1623+
16171624
def p_case_comp(self, p):
16181625
'case_comp : expression'
16191626
p[0] = p[1]

0 commit comments

Comments
 (0)