2 Commits 1c71a5d6d2 ... 7c62e45f00

Author SHA1 Message Date
  Michael Buesch 7c62e45f00 setup/cython: Add support for ubsan 5 years ago
  Michael Buesch 5b84512dc7 insns/call: Remove unnecessary C-call 5 years ago
5 changed files with 54 additions and 29 deletions
  1. 29 0
      README.md
  2. 1 2
      awlsim/core/instructions/insn_call.pxd.in
  3. 7 24
      awlsim/core/instructions/insn_call.py
  4. 12 3
      misc/setup_cython.py
  5. 5 0
      setup.py

+ 29 - 0
README.md

@@ -210,6 +210,35 @@ The following environment variables control Awlsim's basic behavior:
   The number of OB1 cycles it takes to trigger a manual garbage collection.<br />
 
 
+## Environment variables during build (setup.py)
+
+The following environment variables control Awlsim's build (setup.py) behavior:
+
+* `AWLSIM_FULL_BUILD`<br />
+  `=0`  Do not include scripts that are not necessary on this platform. (default)<br />
+  `=1`  Include all scripts; also those that aren't required on the platform.<br />
+
+* `AWLSIM_CYTHON_BUILD`<br />
+  `=0`  Do not build any Cython modules. (default on non-Posix)<br />
+  `=1`  Build Cython modules.<br />
+  `=2`  Build Cython modules only, if setup.py is being executed by Python 2.<br />
+  `=3`  Build Cython modules only, if setup.py is being executed by Python 3. (default on Posix)<br />
+
+* `AWLSIM_CYTHON_PARALLEL`<br />
+  `=0`  Do not use parallel compilation for Cython modules.<br />
+  `=1`  Invoke multiple compilers in parallel (faster on multicore). (default)<br />
+  `=2`  Invoke multiple compilers only, if setup.py is being executed by Python 2.<br />
+  `=3`  Invoke multiple compilers only, if setup.py is being executed by Python 3.<br />
+
+* `AWLSIM_PROFILE`<br />
+  `=0`  Do not enable profiling support in compiled Cython modules. (default)<br />
+  `=1`  Enable profiling support in compiled Cython modules.<br />
+
+* `AWLSIM_DEBUG_BUILD`<br />
+  `=0`  Do not enable debugging support in compiled Cython modules. (default)<br />
+  `=1`  Enable debugging support in compiled Cython modules.<br />
+
+
 ## Building Awlsim
 
 Awlsim can be run from the source directory in interpreted Python mode without building it. Just `cd` into the Awlsim source directory and execute the desired main executable (e.g. `./awlsim-gui` or `./awlsim-server` etc...).

+ 1 - 2
awlsim/core/instructions/insn_call.pxd.in

@@ -5,8 +5,7 @@ cdef class AwlInsn_AbstractCall(AwlInsn):
 	pass
 
 cdef class AwlInsn_CALL(AwlInsn_AbstractCall):
-	cdef __run_CALL_FC(self)
-	cdef __run_CALL_FB(self)
+	pass
 
 cdef class AwlInsn_CC(AwlInsn_AbstractCall):
 	pass

+ 7 - 24
awlsim/core/instructions/insn_call.py

@@ -2,7 +2,7 @@
 #
 # AWL simulator - instructions
 #
-# Copyright 2012-2017 Michael Buesch <m@bues.ch>
+# Copyright 2012-2019 Michael Buesch <m@bues.ch>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -171,39 +171,22 @@ class AwlInsn_AbstractCall(AwlInsn): #+cdef
 
 class AwlInsn_CALL(AwlInsn_AbstractCall): #+cdef
 
-	__slots__ = (
-		"run",
-	)
+	__slots__ = ()
 
 	def __init__(self, cpu, rawInsn=None, **kwargs):
 		AwlInsn_AbstractCall.__init__(self, cpu, AwlInsn.TYPE_CALL, rawInsn, **kwargs)
 		self.assertOpCount((1, 2))
 
