|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from pyverilog.dataflow.dataflow_analyzer import VerilogDataflowAnalyzer |
| 4 | + |
| 5 | +codedir = '../../testcode/' |
| 6 | + |
| 7 | +expected = """\ |
| 8 | +Directive: |
| 9 | +Instance: |
| 10 | +(led, 'led') |
| 11 | +Term: |
| 12 | +(Term name:led.CLK type:['Input'] msb:(IntConst 0) lsb:(IntConst 0)) |
| 13 | +(Term name:led.LED type:['Output', 'Reg'] msb:(IntConst 7) lsb:(IntConst 0)) |
| 14 | +(Term name:led.RST type:['Input'] msb:(IntConst 0) lsb:(IntConst 0)) |
| 15 | +(Term name:led.STEP type:['Parameter'] msb:'d31 lsb:'d0) |
| 16 | +(Term name:led.count type:['Reg'] msb:(IntConst 31) lsb:(IntConst 0)) |
| 17 | +Bind: |
| 18 | +(Bind dest:led.LED tree:(Branch Cond:(Terminal led.RST) True:(IntConst 0) False:(Branch Cond:(Operator Eq Next:(Terminal led.count),(Operator Minus Next:(Terminal led.STEP),(IntConst 1))) True:(Operator Plus Next:(Terminal led.LED),(IntConst 1))))) |
| 19 | +(Bind dest:led.STEP tree:(IntConst 10)) |
| 20 | +(Bind dest:led.count tree:(Branch Cond:(Terminal led.RST) True:(IntConst 0) False:(Branch Cond:(Operator Eq Next:(Terminal led.count),(Operator Minus Next:(Terminal led.STEP),(IntConst 1))) True:(IntConst 0) False:(Operator Plus Next:(Terminal led.count),(IntConst 1))))) |
| 21 | +""" |
| 22 | + |
| 23 | +def test(): |
| 24 | + filelist = [codedir + 'led.v'] |
| 25 | + topmodule = 'led' |
| 26 | + noreorder = False |
| 27 | + nobind = False |
| 28 | + include = None |
| 29 | + define = None |
| 30 | + |
| 31 | + analyzer = VerilogDataflowAnalyzer(filelist, topmodule, |
| 32 | + noreorder=noreorder, |
| 33 | + nobind=nobind, |
| 34 | + preprocess_include=include, |
| 35 | + preprocess_define=define) |
| 36 | + analyzer.generate() |
| 37 | + |
| 38 | + directives = analyzer.get_directives() |
| 39 | + instances = analyzer.getInstances() |
| 40 | + terms = analyzer.getTerms() |
| 41 | + binddict = analyzer.getBinddict() |
| 42 | + |
| 43 | + output = [] |
| 44 | + |
| 45 | + output.append('Directive:\n') |
| 46 | + for dr in sorted(directives, key=lambda x:str(x)): |
| 47 | + output.append(str(dr)) |
| 48 | + output.append('\n') |
| 49 | + |
| 50 | + output.append('Instance:\n') |
| 51 | + for module, instname in sorted(instances, key=lambda x:str(x[1])): |
| 52 | + output.append(str((module, instname))) |
| 53 | + output.append('\n') |
| 54 | + |
| 55 | + output.append('Term:\n') |
| 56 | + for tk, tv in sorted(terms.items(), key=lambda x:str(x[0])): |
| 57 | + output.append(tv.tostr()) |
| 58 | + output.append('\n') |
| 59 | + |
| 60 | + output.append('Bind:\n') |
| 61 | + for bk, bv in sorted(binddict.items(), key=lambda x:str(x[0])): |
| 62 | + for bvi in bv: |
| 63 | + output.append(bvi.tostr()) |
| 64 | + output.append('\n') |
| 65 | + |
| 66 | + rslt = ''.join(output) |
| 67 | + |
| 68 | + print(rslt) |
| 69 | + assert(rslt == expected) |
| 70 | + |
| 71 | +if __name__ == '__main__': |
| 72 | + test() |
0 commit comments