lol
1{
2 stdenv,
3 writeText,
4 qbe,
5}:
6
7# The hello world program available at https://c9x.me/compile/
8let
9 helloWorld = writeText "hello-world.ssa" ''
10 function w $add(w %a, w %b) { # Define a function add
11 @start
12 %c =w add %a, %b # Adds the 2 arguments
13 ret %c # Return the result
14 }
15 export function w $main() { # Main function
16 @start
17 %r =w call $add(w 1, w 1) # Call add(1, 1)
18 call $printf(l $fmt, w %r, ...) # Show the result
19 ret 0
20 }
21 data $fmt = { b "One and one make %d!\n", b 0 }
22 '';
23
24in
25stdenv.mkDerivation {
26 name = "qbe-test-can-run-hello-world";
27 meta.timeout = 10;
28 buildCommand = ''
29 ${qbe}/bin/qbe -o asm.s ${helloWorld}
30 cc -o out asm.s
31 ./out | grep 'One and one make 2!'
32 touch $out
33 '';
34}