-		if self.opCount == 1:			#@nocy
-			self.run = self.__run_CALL_FC	#@nocy
-		else:					#@nocy
-			self.run = self.__run_CALL_FB	#@nocy
-
-	def __run_CALL_FC(self): #+cdef
-#@cy		cdef S7StatusWord s
-
-		self.cpu.run_CALL(self.op0, None, self.params, False)
-		s = self.cpu.statusWord
-		s.OS, s.OR, s.STA, s.NER = 0, 0, 1, 0
-
-	def __run_CALL_FB(self): #+cdef
+	def run(self): #+cdef
 #@cy		cdef S7StatusWord s
 
-		self.cpu.run_CALL(self.op0, self.op1, self.params, False)
+		if self.opCount == 1:
+			self.cpu.run_CALL(self.op0, None, self.params, False)
+		else:
+			self.cpu.run_CALL(self.op0, self.op1, self.params, False)
 		s = self.cpu.statusWord
 		s.OS, s.OR, s.STA, s.NER = 0, 0, 1, 0
 
-#@cy	cdef run(self):
-#@cy		if self.opCount == 1:
-#@cy			self.__run_CALL_FC()
-#@cy		else:
-#@cy			self.__run_CALL_FB()
-
 class AwlInsn_CC(AwlInsn_AbstractCall): #+cdef
 
 	__slots__ = ()

+ 12 - 3
misc/setup_cython.py

@@ -1,8 +1,8 @@
 #
 #   Cython patcher
-#   v1.18
+#   v1.19
 #
-#   Copyright (C) 2012-2018 Michael Buesch <m@bues.ch>
+#   Copyright (C) 2012-2019 Michael Buesch <m@bues.ch>
 #
 #   This program is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@ WORKER_CPU_OVERCOMMIT	= 2
 
 parallelBuild = False
 profileEnabled = False
+debugEnabled = False
 ext_modules = []
 CythonBuildExtension = None
 
@@ -352,7 +353,15 @@ def registerCythonModule(baseDir, sourceModName):
 					extra_compile_args.append("-Wno-cast-function-type")
 					extra_compile_args.append("-Wno-maybe-uninitialized")
 					extra_compile_args.append("-Wno-type-limits")
-					if not profileEnabled:
+					if debugEnabled:
+						# Enable debugging and UBSAN.
+						extra_compile_args.append("-g3")
+						extra_compile_args.append("-fsanitize=undefined")
+						extra_compile_args.append("-fsanitize=float-divide-by-zero")
+						extra_compile_args.append("-fsanitize=float-cast-overflow")
+						extra_compile_args.append("-fno-sanitize-recover")
+						extra_link_args.append("-lubsan")
+					else:
 						# Disable all debugging symbols.
 						extra_compile_args.append("-g0")
 						extra_link_args.append("-Wl,--strip-all")

+ 5 - 0
setup.py

@@ -24,6 +24,10 @@
 #	0 (default): Do not enable profiling support in compiled Cython modules.
 #	1:           Enable profiling support in compiled Cython modules.
 #
+#  AWLSIM_DEBUG_BUILD:
+#	0 (default): Do not enable debugging support in compiled Cython modules.
+#	1:           Enable debugging support in compiled Cython modules.
+#
 
 from __future__ import division, absolute_import, print_function
 # Avoid __future__.unicode_literals. It breaks on pypy2.
@@ -70,6 +74,7 @@ buildCython = ((buildCython == 1) or (buildCython == sys.version_info[0]))
 setup_cython.parallelBuild = bool(getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == 1 or\
 				  getEnvInt("AWLSIM_CYTHON_PARALLEL", 1) == sys.version_info[0])
 setup_cython.profileEnabled = bool(getEnvInt("AWLSIM_PROFILE") > 0)
+setup_cython.debugEnabled = bool(getEnvInt("AWLSIM_DEBUG_BUILD") > 0)
 
 
 def pyCythonPatchLine(line):