Greetings to all,
I'm new to JAL, only using it a couple of month now.
So I have the following code:
;-------------------------------------------- START
-- Compiler: >=2.4q2
const Branch_A = 0
const Branch_B = 1
const Branch_C = 2
const byte strA[] = "A"
const byte strB[] = "B"
const byte strC[] = "C"
procedure optimize_me(byte in value) is
case value of
Branch_A: serial_hw_write(strA)
Branch_B: serial_hw_write(strB)
Branch_C: serial_hw_write(strC)
end case
forever loop
end loop
end procedure
var bit maybe = false
if maybe then
optimize_me(Branch_A)
end if
optimize_me(Branch_C)
;--------------------------------------------END
I noticed that as the compiler analyses the code path and sees the forever loop it tries to prune the case ramification for items that it considers unreachable.
Yet, what happens is that it tries to optimize the whole case block at the first call instance (Branch_A), leaving an incomplete compiled code for other cases, there are workarounds to it, this is just a comment to this behavior.
Thank-you,
Leonardo Hamada
The asm code it generates with default compiler options is:
; -----START ASM
l_optimize_me
; 55 case value of
; 56 Branch_A: serial_hw_write(strA)
movlw 65
call l_serial_hw_write
goto l__l413
; 57 Branch_B: serial_hw_write(strB)
; 58 Branch_C: serial_hw_write(strC)
l__l409
; 59 end case
l__l406
; 60 forever loop
l__l413
; 61 end loop
goto l__l413
; 62 end procedure
l__l402
; 64 var bit maybe = false
bcf v__bitbucket, 0,v__access ; maybe
; 65 if maybe then
btfsc v__bitbucket, 0,v__access ; maybe
; 66 optimize_me(Branch_A)
call l_optimize_me
; 67 end if
l__l416
; 68 optimize_me(Branch_C)
call l_optimize_me
; 112 forever loop
l__l417
; 113 end loop
goto l__l417
end