diff --git a/example/manual/bin2gray.py b/example/manual/bin2gray.py index 4646a526..51dcf2f3 100644 --- a/example/manual/bin2gray.py +++ b/example/manual/bin2gray.py @@ -28,7 +28,11 @@ def testBench(width): return (dut, stimulus()) -if __name__ == '__main__': +def main(): Simulation(testBench(width=3)).run() +if __name__ == '__main__': + main() + + diff --git a/example/manual/fifo.py b/example/manual/fifo.py index 0f06cfa5..5fb30cd1 100644 --- a/example/manual/fifo.py +++ b/example/manual/fifo.py @@ -1,5 +1,6 @@ from __future__ import generators import sys +import traceback from myhdl import Signal, Simulation, posedge, negedge, delay, \ StopSimulation, join @@ -124,6 +125,13 @@ def test(): sim = Simulation(clkGen(), test(), dut) -if __name__ == "__main__": - sim.run() +def main(): + try: + sim.run() + except: + traceback.print_exc() +if __name__ == '__main__': + main() + + diff --git a/example/manual/greetings.py b/example/manual/greetings.py index 5cef9d29..049b7412 100644 --- a/example/manual/greetings.py +++ b/example/manual/greetings.py @@ -27,6 +27,10 @@ def greetings(): return clkGen1, clkGen2, sayHello1, sayHello2 -sim = Simulation(greetings()) -sim.run(50) +def main(): + sim = Simulation(greetings()) + sim.run(50) + +if __name__ == '__main__': + main() diff --git a/example/manual/hec.py b/example/manual/hec.py index 93da8eb2..b429cd56 100644 --- a/example/manual/hec.py +++ b/example/manual/hec.py @@ -23,7 +23,9 @@ headers = ( 0x00000000, 0xbac6f4ca ) -if __name__ == '__main__': +def main(): for header in headers: print hex(calculateHec(intbv(header))) +if __name__ == '__main__': + main() diff --git a/example/manual/hello1.py b/example/manual/hello1.py index e404121c..18f1d1c0 100644 --- a/example/manual/hello1.py +++ b/example/manual/hello1.py @@ -6,6 +6,11 @@ def sayHello(): yield delay(10) print "%s Hello World!" % now() -sim = Simulation(sayHello()) -sim.run(30) +def main(): + sim = Simulation(sayHello()) + sim.run(30) + +if __name__ == '__main__': + main() + diff --git a/example/manual/hello2.py b/example/manual/hello2.py index 4eb4483c..b2bf9c43 100644 --- a/example/manual/hello2.py +++ b/example/manual/hello2.py @@ -15,6 +15,9 @@ def sayHello(): yield posedge(clk) print "%s Hello World!" % now() -sim = Simulation(clkGen(), sayHello()) -sim.run(50) +def main(): + sim = Simulation(clkGen(), sayHello()) + sim.run(50) +if __name__ == '__main__': + main() diff --git a/example/manual/inc.py b/example/manual/inc.py index 2623e3af..23c7288a 100644 --- a/example/manual/inc.py +++ b/example/manual/inc.py @@ -52,10 +52,14 @@ def monitor(): print " %s %s" % (enable, count) -if __name__ == "__main__": +def main(): Simulation(clockGen(), stimulus(), INC_1, monitor(), INC_1).run() +if __name__ == '__main__': + main() + + diff --git a/example/manual/mux.py b/example/manual/mux.py index 1dbd6833..c009dd68 100644 --- a/example/manual/mux.py +++ b/example/manual/mux.py @@ -28,6 +28,8 @@ def test(): yield delay(10) print "%s %s %s %s" % (z, a, b, sel) -if __name__ == "__main__": +def main(): Simulation(MUX_1, test()).run() +if __name__ == '__main__': + main() diff --git a/example/manual/rs232.py b/example/manual/rs232.py index efb61444..1938f407 100644 --- a/example/manual/rs232.py +++ b/example/manual/rs232.py @@ -107,14 +107,17 @@ def testJoin(): txData = intbv(val) yield join(rs232_rx(rx, rxData), rs232_tx(tx, txData, duration=T_10200)) +def main(): + print "\n\n## stimulus ##\n" + Simulation(stimulus()).run() + print "\n\n## test ##\n" + Simulation(test()).run() + print "\n\n## testTimeout ##\n" + Simulation(testTimeout()).run() + print "\n\n## testNoJoin ##\n" + Simulation(testNoJoin()).run() + print "\n\n## testJoin ##\n" + Simulation(testJoin()).run() -print "\n\n## stimulus ##\n" -Simulation(stimulus()).run() -print "\n\n## test ##\n" -Simulation(test()).run() -print "\n\n## testTimeout ##\n" -Simulation(testTimeout()).run() -print "\n\n## testNoJoin ##\n" -Simulation(testNoJoin()).run() -print "\n\n## testJoin ##\n" -Simulation(testJoin()).run() +if __name__ == '__main__': + main() diff --git a/example/manual/sparseMemory.py b/example/manual/sparseMemory.py index 0fd150f7..40c2d177 100644 --- a/example/manual/sparseMemory.py +++ b/example/manual/sparseMemory.py @@ -1,5 +1,7 @@ from __future__ import generators +import traceback + from myhdl import Signal, Simulation, posedge, negedge, delay, StopSimulation @@ -99,10 +101,14 @@ def test(): sim = Simulation(clkGen(), test(), dut) -if __name__ == "__main__": - sim.run() - +def main(): + try: + sim.run() + except: + traceback.print_exc() +if __name__ == '__main__': + main()