Add Kaleidoscope regression tests.
authorLang Hames <lhames@gmail.com>
Thu, 27 Aug 2015 18:13:34 +0000 (18:13 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 27 Aug 2015 18:13:34 +0000 (18:13 +0000)
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

21 files changed:
docs/tutorial/LangImpl4.rst
examples/Kaleidoscope/Chapter4/CMakeLists.txt
examples/Kaleidoscope/Chapter4/toy.cpp
examples/Kaleidoscope/Chapter5/CMakeLists.txt
examples/Kaleidoscope/Chapter5/toy.cpp
examples/Kaleidoscope/Chapter6/CMakeLists.txt
examples/Kaleidoscope/Chapter6/toy.cpp
examples/Kaleidoscope/Chapter7/CMakeLists.txt
examples/Kaleidoscope/Chapter7/toy.cpp
examples/Kaleidoscope/Chapter8/CMakeLists.txt
examples/Kaleidoscope/Chapter8/toy.cpp
test/CMakeLists.txt
test/Examples/Kaleidoscope/Chapter3.test [new file with mode: 0644]
test/Examples/Kaleidoscope/Chapter4.test [new file with mode: 0644]
test/Examples/Kaleidoscope/Chapter5.test [new file with mode: 0644]
test/Examples/Kaleidoscope/Chapter6.test [new file with mode: 0644]
test/Examples/Kaleidoscope/Chapter7.test [new file with mode: 0644]
test/Examples/lit.local.cfg [new file with mode: 0644]
test/Makefile
test/lit.cfg
test/lit.site.cfg.in

index 702886f6aec6b432f4b51795339307634e99cb4a..92dcc3d33a0ed89fdfa82d0d783f6f8f5184dcda 100644 (file)
@@ -566,7 +566,7 @@ if we add:
 
     /// putchard - putchar that takes a double and returns 0.
     extern "C" double putchard(double X) {
-      putchar((char)X);
+      fputc((char)X, stderr);
       return 0;
     }
 
index 44e1aeecaaeb9d6b0b934556829ca2c060bc38f6..89feed143adcd53ab0ed2d5e4e1d4c4e66dccdda 100644 (file)
@@ -13,3 +13,5 @@ set(LLVM_LINK_COMPONENTS
 add_kaleidoscope_chapter(Kaleidoscope-Ch4
   toy.cpp
   )
+
+export_executable_symbols(Kaleidoscope-Ch4)
index 12777ae2c758fa93587b969b6c546aaedd9c9423..c102784b531d292698d199c6664aad6043e469d4 100644 (file)
@@ -632,13 +632,13 @@ static void MainLoop() {
 
 /// putchard - putchar that takes a double and returns 0.
 extern "C" double putchard(double X) {
-  putchar((char)X);
+  fputc((char)X, stderr);
   return 0;
 }
 
 /// printd - printf that takes a double prints it as "%f\n", returning 0.
 extern "C" double printd(double X) {
-  printf("%f\n", X);
+  fprintf(stderr, "%f\n", X);
   return 0;
 }
 
index b62ed410103fa07ae349359c35e10ff93a4db896..c0ae70654c363cfecfbf8b3e08d622a64d99f87c 100644 (file)
@@ -13,3 +13,5 @@ set(LLVM_LINK_COMPONENTS
 add_kaleidoscope_chapter(Kaleidoscope-Ch5
   toy.cpp
   )
+
+export_executable_symbols(Kaleidoscope-Ch5)
index 83af1776b20ebcf80307eee32e3d50ef8b30de4a..29db71c20a8143f88a23562704bf2d9af1404d6e 100644 (file)
@@ -906,13 +906,13 @@ static void MainLoop() {
 
 /// putchard - putchar that takes a double and returns 0.
 extern "C" double putchard(double X) {
-  putchar((char)X);
+  fputc((char)X, stderr);
   return 0;
 }
 
 /// printd - printf that takes a double prints it as "%f\n", returning 0.
 extern "C" double printd(double X) {
-  printf("%f\n", X);
+  fprintf(stderr, "%f\n", X);
   return 0;
 }
 
index 6bb2b19375276d45099c41f2072252e12a4a7d65..49627f07ddf05ece09bdcac0bf8d9f46cb163c2b 100644 (file)
@@ -13,3 +13,5 @@ set(LLVM_LINK_COMPONENTS
 add_kaleidoscope_chapter(Kaleidoscope-Ch6
   toy.cpp
   )
+
+export_executable_symbols(Kaleidoscope-Ch6)
index e1bed45189e0593d36c113036b200757080b7f9f..8f802384d1df8841a3e04c0b3747a42d83117e44 100644 (file)
@@ -1024,13 +1024,13 @@ static void MainLoop() {
 
 /// putchard - putchar that takes a double and returns 0.
 extern "C" double putchard(double X) {
-  putchar((char)X);
+  fputc((char)X, stderr);
   return 0;
 }
 
 /// printd - printf that takes a double prints it as "%f\n", returning 0.
 extern "C" double printd(double X) {
-  printf("%f\n", X);
+  fprintf(stderr, "%f\n", X);
   return 0;
 }
 
index 27c18cdd0654ff0a48df6f1d1aea1cd9f2331b46..e67d7928efe79539522bb8e955de6c522469aa31 100644 (file)
@@ -13,3 +13,5 @@ set(LLVM_LINK_COMPONENTS
 add_kaleidoscope_chapter(Kaleidoscope-Ch7
   toy.cpp
   )
+
+export_executable_symbols(Kaleidoscope-Ch7)
index 4558522952ce26d405745f2c8c1f3e426d349ccd..be00f873e6d571f997d9ce7fe5a14d4229967acc 100644 (file)
@@ -1190,13 +1190,13 @@ static void MainLoop() {
 
 /// putchard - putchar that takes a double and returns 0.
 extern "C" double putchard(double X) {
-  putchar((char)X);
+  fputc((char)X, stderr);
   return 0;
 }
 
 /// printd - printf that takes a double prints it as "%f\n", returning 0.
 extern "C" double printd(double X) {
-  printf("%f\n", X);
+  fprintf(stderr, "%f\n", X);
   return 0;
 }
 
index e335cb48ac7a244d19bb9f36ddd60c7cb827e9c1..d9b5cc421be397e6a7df382b4901505caec67f6d 100644 (file)
@@ -9,3 +9,5 @@ set(LLVM_LINK_COMPONENTS
 add_kaleidoscope_chapter(Kaleidoscope-Ch8
   toy.cpp
   )
+
+export_executable_symbols(Kaleidoscope-Ch8)
index 7338c6ebc50bd15b86b686827031e96a64bb23b5..b78d901db2d5fb5525b88dc88994b4074b35b87a 100644 (file)
@@ -1384,13 +1384,13 @@ static void MainLoop() {
 
 /// putchard - putchar that takes a double and returns 0.
 extern "C" double putchard(double X) {
-  putchar((char)X);
+  fputc((char)X, stderr);
   return 0;
 }
 
 /// printd - printf that takes a double prints it as "%f\n", returning 0.
 extern "C" double printd(double X) {
-  printf("%f\n", X);
+  fprintf(stderr, "%f\n", X);
   return 0;
 }
 
index 1f417c2a0fc6715489dc4e452b31c909f0bed1ae..464a6f0161a97a4f9622b045a8a6728a230c2896 100644 (file)
@@ -1,3 +1,7 @@
+if(LLVM_BUILD_EXAMPLES)
+  set(ENABLE_EXAMPLES 1)
+endif()
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@@ -96,6 +100,16 @@ if(TARGET ocaml_llvm)
         )
 endif()
 
+if(LLVM_BUILD_EXAMPLES)
+  list(APPEND LLVM_TEST_DEPENDS
+    Kaleidoscope-Ch3
+    Kaleidoscope-Ch4
+    Kaleidoscope-Ch5
+    Kaleidoscope-Ch6
+    Kaleidoscope-Ch7
+    )
+endif()
+
 add_lit_testsuite(check-llvm "Running the LLVM regression tests"
   ${CMAKE_CURRENT_BINARY_DIR}
   PARAMS llvm_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
diff --git a/test/Examples/Kaleidoscope/Chapter3.test b/test/Examples/Kaleidoscope/Chapter3.test
new file mode 100644 (file)
index 0000000..b9c8ba6
--- /dev/null
@@ -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 (file)
index 0000000..5fd0e42
--- /dev/null
@@ -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 (file)
index 0000000..1ad9023
--- /dev/null
@@ -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 (file)
index 0000000..cbdd01f
--- /dev/null
@@ -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 (file)
index 0000000..4843ca7
--- /dev/null
@@ -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 (file)
index 0000000..d97a2a5
--- /dev/null
@@ -0,0 +1,2 @@
+if not config.test_examples:
+    config.unsupported = True
index 558762e39dc2c1fe39c78dca028e30f5fa41a3be..9b37cedaaffd8ca0e6acdc23a25b0186cd797ecd 100644 (file)
@@ -146,6 +146,7 @@ lit.site.cfg: FORCE
        @$(ECHOPATH) s=@HOST_ARCH@=$(HOST_ARCH)=g >> lit.tmp
        @$(ECHOPATH) s=@HAVE_LIBZ@=$(HAVE_LIBZ)=g >> lit.tmp
        @$(ECHOPATH) s=@HAVE_DIA_SDK@=0=g >> lit.tmp
+       @$(ECHOPATH) s=@ENABLE_EXAMPLES@=$(BUILD_EXAMPLES)=g >> lit.tmp
        @sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
        @-rm -f lit.tmp
 
index 167a81afad1ce5a026a3785111eee24310ebcc31..38a2ec20ec8d6b4f4b61edd70a32f44bc5aff0e2 100644 (file)
@@ -258,6 +258,12 @@ for pattern in [r"\bbugpoint\b(?!-)",
                 r"\byaml2obj\b",
                 r"\byaml-bench\b",
                 r"\bverify-uselistorder\b",
+                r"\bKaleidoscope-Ch3\b",
+                r"\bKaleidoscope-Ch4\b",
+                r"\bKaleidoscope-Ch5\b",
+                r"\bKaleidoscope-Ch6\b",
+                r"\bKaleidoscope-Ch7\b",
+                r"\bKaleidoscope-Ch8\b",
                 # Handle these specially as they are strings searched
                 # for during testing.
                 r"\| \bcount\b",
index 0b8ca65a18e702f8cc34e79da269a2c202a13502..a181037965882291134a1cfa3683165cbd43bd9e 100644 (file)
@@ -35,6 +35,7 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = "@HAVE_LIBZ@"
 config.have_dia_sdk = @HAVE_DIA_SDK@
 config.enable_ffi = "@LLVM_ENABLE_FFI@"
+config.test_examples = "@ENABLE_EXAMPLES@"
 
 # Support substitution of the tools_dir with user parameters. This is
 # used when we can't determine the tool dir at configuration time.