/// putchard - putchar that takes a double and returns 0.
extern "C" double putchard(double X) {
- putchar((char)X);
+ fputc((char)X, stderr);
return 0;
}
add_kaleidoscope_chapter(Kaleidoscope-Ch4
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch4)
/// 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;
}
add_kaleidoscope_chapter(Kaleidoscope-Ch5
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch5)
/// 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;
}
add_kaleidoscope_chapter(Kaleidoscope-Ch6
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch6)
/// 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;
}
add_kaleidoscope_chapter(Kaleidoscope-Ch7
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch7)
/// 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;
}
add_kaleidoscope_chapter(Kaleidoscope-Ch8
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch8)
/// 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;
}
+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
)
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
--- /dev/null
+# 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: }
--- /dev/null
+# 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
+
--- /dev/null
+# 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
--- /dev/null
+# 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
+
--- /dev/null
+# 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
--- /dev/null
+if not config.test_examples:
+ config.unsupported = True
@$(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
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",
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.