clang-interpreter headers issue

Hi.

I’m testing llvm/clang release 3.4 and i’m having clang-interpreter issue - headers are not found. But i can compile with clang without problems.

I’m not sure if the issue relates to the trunk/3.5 RC as i need the latest release available.

Please let me know if i miss smth.

// test file (hello world)

MBA-Anton:bin asmirnov$ cat /tmp/hw.cpp

#include <stdio.h>

int main() {

printf(“hello world\n”);

return 1;

}

// default compiler info

MBA-Anton:bin asmirnov$ clang -v

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)

Target: x86_64-apple-darwin13.3.0

Thread model: posix

// compile test file with clang

MBA-Anton:bin asmirnov$ clang /tmp/hw.cpp -o /tmp/hw

// run to test

MBA-Anton:bin asmirnov$ /tmp/hw

hello world

// where clang is?

MBA-Anton:bin asmirnov$ which clang

/usr/bin/clang

// test clang-interpreter (expected to be translated and launched)

MBA-Anton:bin asmirnov$ ./clang-interpreter /tmp/hw.cpp

/tmp/hw.cpp:1:10: fatal error: ‘stdio.h’ file not found

#include <stdio.h>

^

1 error generated.

OK, i found i’ve forgot to add -I for headers (not sure why they were not detected automatically somehow) and now clang-interpret output is exactly as expected.

The question is did it compile or interpreted source file?

I need to understand it as i can’t launch executables in my test environment. So i’m going to copy\paste
clang-interpreter code or extract static lib to avoid ./clang-interpreter executable invocation. Just want to be sure
it does not execute other executables behind the scene.

My original idea was to interpret .cpp files in 2 steps:

  1. produce .ll file using “clang -S -emit-llvm” using Driver (seems not to invoke other executables behind the scene)
  2. interpret it using “lli” tool (copy\paste code or prepare static lib instead of executable)

Is using clang-interpret code similar to this 2 steps?

Both clang-interpreter code and lli use the ExecutionEngine interface, more precisely the methods “int ExecutionEngine::runFunctionAsMain()” (http://llvm.org/docs/doxygen/html/classllvm_1_1ExecutionEngine.html#a97bbf524ee03354bb73dce9614b0e959) which is just a wrapper around ExecutionEngine::runFunction(). And if I recall from what I looked in the source code some weeks ago they will compile the given function if it’s not been compiled and then run it.

The only thing that might change is how the ExecutionEngine is setup. I just quickly skimmed through it http://llvm.org/svn/llvm-project/cfe/trunk/examples/clang-interpreter/main.cpp and http://llvm.org/svn/llvm-project/llvm/trunk/tools/lli/lli.cpp.

I hope that helps

Hi, Adrian.

Thank you for the reply, it’s exactly about question 2 in my previous email.
Now it’s clear to my how Module function can be run. Also in lli i’ve found that
Module is loaded from .ll file (which is produced by clang -S -emit-llvm). As
far as i understand Module can be compiled by Driver and launched with no
intermediate saving of bytecode to .ll file.

But i can’t figure out how converting to bytecode is done. It seems that
invoking “clang -S -emit-llvm” (by the Driver) relaunches clang with more arguments
(cc1 and many others) behind the scene which actually produces bytecode file (.ll).

Can this be rewritten with no executable invocation (i’m going to do it if it’s possible)?

BTW. Are there any significant related changes/new possibilities in 3.5 release?

Thanks and regards,
Anton.

If by saying bytecode you mean LLVM IR Code, you may want to checkout the clang::CodeGenAction class and all of its subclasses as they generate the LLVM IR code