blaise/vendor/qbe/test/sum.ssa
Graeme Geldenhuys 25de8be212 Fix compilation errors; vendor QBE 1.2; end-to-end Hello World works
Fix TProgram.Uses reserved-word clash (renamed to UsedUnits), nested
brace-comment in uParser.pas, and missing uAST in Blaise.pas uses clause.

Vendor QBE 1.2 source in vendor/qbe/ (built locally with make; binary
excluded via .gitignore). End-to-end pipeline confirmed: Blaise compiles
Hello World and Calc (6*7=42) to native x86_64 Linux binaries.

71/71 FPCUnit tests passing.
2026-04-20 16:38:57 +01:00

33 lines
608 B
Plaintext

# Simple test for addressing modes.
export
function w $sum(l %arr, w %num) {
@start
@loop
%n1 =w phi @start %num, @loop1 %n2
%s0 =w phi @start 0, @loop1 %s1
%n2 =w sub %n1, 1
%c =w cslew %n1, 0
jnz %c, @end, @loop1
@loop1
%idx0 =l extsw %n2
%idx1 =l mul 4, %idx0
%idx2 =l add %idx1, %arr
%w =w loadw %idx2
%s1 =w add %w, %s0
jmp @loop
@end
ret %s0
}
# >>> driver
# extern int sum(int *, int);
# int arr[] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 };
# #define N sizeof arr / sizeof arr[0]
# int main() {
# int i, s;
# for (s=i=0; i<N; i++) s+=arr[i];
# return !(sum(arr, N) == s);
# }
# <<<