IO intrinsics?

I found these lines in the BrainF example:

//declare i32 @getchar()

getchar_func = cast(module->

getOrInsertFunction(“getchar”, IntegerType::getInt32Ty(C), NULL));

//declare i32 @putchar(i32)

putchar_func = cast(module->

getOrInsertFunction(“putchar”, IntegerType::getInt32Ty(C),

IntegerType::getInt32Ty(C), NULL));

Since getchar and putchar are never defined, I’m assuming they are intrinsics, but they are not documented with the rest of the intrinsics. So are they intrinsics or something else?

Hi, Hans

Since getchar and putchar are never defined, I'm assuming they are
intrinsics, but they are not documented with the rest of the intrinsics. So
are they intrinsics or something else?

  I _guess_ standard functions like getchar/putchar are linked by
default.

Regards,
chenwj

Indeed, they're coming from libc. The JIT will find any visible functions in the program it's running in (it calls dlsym() actually), so it finds putchar() just like C code finds putchar(). You can even declare your own extern "C" functions and the JIT will find those too.

Nick

Hi Hans,

I found these lines in the BrainF example:

       //declare i32 @getchar()
       getchar_func = cast<Function>(module->
         getOrInsertFunction("getchar", IntegerType::getInt32Ty(C), NULL));

       //declare i32 @putchar(i32)
       putchar_func = cast<Function>(module->
         getOrInsertFunction("putchar", IntegerType::getInt32Ty(C),
                             IntegerType::getInt32Ty(C), NULL));

Since getchar and putchar are never defined, I'm assuming they are intrinsics,

no, they are the C standard library functions putchar and getchar.

Ciao, Duncan.

To be a bit more specific, they're guaranteed to be present because BrainF itself is a C++ program, and thus must be linked against libc. Therefore putchar and friends must be visible in the BrainF executable, and the JIT will find them when it tries to resolve the calls from within the JIT'd program.

--Owen