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