sim/verilator: catch ctrl-c on exit and revert default termios settings
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 16 Aug 2018 13:13:27 +0000 (15:13 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 16 Aug 2018 13:13:27 +0000 (15:13 +0200)
litex/build/sim/verilator.py

index 72b7d5e99643d33f4ea41723520cb060ba90794c..ffb89e0f62e994a4d2bc17126dde91d4f3e35ade 100644 (file)
@@ -3,6 +3,7 @@
 # License: BSD
 
 import os
+import sys
 import subprocess
 
 from migen.fhdl.structure import _Fragment
@@ -131,9 +132,16 @@ sudo obj_dir/Vdut
 """
     run_script_file = "run_" + build_name + ".sh"
     tools.write_to_file(run_script_file, run_script_contents, force_unix=True)
-    r = subprocess.call(["bash", run_script_file])
-    if r != 0:
-        raise OSError("Subprocess failed")
+    if sys.platform != "win32":
+        import termios
+        termios_settings = termios.tcgetattr(sys.stdin.fileno())
+    try:
+        r = subprocess.call(["bash", run_script_file])
+        if r != 0:
+            raise OSError("Subprocess failed")
+    except:
+        if sys.platform != "win32":
+            termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, termios_settings)
 
 
 class SimVerilatorToolchain: