mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
add truth table generator
This commit is contained in:
parent
bf7864104a
commit
68750445cd
3 changed files with 33 additions and 0 deletions
0
migScope/tools/__init__.py
Normal file
0
migScope/tools/__init__.py
Normal file
29
migScope/tools/truthtable.py
Normal file
29
migScope/tools/truthtable.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
def get_operands(s):
|
||||
return sorted(re.findall("[A-z0-9_]+",s))
|
||||
|
||||
def gen_truth_table(s):
|
||||
operands = get_operands(s)
|
||||
width = len(operands)
|
||||
stim = []
|
||||
for i in range(width):
|
||||
stim_op = []
|
||||
for j in range(2**width):
|
||||
stim_op.append((int(j/(2**i)))%2)
|
||||
stim.append(stim_op)
|
||||
|
||||
truth_table = []
|
||||
for i in range(2**width):
|
||||
for j in range(width):
|
||||
exec("%s = stim[j][i]" %operands[j])
|
||||
truth_table.append(eval(s))
|
||||
return truth_table
|
||||
|
||||
def main():
|
||||
print(gen_truth_table("(A&B&C)|D"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
4
top.py
4
top.py
|
@ -8,6 +8,8 @@ from migen.bus import csr
|
|||
import migScope
|
||||
import spi2Csr
|
||||
|
||||
from migScope.tools.truthtable import *
|
||||
|
||||
#
|
||||
#Test Term
|
||||
#
|
||||
|
@ -91,4 +93,6 @@ print(v)
|
|||
#v = verilog.convert(spi2csr0.get_fragment())
|
||||
#print(v)
|
||||
|
||||
print(gen_truth_table("A&B&C"))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue