Will especially wait for your work to test it

Code : Tout sélectionner
file: /tmp/PureBasic_TempFile1.pb
Declare.q fibPB2(n.i)
Procedure.q fibPB2(n.i)
Protected a.q,b.q,c.q
If n <= 2
ProcedureReturn 1
Else
a = 1
b = 1
While n > 2
c = a + b
b = a
a = c
n = n-1
Wend
ProcedureReturn c
EndIf
EndProcedure
Procedure.q main()
ProcedureReturn fibPB2(20)
EndProcedure
; IDE Options = PureBasic 4.51 (Linux - x86)
; CursorPosition = 12
; CursorColumn = 12
; Folding = -
; EnableXP
; ModuleID = 'test'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i686-pc-linux-gnu"
define i64 @fibPB2(i32 %n) {
Entry:
%cond = icmp slt i32 %n, 3
br i1 %cond, label %CmpTrue1, label %While1
CmpTrue1: ; preds = %While1, %Entry
%merge = phi i64 [ 1, %Entry ], [ %c.0, %While1 ]
ret i64 %merge
While1: ; preds = %Entry, %WhileBody1
%c.0 = phi i64 [ %add, %WhileBody1 ], [ 0, %Entry ]
%b.0 = phi i64 [ %a.0, %WhileBody1 ], [ 1, %Entry ]
%a.0 = phi i64 [ %add, %WhileBody1 ], [ 1, %Entry ]
%n1.0 = phi i32 [ %sub, %WhileBody1 ], [ %n, %Entry ]
%cond4 = icmp sgt i32 %n1.0, 2
br i1 %cond4, label %WhileBody1, label %CmpTrue1
WhileBody1: ; preds = %While1
%add = add i64 %a.0, %b.0
%sub = add i32 %n1.0, -1
br label %While1
}
define i64 @main() {
Entry:
%fibPB2 = tail call i64 @fibPB2(i32 20)
ret i64 %fibPB2
}
module succeeded
Run Function in JIT
Jit Result:
6765