How to compile .cpp file into LLVM IR with LLVM API?

Hi, all.

I’d like to compile source code (.cpp source file) using LLVM classes (not from command-line) into LLVM IR bytecode. How can i do it? I can’t create processes so no executable invocations (like clang or ld) are allowed. I believe ld is not needed as i’m not going to link the files.

Actually what i need is to do clang -S -emit-llvm main.cpp but using LLVM/Clang API.

Regards, Anton.