From daeed0ce5e5c2031366e002556c4bd6cf38f032e Mon Sep 17 00:00:00 2001 From: Dan Vargas Date: Mon, 21 Mar 2022 08:59:03 -0600 Subject: [PATCH] add piston nix pkg for llvm_ir --- packages/llvm_ir/12.0.1/build.sh | 6 ---- packages/llvm_ir/12.0.1/compile | 4 --- packages/llvm_ir/12.0.1/environment | 2 -- packages/llvm_ir/12.0.1/metadata.json | 5 --- packages/llvm_ir/12.0.1/run | 4 --- packages/llvm_ir/12.0.1/test.ll | 10 ------ runtimes/default.nix | 1 + runtimes/llvm_ir.nix | 47 +++++++++++++++++++++++++++ 8 files changed, 48 insertions(+), 31 deletions(-) delete mode 100755 packages/llvm_ir/12.0.1/build.sh delete mode 100755 packages/llvm_ir/12.0.1/compile delete mode 100644 packages/llvm_ir/12.0.1/environment delete mode 100644 packages/llvm_ir/12.0.1/metadata.json delete mode 100644 packages/llvm_ir/12.0.1/run delete mode 100644 packages/llvm_ir/12.0.1/test.ll create mode 100644 runtimes/llvm_ir.nix diff --git a/packages/llvm_ir/12.0.1/build.sh b/packages/llvm_ir/12.0.1/build.sh deleted file mode 100755 index 7afd41a..0000000 --- a/packages/llvm_ir/12.0.1/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -curl -L "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/clang+llvm-12.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz" -o llvm-ir.tar.xz - -tar xf llvm-ir.tar.xz clang+llvm-12.0.1-x86_64-linux-gnu-ubuntu-/bin --strip-components=1 - -rm llvm-ir.tar.xz diff --git a/packages/llvm_ir/12.0.1/compile b/packages/llvm_ir/12.0.1/compile deleted file mode 100755 index 082fb5c..0000000 --- a/packages/llvm_ir/12.0.1/compile +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -llc "$@" -o binary.s -clang binary.s -o binary diff --git a/packages/llvm_ir/12.0.1/environment b/packages/llvm_ir/12.0.1/environment deleted file mode 100644 index 85a25b6..0000000 --- a/packages/llvm_ir/12.0.1/environment +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -export PATH=$PWD/bin:$PATH diff --git a/packages/llvm_ir/12.0.1/metadata.json b/packages/llvm_ir/12.0.1/metadata.json deleted file mode 100644 index 50dfbbc..0000000 --- a/packages/llvm_ir/12.0.1/metadata.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "language": "llvm_ir", - "version": "12.0.1", - "aliases": ["llvm", "llvm-ir", "ll"] -} diff --git a/packages/llvm_ir/12.0.1/run b/packages/llvm_ir/12.0.1/run deleted file mode 100644 index 94b3b0b..0000000 --- a/packages/llvm_ir/12.0.1/run +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -shift -binary "$@" diff --git a/packages/llvm_ir/12.0.1/test.ll b/packages/llvm_ir/12.0.1/test.ll deleted file mode 100644 index be7d5d3..0000000 --- a/packages/llvm_ir/12.0.1/test.ll +++ /dev/null @@ -1,10 +0,0 @@ -@.str = private unnamed_addr constant [2 x i8] c"OK" - -declare i32 @puts(i8* nocapture) nounwind - -define i32 @main() { - %cast210 = getelementptr [2 x i8],[2 x i8]* @.str, i64 0, i64 0 - - call i32 @puts(i8* %cast210) - ret i32 0 -} diff --git a/runtimes/default.nix b/runtimes/default.nix index 29d1457..1669be2 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -61,4 +61,5 @@ args: { "brainfuck" = import ./brainfuck.nix args; "node-coffeescript" = import ./node-coffeescript.nix args; "jvm-scala" = import ./jvm-scala.nix args; + "llvm_ir" = import ./llvm_ir.nix args; } diff --git a/runtimes/llvm_ir.nix b/runtimes/llvm_ir.nix new file mode 100644 index 0000000..2f736aa --- /dev/null +++ b/runtimes/llvm_ir.nix @@ -0,0 +1,47 @@ +{pkgs, piston, ...}: +let + pkg = pkgs.llvm; + clang = pkgs.llvmPackages_13.libcxxClang; +in piston.mkRuntime { + language = "llvm_ir"; + version = clang.version; + + aliases = [ + "llvm" + "llvm-ir" + "ll" + ]; + + compile = '' + ${pkg}/bin/llc "$@" -o binary.s + ${clang}/bin/clang binary.s -o binary + ''; + + run = '' + shift + ./binary "$@" + ''; + + tests = [ + (piston.mkTest { + files = { + "test.ll" = '' + @.str = private unnamed_addr constant [2 x i8] c"OK" + + declare i32 @puts(i8* nocapture) nounwind + + define i32 @main() { + %cast210 = getelementptr [2 x i8],[2 x i8]* @.str, i64 0, i64 0 + + call i32 @puts(i8* %cast210) + ret i32 0 + } + ''; + }; + args = []; + stdin = ""; + packages = []; + main = "test.ll"; + }) + ]; +} \ No newline at end of file