[llvm-dev] How to "use" the LLVM API?

Thomas Kr├╝ger via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 26 23:07:05 PDT 2017


Hallo,


I currently work with the LLVM API in the C language and try to program 
a compiler for my own simple programming language, but it is very hard 
for me to work with the LLVM API. The concept behind creating a frontend 
and use the LLVM API with the complete LLVM backend is great, but to 
puzzle over the API calls is very tiring. :-|

My current state:
Yesterday I solved the problem of assigning a text to a new created heap 
i8 array indirect with the help of the strncpy stdlib function. But how 
to access the "last" array element for terminating sign is unclear for 
me. Do not want to use strcat for this case, it have to be easier. ^^ 
Creating a simple c file and converting it to LLVM IR does not help, 
because it does not saying anything about the related API calls to 
create this LLVM IR.

Questions:
Is there any good documentation about "using" the LLVM API?
Do I anything fundamental wrong in the kind of working with the API 
documentation?
I found this kind of Kaleidoscope tutorial, but it do not answer my 
questions. The plain API documentation is complete, but does not say 
about the "using" these calls. For example LLVMBuildArrayMalloc(...):
http://llvm.org/docs/doxygen/html/group__LLVMCCoreInstructionBuilder.html#gaa2572582272b52c9f13d25787e2f6937
Checking the parameters from LLVMBuildArrayMalloc shows up that it is 
ideal for creating an dynamic heap array, but it has no description and 
most of the API call signatures are not that easy to identify like the 
malloc call.

I would love to see help for these simple standard cases:
- How to assign a text to a string variable?
- How to access for example the 4th element in a heap-allocated array?
- How to create local variables which are not part of the global scope?
- How to create complex structures like classes and objects?
- and so on

Some hints in the internet say tht I should move my "problems" into C 
language, so writing functions for my compiler in plain C and link this 
file to the compiler, so there is less need for knowing how to do things 
in the LLVM API. But I want to write everything with the API, because it 
is full type safe and it does make more sence for me. It is currently 
harder for me to use the LLVM API than to create a workable new 
programming language, should be vice versa. ^^

Thanks in advance for help. :)


Best regards,
Thomas


More information about the llvm-dev mailing list