The goal is to program a small logic simulator. The program should read in
circuits in the benchmark format (*.bench) and translate them to an internal circuit representation. To test your simulator example inputs to the circuit are provided in separate files
(*.in). The inputs are read in and assigned to the circuit sequentially. After every input vector
the circuit needs to be evaluated and the result should be printed to the console. An example
output format together with simulation results are provided in the *.result files.
The assignment is divided into 3 parts:
a) Write the class Circuit which is able to read in a .bench file and translates the description
into an internal representation of the circuit.
The statements in the benchmark files that you need to identify are:
INPUT(name), OUTPUT(name) : These mark the input and output lines of
name = AND(name1, name2, ... name n) : This is an AND gate with inputs name 1to name
n and the output name
The gates you should implement are: NOT, AND, NAND, OR, NOR, XOR.
Hint: Create another class Node which contains the description of every gate (or in-put/output) and it’s state.
Also, you don’t need to implement every data structure. For common data structures
there are templates in the standard template library (e.g. vector) which you may use.
[url removed, login to view]
b) Write the function setInputs(string inputstring) to set all the inputs in a circuit with
the bits provided in the input string and then simulate the circuit with eval(). The
provided circuits are already sorted topologically, so the evaluation of nodes can be done
in order of appearance in the bench files.
c) Implement the function TopologicalSort() for circuits that are not sorted topologically.
Evaluate your program with the circuits in the folder mixed. These are the same circuits
as before but with their lines beeing swapped randomly