summaryrefslogtreecommitdiff
path: root/test/Examples
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-08-27 18:13:34 +0000
committerLang Hames <lhames@gmail.com>2015-08-27 18:13:34 +0000
commitb325a1ace53c1f0b1b38505fefeb08114f40dc10 (patch)
treeab62639f1f02696b1bfd37cea626b6df495fc3b4 /test/Examples
parent2b96ce62f49d4701bc9880e27ebc894a371342e2 (diff)
Add Kaleidoscope regression tests.
These will be run if LLVM_BUILD_EXAMPLES is enabled. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246175 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Examples')
-rw-r--r--test/Examples/Kaleidoscope/Chapter3.test17
-rw-r--r--test/Examples/Kaleidoscope/Chapter4.test17
-rw-r--r--test/Examples/Kaleidoscope/Chapter5.test19
-rw-r--r--test/Examples/Kaleidoscope/Chapter6.test15
-rw-r--r--test/Examples/Kaleidoscope/Chapter7.test15
-rw-r--r--test/Examples/lit.local.cfg2
6 files changed, 85 insertions, 0 deletions
diff --git a/test/Examples/Kaleidoscope/Chapter3.test b/test/Examples/Kaleidoscope/Chapter3.test
new file mode 100644
index 00000000000..b9c8ba6fad8
--- /dev/null
+++ b/test/Examples/Kaleidoscope/Chapter3.test
@@ -0,0 +1,17 @@
+# RUN: Kaleidoscope-Ch3 < %s 2>&1 | FileCheck %s
+
+# Test basic parsing and IR generation.
+def foo(x) x + 1;
+foo(1);
+
+# CHECK: define double @foo(double %x) {
+# CHECK-NEXT: entry:
+# CHECK-NEXT: %addtmp = fadd double %x, 1.000000e+00
+# CHECK-NEXT: ret double %addtmp
+# CHECK-NEXT: }
+
+# CHECK: define double @__anon_expr() {
+# CHECK-NEXT: entry:
+# CHECK-NEXT: %calltmp = call double @foo(double 1.000000e+00)
+# CHECK-NEXT: ret double %calltmp
+# CHECK-NEXT: }
diff --git a/test/Examples/Kaleidoscope/Chapter4.test b/test/Examples/Kaleidoscope/Chapter4.test
new file mode 100644
index 00000000000..5fd0e42c9a6
--- /dev/null
+++ b/test/Examples/Kaleidoscope/Chapter4.test
@@ -0,0 +1,17 @@
+# RUN: Kaleidoscope-Ch4 < %s 2>&1 | FileCheck %s
+
+# Test basic definition, binding, and execution.
+def foo(x) x + 1;
+def bar(x) foo(2 * x);
+bar(2);
+# CHECK: Evaluated to 5.000000
+
+# Test redefinition.
+def foo(x) x + 2;
+foo(2);
+# CHECK: Evaluated to 4.000000
+
+# Verify that 'bar' still calls the original 'foo'.
+bar(2);
+# CHECK: Evaluated to 5.000000
+
diff --git a/test/Examples/Kaleidoscope/Chapter5.test b/test/Examples/Kaleidoscope/Chapter5.test
new file mode 100644
index 00000000000..1ad902378ed
--- /dev/null
+++ b/test/Examples/Kaleidoscope/Chapter5.test
@@ -0,0 +1,19 @@
+# RUN: Kaleidoscope-Ch5 < %s 2>&1 | FileCheck %s
+
+# Test 'if' expression.
+def foo(x) if x < 10 then 0 else 1;
+foo(9);
+foo(11);
+# CHECK: Evaluated to 0.000000
+# CHECK: Evaluated to 1.000000
+
+# Test 'for' expression.
+extern printd(x);
+for i = 1, i < 5, 1.0 in
+ printd(i);
+# CHECK: 1.0
+# CHECK: 2.0
+# CHECK: 3.0
+# CHECK: 4.0
+# CHECK: 5.0
+# CHECK: Evaluated to 0.000000 \ No newline at end of file
diff --git a/test/Examples/Kaleidoscope/Chapter6.test b/test/Examples/Kaleidoscope/Chapter6.test
new file mode 100644
index 00000000000..cbdd01f5268
--- /dev/null
+++ b/test/Examples/Kaleidoscope/Chapter6.test
@@ -0,0 +1,15 @@
+# RUN: Kaleidoscope-Ch6 < %s 2>&1 | FileCheck %s
+
+# Test unary operator definition.
+def unary-(x) 0 - x;
+1 + (-1);
+# CHECK: Evaluated to 0.000000
+
+# Test binary operator definition.
+def binary> 10 (lhs rhs) rhs < lhs;
+def foo(x) if x > 10 then 0 else 1;
+foo(9);
+foo(11);
+# CHECK: Evaluated to 1.000000
+# CHECK: Evaluated to 0.000000
+
diff --git a/test/Examples/Kaleidoscope/Chapter7.test b/test/Examples/Kaleidoscope/Chapter7.test
new file mode 100644
index 00000000000..4843ca703ae
--- /dev/null
+++ b/test/Examples/Kaleidoscope/Chapter7.test
@@ -0,0 +1,15 @@
+# RUN: Kaleidoscope-Ch7 < %s 2>&1 | FileCheck %s
+
+# Sequence operator and iterative fibonacci function to test user defined vars.
+def binary : 1 (x y) y;
+
+def fibi(x)
+ var a = 1, b = 1, c in
+ (for i = 3, i < x in
+ c = a + b :
+ a = b :
+ b = c) :
+ b;
+
+fibi(10);
+# CHECK: Evaluated to 55.000000
diff --git a/test/Examples/lit.local.cfg b/test/Examples/lit.local.cfg
new file mode 100644
index 00000000000..d97a2a5b7a3
--- /dev/null
+++ b/test/Examples/lit.local.cfg
@@ -0,0 +1,2 @@
+if not config.test_examples:
+ config.unsupported = True