Hello world shows how to create a Main and import an external function. (llvm has all the definitions of the std c lib)
The recursive Fibonacci shows how to call an internal function
The iterative Fibonacci shows how to create local Variables and do add and sub
All expressions are in SSA (static single assignment) like this
a1 = a0 * a0
a2= a1 + b
You can't have
a0 = a0 * a0
It doesn't matter what you name them but in a compiler you would do it adding to the label name
I still need to work out how to call Functions with multiple parameters
Haven't got around to Structures, Arrays, Vectors yet
Basic Structures of First class types should be easy enough to do though
Next step is to work out how to handle functions with multiple parameters
I'm not sure how to do it yet, I'm guessing we will need to use the VarArg class since every thing you do with llvm
requires a pointer returned from it, but I'm not sure what the list pointer in the buildVarArg functions is supposed to be
it might be meaning a llvmArray or an llvmVector or maybe we can do a varArg like this
Code : Tout sélectionner
*mem = allocatememory(X)
pokeI(*mem,LLVMInt32Type())
pokeI(*mem+4,#null)
pokeI(*mem+8,LLVMInt8Type())
pokeI(*mem+12,#null)
pokeI(*mem+16,#null) ;Don't know if you need to terminate a varArg with a null I assume you do
vArg = LLVMBuildVAArg(Builder,*mem,intType,"whatever");