# Copyright 2017 The Australian National University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from util import execute, compile_bundle, load_bundle, get_function; import pytest; import ctypes; def test_swapstack_kill_old(): compile_bundle( """ .funcdef test_swapstack_kill_old_swapee <()->()> { entry(): CCALL #DEFAULT exit(>3) RET } .funcdef test_swapstack_kill_old { entry(>argc >>argv): s = COMMINST uvm.new_stack<[()->()]>(test_swapstack_kill_old_swapee) SWAPSTACK s KILL_OLD PASS_VALUES<>() } """, "test_swapstack_kill_old"); assert(execute("test_swapstack_kill_old", []) == 3); def test_swapstack_swap_back(): compile_bundle( """ .funcdef test_swapstack_swap_back_swapee <(stackref)->()> { entry(s): SWAPSTACK s KILL_OLD PASS_VALUES<>() } .funcdef test_swapstack_swap_back { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_swap_back_swapee) SWAPSTACK s RET_WITH<> PASS_VALUES(cs) RET >3 } """, "test_swapstack_swap_back"); assert(execute("test_swapstack_swap_back", []) == 3); def test_swapstack_ret_values(): compile_bundle( """ .funcdef test_swapstack_ret_values_swapee <(stackref)->()> { entry(s): SWAPSTACK s KILL_OLD PASS_VALUES>(> 2) } .funcdef test_swapstack_ret_values { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_ret_values_swapee) r = SWAPSTACK s RET_WITH> PASS_VALUES(cs) rv = ADD > argc r RET rv } """, "test_swapstack_ret_values"); assert(execute("test_swapstack_ret_values", []) == 3); def test_swapstack_pass_stack_args(): compile_bundle( """ .funcsig stack_sig = (stackref double double double double double double double double double double)->() .funcdef test_swapstack_pass_stack_args_swapee { entry(s d0 d1 d2 d3 d4 d5 d6 d7 d8 d9): SWAPSTACK s KILL_OLD PASS_VALUES(d0 d1 d2 d3 d4 d5 d6 d7 d8 d9) } .funcdef test_swapstack_pass_stack_args { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[stack_sig]>(test_swapstack_pass_stack_args_swapee) (d0 d1 d2 d3 d4 d5 d6 d7 d8 d9) = SWAPSTACK s RET_WITH PASS_VALUES(cs 0.0 d 1.0 d 2.0 d 3.0 d 4.0 d 5.0 d 6.0 d 7.0 d 8.0 d 9.0 d) s1 = FADD d0 d1 s2 = FADD s1 d2 s3 = FADD s2 d3 s4 = FADD s3 d4 s5 = FADD s4 d5 s6 = FADD s5 d6 s7 = FADD s6 d7 s8 = FADD s7 d8 s9 = FADD s8 d9 r = FPTOSI > s9 RET r } """, "test_swapstack_pass_stack_args"); assert(execute("test_swapstack_pass_stack_args", []) == 45); def test_swapstack_spill(): compile_bundle( """ .funcdef test_swapstack_spill_swapee <(stackref)->()> { entry(s): SWAPSTACK s KILL_OLD PASS_VALUES<>() } .funcdef test_swapstack_spill { entry(>argc >>argv): BRANCH block(0.0 d 1.0 d 2.0 d 3.0 d 4.0 d 5.0 d 6.0 d 7.0 d 8.0 d 9.0 d) block(d0 d1 d2 d3 d4 d5 d6 d7 d8 d9): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_spill_swapee) SWAPSTACK s RET_WITH<> PASS_VALUES(cs) s1 = FADD d0 d1 s2 = FADD s1 d2 s3 = FADD s2 d3 s4 = FADD s3 d4 s5 = FADD s4 d5 s6 = FADD s5 d6 s7 = FADD s6 d7 s8 = FADD s7 d8 s9 = FADD s8 d9 r = FPTOSI > s9 RET r } """, "test_swapstack_spill"); assert(execute("test_swapstack_spill", []) == 45); def test_swapstack_throw(): compile_bundle( """ .funcdef test_swapstack_throw_swapee <(stackref)->()> { entry(s): er = NEW > eri = GETIREF > er STORE > eri > 3 ev = REFCAST > ref> er SWAPSTACK s KILL_OLD THROW_EXC ev } .funcdef test_swapstack_throw { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_throw_swapee) r = SWAPSTACK s RET_WITH> PASS_VALUES(cs) EXC(nor_dest(r) exc_dest()) nor_dest(> r): RET >0 exc_dest()[exc_param]: e = REFCAST ref>> exc_param evi = GETIREF > e ev = LOAD > evi RET ev } """, "test_swapstack_throw"); assert(execute("test_swapstack_throw", []) == 3); def test_swapstack_throw_back(): compile_bundle( """ .funcdef test_swapstack_throw_back_swapee <(stackref)->()> { entry(s): er = NEW > eri = GETIREF > er STORE > eri > 1 ev = REFCAST > ref> er r = SWAPSTACK s RET_WITH> THROW_EXC ev EXC(nor_dest(r) exc_dest()) nor_dest(> r): CCALL #DEFAULT exit(>0) RET exc_dest()[exc_param]: e = REFCAST ref>> exc_param evi = GETIREF > e ev = LOAD > evi CCALL #DEFAULT exit(ev) RET } .funcdef test_swapstack_throw_back { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_throw_back_swapee) r = SWAPSTACK s RET_WITH> PASS_VALUES(cs) EXC(nor_dest(r) exc_dest(s)) nor_dest(> r): RET >0 exc_dest( s)[exc_param]: e = REFCAST ref>> exc_param evi = GETIREF > e ev = LOAD > evi newv = ADD > ev > 2 STORE > evi newv // exc_param += 2 // Throw back to new_func SWAPSTACK s KILL_OLD THROW_EXC exc_param } """, "test_swapstack_throw_back"); assert(execute("test_swapstack_throw_back", []) == 3); def test_kill_stack(): compile_bundle( """ .funcdef test_kill_stack_swapee <(stackref)->()> { entry(s): COMMINST uvm.kill_stack(s) CCALL #DEFAULT exit(>3) RET } .funcdef test_kill_stack { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_kill_stack_swapee) SWAPSTACK s RET_WITH<> PASS_VALUES(cs) RET >0 } """, "test_kill_stack"); assert(execute("test_kill_stack", []) == 3); def test_newthread_simple(): compile_bundle( """ .funcdef test_newthread_simple_thread <()->()> { entry(): CCALL #DEFAULT exit(>3) RET } .funcdef test_newthread_simple { entry(>argc >>argv): s = COMMINST uvm.new_stack<[()->()]>(test_newthread_simple_thread) t = NEWTHREAD s PASS_VALUES<>() COMMINST uvm.thread_exit() } """, "test_newthread_simple"); assert(execute("test_newthread_simple", []) == 3); def test_newthread_swapstack(): compile_bundle( """ .funcdef test_newthread_swapstack_thread <(stackref)->()> { entry(s): t = NEWTHREAD s PASS_VALUES>(> 2) BRANCH loop() loop(): BRANCH loop() } .funcdef test_newthread_swapstack { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_newthread_swapstack_thread) r = SWAPSTACK s RET_WITH> PASS_VALUES(cs) rv = ADD > argc r RET rv // argc = 1 } """, "test_newthread_swapstack"); assert(execute("test_newthread_swapstack", []) == 3); def test_newthread_throw(): compile_bundle( """ .funcdef test_newthread_throw_thread <(stackref)->()> { entry(s): er = NEW > eri = GETIREF > er STORE > eri > 3 ev = REFCAST > ref> er t = NEWTHREAD s THROW_EXC ev COMMINST uvm.thread_exit() } .funcdef test_newthread_throw { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_newthread_throw_thread) r = SWAPSTACK s RET_WITH> PASS_VALUES(cs) EXC(nor_dest(r) exc_dest()) nor_dest(> r): RET >0 exc_dest()[exc_param]: e = REFCAST ref>> exc_param evi = GETIREF > e ev = LOAD > evi RET ev } """, "test_newthread_throw"); assert(execute("test_newthread_throw", []) == 3); def test_newthread_threadlocal(): compile_bundle( """ .funcdef test_newthread_threadlocal_thread <()->()> { entry(): tv = COMMINST uvm.get_threadlocal() tr = REFCAST ref>> tv tvi = GETIREF > tr tv = LOAD > tvi CCALL #DEFAULT exit(tv) RET } .funcdef test_newthread_threadlocal { entry(>argc >>argv): s = COMMINST uvm.new_stack<[()->()]>(test_newthread_threadlocal_thread) tr = NEW > tri = GETIREF > tr STORE > tri > 3 tl = REFCAST > ref> tr t = NEWTHREAD s THREADLOCAL (tl) PASS_VALUES<>() COMMINST uvm.thread_exit() } """, "test_newthread_threadlocal"); assert(execute("test_newthread_threadlocal", []) == 3); def test_newthread_stack_args(): compile_bundle( """ .funcsig stack_sig = (stackref double double double double double double double double double double)->() .funcdef test_newthread_stack_args_thread { entry(s d0 d1 d2 d3 d4 d5 d6 d7 d8 d9): s1 = FADD d0 d1 s2 = FADD s1 d2 s3 = FADD s2 d3 s4 = FADD s3 d4 s5 = FADD s4 d5 s6 = FADD s5 d6 s7 = FADD s6 d7 s8 = FADD s7 d8 s9 = FADD s8 d9 r = FPTOSI > s9 CCALL #DEFAULT exit(r) RET } .funcdef test_newthread_stack_args { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[stack_sig]>(test_newthread_stack_args_thread) t = NEWTHREAD s PASS_VALUES(cs 0.0 d 1.0 d 2.0 d 3.0 d 4.0 d 5.0 d 6.0 d 7.0 d 8.0 d 9.0 d) COMMINST uvm.thread_exit() } """, "test_newthread_stack_args"); assert(execute("test_newthread_stack_args", []) == 45); def test_swapstack_threadlocal(): compile_bundle( """ .funcdef test_swapstack_threadlocal_stack <(stackref)->()> { entry(s): tr = NEW > tri = GETIREF > tr STORE > tri > 3 tl = REFCAST > ref> tr t = NEWTHREAD s THREADLOCAL (tl) PASS_VALUES<>() COMMINST uvm.thread_exit() } .funcdef test_swapstack_threadlocal { entry(>argc >>argv): cs = COMMINST uvm.current_stack() s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_threadlocal_stack) SWAPSTACK s RET_WITH<> PASS_VALUES(cs) tv = COMMINST uvm.get_threadlocal() tr = REFCAST ref>> tv tvi = GETIREF > tr tv = LOAD > tvi RET (tv) } """, "test_swapstack_threadlocal"); assert(execute("test_swapstack_threadlocal", []) == 3);