From 76a2273f6eb4a9ec930749d70b3180fa82073640 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 25 Oct 2007 17:52:39 +0000 Subject: [PATCH] some minor edits, link to Passes.html, make one point I forgot about yesterday. llvm-svn: 43350 --- llvm/docs/tutorial/LangImpl4.html | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/llvm/docs/tutorial/LangImpl4.html b/llvm/docs/tutorial/LangImpl4.html index 1048f730a163..8661b6244bfe 100644 --- a/llvm/docs/tutorial/LangImpl4.html +++ b/llvm/docs/tutorial/LangImpl4.html @@ -252,8 +252,9 @@ entry: add from the program.

LLVM provides a wide variety of optimizations that can be used in certain -circumstances. Unfortunately we don't have a good centralized description of -what every pass does, but you can check out the ones that llvm-gcc or +circumstances. Some documentation about the various +passes is available, but it isn't very complete. Another good source of +ideas is to look at the passes that llvm-gcc or llvm-ld run to get started. The "opt" tool allows you to experiment with passes from the command line, so you can see if they do anything.

@@ -410,6 +411,7 @@ declare double @cos(double) ready> sin(1.0); Evaluated to 0.841471 + ready> def foo(x) sin(x)*sin(x) + cos(x)*cos(x); Read function definition: define double @foo(double %x) { @@ -444,6 +446,27 @@ tables, for example), allows you to dynamically decide on the fly based on the function name, and even allows you to have the JIT abort itself if any lazy compilation is attempted.

+

One interesting application of this is that we can now extend the language +by writing arbitrary C++ code to implement operations. For example, if we add: +

+ +
+
+/// putchard - putchar that takes a double and returns 0.
+extern "C" 
+double putchard(double X) {
+  putchar((char)X);
+  return 0;
+}
+
+
+ +

Now we can produce simple output to the console by using things like: +"extern putchard(x); putchard(120);", which prints a lowercase 'x' on +the console (120 is the ascii code for 'x'). Similar code could be used to +implement file I/O, console input, and many other capabilities in +Kaleidoscope.

+

This completes the JIT and optimizer chapter of the Kaleidoscope tutorial. At this point, we can compile a non-Turing-complete programming language, optimize and JIT compile it in a user-driven way. Next up we'll look into