to the C-Compiler I get an error. If I pass the same variable in LoCase characters it works.
It seems like the PB-Compiler LoCase all variable names. But not in Macros!
Go to Lines 133, 140, 147 and switch to the BSwapVar(W), BSwapVar(L), BSwapVar(Q)
to see the problem! Only in C-Backend!!!
Is there any workarround to fix that?
I tested with PB 6.12 x64 Windows 10
Update: Bug x32 ASM Backend fixed!
Code: Select all
; ===========================================================================
; Universal BSwap Macro : BSwapVar to swap the bytes in a variable
; does not matter which size the variable has!
; ===========================================================================
EnableExplicit
; there is a problem in C-Backend. In C-Backend we have to
; call BSwapVar always with variable name in lower case
; if we define L.l and call BSwapVar(L) we get an error
; if we call BSwapVar(l) it works!
; it looks like the compler LoCase all variables but in a Macro not!
CompilerIf #PB_Compiler_Backend = #PB_Backend_C
Macro BSwapVar(var)
CompilerSelect SizeOf(var)
CompilerCase 2
!v_#var = __builtin_bswap16(v_#var);
CompilerCase 4
!v_#var = __builtin_bswap32(v_#var);
CompilerCase 8
!v_#var = __builtin_bswap64(v_#var);
CompilerEndSelect
EndMacro
CompilerElse
; ASM Backend
Macro BSwapVar(var)
EnableASM
CompilerSelect SizeOf(var)
CompilerCase 2
!XOR EAX, EAX
MOV AX, var
!XCHG AL, AH
MOV var, AX
CompilerCase 4
MOV EAX, var
!BSWAP EAX
MOV var, EAX
CompilerCase 8
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
MOV RAX, var
!BSWAP RAX
MOV var, RAX
CompilerElse
LEA ECX, var ; load effective address of Value (:= @Value)
!MOV EDX, DWORD [ECX]
!MOV EAX, DWORD [ECX +4]
!BSWAP EDX
!BSWAP EAX
!MOV DWORD [ECX], EAX
!MOV DWORD [ECX +4], EDX
CompilerEndIf
CompilerEndSelect
DisableASM
EndMacro
CompilerEndIf
Procedure Test()
Protected Qp.q, Lp.l, Wp.w
Debug ""
Debug "----------------------------------------"
Debug "BSwap inside Procedure"
Debug "----------------------------------------"
Debug ""
Debug "Varsizes"
Debug SizeOf(Wp)
Debug SizeOf(Lp)
Debug SizeOf(Qp)
Wp=$1122
Lp=$11223344
Qp=$1122334455667788
Debug ""
Debug "BSwap16"
Debug Hex(wp, #PB_Word)
BSwapVar(wp)
Debug Hex(wp, #PB_Word)
; This do not work in C-Backend
Debug ""
Debug "BSwap32"
Debug Hex(lp, #PB_Long)
BSwapVar(lp)
Debug Hex(lp, #PB_Long)
; This do not work in C-Backend
Debug ""
Debug "BSwap64"
Debug Hex(qp, #PB_Quad)
BSwapVar(qp)
Debug Hex(qp, #PB_Quad)
EndProcedure
Define Q.q, L.l, W.w
Debug "----------------------------------------"
Debug "BSwap outside of Procedure"
Debug "----------------------------------------"
Debug ""
Debug "Varsizes"
Debug SizeOf(W)
Debug SizeOf(L)
Debug SizeOf(Q)
W=$1122
L=$11223344
Q=$1122334455667788
Debug ""
Debug "BSwap16"
Debug Hex(w, #PB_Word)
BSwapVar(w) ; in LoCase it works
; BSwapVar(W) ; in UpCase it do not work in C-Backen!
Debug Hex(w, #PB_Word)
Debug ""
Debug "BSwap32"
Debug Hex(l, #PB_Long)
BSwapVar(l)
; BSwapVar(L) ; don't work with UCase character
Debug Hex(l, #PB_Long)
Debug ""
Debug "BSwap64"
Debug Hex(q, #PB_Quad)
BSwapVar(q)
; BSwapVar(Q) ; don't work with UCase character
Debug Hex(q, #PB_Quad)
Test()



