From 44fc3d8ca2068c040fffdfb0c4282548f96bd9b2 Mon Sep 17 00:00:00 2001 From: EvilDragon Date: Tue, 30 Jan 2024 22:22:44 +0100 Subject: [PATCH] Fix typo in pragma for extra branch optimization (#438) Add a test to compile with TCM included and extra branch optimization enabled --- compiler/ksp_compiler.py | 2 +- compiler/tests.py | 66 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/compiler/ksp_compiler.py b/compiler/ksp_compiler.py index ff5557c..afb22d4 100644 --- a/compiler/ksp_compiler.py +++ b/compiler/ksp_compiler.py @@ -95,7 +95,7 @@ \. # a literal dot ''', re.VERBOSE) -compiler_options = '(remove_whitespace|compact_variables|combine_callbacks|extra_syntax_checks|optimize_code|additional_branch_optimization|add_compile_date|sanitize_exit_command)' +compiler_options = '(remove_whitespace|compact_variables|combine_callbacks|extra_syntax_checks|optimize_code|extra_branch_optimization|add_compile_date|sanitize_exit_command)' pragma_compile_with_re = re.compile(r'\{\s*\#pragma\s+compile_with\s+%s\s*\}' % compiler_options) pragma_compile_without_re = re.compile(r'\{\s*\#pragma\s+compile_without\s+%s\s*\}' % compiler_options) diff --git a/compiler/tests.py b/compiler/tests.py index 6c3193d..3d4faa3 100644 --- a/compiler/tests.py +++ b/compiler/tests.py @@ -2193,6 +2193,72 @@ def testTaskfunc(self): output = do_compile(code, optimize = True) assert_equal(self, output, expected_output) + def testTaskfuncWithAdditionalBranchOptimization(self): + code = ''' + { pragma compile_with extra_branch_optimization } + + on init + SET_CONDITION(TCM_DEBUG) + tcm.init(100) + declare x + end on + + taskfunc randomize(min, max) -> result + declare r := random(min, max) + result := r + end taskfunc + + on note + x := randomize(44, 88) + end on''' + + expected_output = ''' + on init + declare %p[32768] + declare $sp + $sp := 268 + declare $fp + $fp := 268 + declare $tx + declare %tstate__id[326] + declare %tstate__fs[326] + $tx := 0 + while ($tx<326) + %tstate__fs[$tx] := 168+($tx*100) + inc($tx) + end while + $tx := 0 + %tstate__id[0] := -1 + pgs_create_key(TCM_EXCEPTION,5) + pgs_set_key_val(TCM_EXCEPTION,$CURRENT_SCRIPT_SLOT,0) + declare $x + end on + function check_full + if ($sp<(%tstate__fs[$tx]+2)) + pgs_set_key_val(TCM_EXCEPTION,$CURRENT_SCRIPT_SLOT,2) + end if + end function + function randomize + %p[$sp-5] := $fp + $fp := $sp-5 + $sp := $fp + call check_full + %p[$fp+1] := random(%p[$fp+2],%p[$fp+3]) + %p[$fp+4] := %p[$fp+1] + $sp := $fp + $fp := %p[$fp] + $sp := $sp+5 + end function + on note + %p[$sp-3] := 44 + %p[$sp-2] := 88 + call randomize + $x := %p[$sp-1] + end on''' + + output = do_compile(code, optimize = True) + assert_equal(self, output, expected_output) + def testTaskfuncWithTWaitAndOutParam(self): code = ''' on init