# Compute the x'th fibonacci number.
def fib(x)
if x < 3 then
1
else
fib(x-1)+fib(x-2)
# This expression will compute the 40th number.
fib(40)
I called the example program toy.kal. When I run toy < toy.kal
I get the output below which has unexpected errors in it; i.e., it is as if the example toy.kal is not a valid Kaleidoscope program ?
./toy < tol.kal
ready> ready> Error: Unknown variable name
ready> Error: Unknown variable name
ready> Error: Unknown variable name
ready> Read top-level expression:define double @__anon_expr() {
entry:
ret double 1.000000e+00
}
ready> Error: Unknown variable name
ready> Error: Unknown function referenced
Error: Unknown function referenced
ready> Error: Unknown function referenced
ready> ; ModuleID = 'my cool jit'
source_filename = "my cool jit"
Chapter 5 will add the control flow support. So if you compile chapter 5 source code with “clang++ -g toy.cpp llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native -O3 -o toy” and then run that toy.kal, it should work fine.
I have another quesiton about this example. It uses the Function class defined by the following include in toy.cpp:
#include "llvm/IR/Function.h`"
and used as a codegen return value; e.g.
Function *codegen();
When I search for the documentaiotn for this class I do not find it, not even in the doxygen. Looking in llvm/IR/Function.h I do not see documentation there either. Is this class part of the llvm API and if so, where can I find documentation for what will be supported by future releases ?
Yes, LegacyPassManager was the default pass manager. I think LLVM now switches to NewPassManager. And in the last week, Sjoerd Meijer announced that in this mailing thread. Some documentation is available here: Writing an LLVM Pass — LLVM 12 documentation or you can try llvm-tutor which show creating passes with both PassManagers.