summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/llvmtranslate/generate-runtime.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/llvmtranslate/generate-runtime.sh')
-rwxr-xr-xtiger-compiler/src/llvmtranslate/generate-runtime.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/tiger-compiler/src/llvmtranslate/generate-runtime.sh b/tiger-compiler/src/llvmtranslate/generate-runtime.sh
new file mode 100755
index 0000000..2e05445
--- /dev/null
+++ b/tiger-compiler/src/llvmtranslate/generate-runtime.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+[ -z "$1" ] && echo "$0: Missing input file" && exit
+[ -z "$2" ] && echo "$0: Missing output file" && exit
+
+input=$1
+output=$2
+
+awk 'BEGIN {
+ print("#include <string>");
+ print("#include <llvmtranslate/libllvmtranslate.hh>");
+ print("");
+ print("namespace llvmtranslate");
+ print("{");
+ print("const char* runtime_string()");
+ print("{");
+ print(" return");
+ printf("R\"0("); # The zero here only serves as an identifier for the raw string, it does not changes the code behavior at all.
+ }
+ /^#(<<|>>)/ {
+ next;
+ }
+ {
+ print($0);
+ }
+ END {
+ print(")0\";");
+ print("}");
+ print("} // namespace llvmtranslate");
+ }' "$input" > "$output".tmp
+
+mv "$output".tmp "$output"