1
votes

As a pet project, I am writing my own programming language and trying to compile to LLVM IR.

After seeing a few tutorials and examples, I got a bit used to how it works, but there is still one things I am not so certain of.

In the examples, most used

declare i32 @puts(i8* nocapture) nounwind

to write to the console. I think they are called native methods, but googling doesnt really help me out here.

However, I want to have more functions like this, like for example reading data from the console, or file i/o or whatever.

Where can I find a list of all the functions I can use (like puts)?

Also, are these functions platform specific? do I need other functions based on which operating system I am building to?

1

1 Answers

1
votes

puts is part of the C standard library, if you link to this library, you can use it and expect whatever guarantees the C standard makes.

If you link the C standard library you can use all the functions there. For more information, have a look at cppreference, the C standard, and/or the documentation provided by the vendor of your C standard library.

You can of course also link to other libraries, as long as you know how to find and call their functions. For C libraries, it is probably easiest to write a small C program using them and compile it with clang -emit-llvm to have a look at how they are properly called.

The C standard library should be fairly portable.