qbe: add hello world test

This commit is contained in:
Francesco Gazzetta 2021-06-21 15:53:14 +02:00
parent 4b8b7840cf
commit 72419d8ee0
2 changed files with 37 additions and 1 deletions

View file

@ -1,6 +1,7 @@
{ lib, stdenv
, fetchgit
, unstableGitUpdater
, callPackage
}:
stdenv.mkDerivation rec {
@ -15,7 +16,10 @@ stdenv.mkDerivation rec {
makeFlags = [ "PREFIX=$(out)" ];
passthru.updateScript = unstableGitUpdater { };
passthru = {
tests.can-run-hello-world = callPackage ./test-can-run-hello-world.nix {};
updateScript = unstableGitUpdater { };
};
meta = with lib; {
homepage = "https://c9x.me/compile/";

View file

@ -0,0 +1,32 @@
{ stdenv
, writeText
, qbe
}:
# The hello world program available at https://c9x.me/compile/
let helloWorld = writeText "hello-world.ssa" ''
function w $add(w %a, w %b) { # Define a function add
@start
%c =w add %a, %b # Adds the 2 arguments
ret %c # Return the result
}
export function w $main() { # Main function
@start
%r =w call $add(w 1, w 1) # Call add(1, 1)
call $printf(l $fmt, w %r, ...) # Show the result
ret 0
}
data $fmt = { b "One and one make %d!\n", b 0 }
'';
in stdenv.mkDerivation {
name = "qbe-test-can-run-hello-world";
meta.timeout = 10;
buildCommand = ''
${qbe}/bin/qbe -o asm.s ${helloWorld}
cc -o out asm.s
./out | grep 'One and one make 2!'
touch $out
'';
}