Skip to content

Commit

Permalink
Fix typo in pragma for extra branch optimization (#438)
Browse files Browse the repository at this point in the history
Add a test to compile with TCM included and extra branch optimization enabled
  • Loading branch information
mkruselj authored Jan 30, 2024
1 parent ba944a3 commit 44fc3d8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/ksp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
66 changes: 66 additions & 0 deletions compiler/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44fc3d8

Please sign in to comment.