[cfe-dev] clang-interpreter headers issue

Anton Smirnov dev at antonsmirnov.name
Tue Aug 19 21:37:23 PDT 2014


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.


2014-08-20 3:51 GMT+06:00 Adrián Ortega <elfus0.1 at gmail.com>:

> 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
>
>
>
>
>
>
> On Tue, Aug 19, 2014 at 2:49 AM, Anton Smirnov <dev at antonsmirnov.name>
> wrote:
>
>> 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?
>>
>> ---
>>
>> PS. My verbose execution:
>>
>> MBA-Anton:bin asmirnov$ ./clang-interpreter /tmp/hw.cpp
>> -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
>> -v
>>
>> clang version 3.4 (198679)
>>
>> Target: x86_64-apple-darwin13.3.0
>>
>> Thread model: posix
>>
>> clang invocation:
>>
>>  "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/clang-interpreter"
>> "-cc1" "-triple" "x86_64-apple-macosx10.9.0" "-fsyntax-only"
>> "-disable-free" "-disable-llvm-verifier" "-main-file-name" "hw.cpp"
>> "-mrelocation-model" "pic" "-pic-level" "2" "-mdisable-fp-elim"
>> "-masm-verbose" "-munwind-tables" "-target-cpu" "core2" "-v"
>> "-resource-dir"
>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../lib/clang/3.4"
>> "-I"
>> "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include"
>> "-stdlib=libc++" "-fdeprecated-macro" "-fdebug-compilation-dir"
>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin"
>> "-ferror-limit" "19" "-fmessage-length" "100" "-stack-protector" "1"
>> "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-10.9.0"
>> "-fencode-extended-block-signature" "-fcxx-exceptions" "-fexceptions"
>> "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-slp" "-x"
>> "c++" "/tmp/hw.cpp"
>>
>>
>> clang -cc1 version 3.4 based upon LLVM 3.4svn default target
>> x86_64-apple-darwin13.3.0
>>
>> ignoring nonexistent directory
>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../include/c++/v1"
>>
>> ignoring nonexistent directory "/usr/include/c++/v1"
>>
>> ignoring nonexistent directory "/usr/include"
>>
>> #include "..." search starts here:
>>
>> #include <...> search starts here:
>>
>>
>>  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
>>
>>  /usr/local/include
>>
>>
>>  /Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../lib/clang/3.4/include
>>
>>  /System/Library/Frameworks (framework directory)
>>
>>  /Library/Frameworks (framework directory)
>>
>> End of search list.
>>
>> hello world
>> ---
>>
>> Regards, Anton.
>>
>>
>> 2014-08-19 13:21 GMT+06:00 Anton Smirnov <dev at antonsmirnov.name>:
>>
>> 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.
>>>
>>> ---
>>>
>>> Also i don't understand actually if it tries to compile the file first
>>> (and i expect it to interpret the source file):
>>>
>>>
>>> MBA-Anton:bin asmirnov$ ./clang-interpreter /tmp/hw.cpp -v
>>>
>>> clang version 3.4 (198679)
>>>
>>> Target: x86_64-apple-darwin13.3.0
>>>
>>> Thread model: posix
>>>
>>> clang invocation:
>>>
>>>  "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/clang-interpreter"
>>> "-cc1" "-triple" "x86_64-apple-macosx10.9.0" "-fsyntax-only"
>>> "-disable-free" "-disable-llvm-verifier" "-main-file-name" "hw.cpp"
>>> "-mrelocation-model" "pic" "-pic-level" "2" "-mdisable-fp-elim"
>>> "-masm-verbose" "-munwind-tables" "-target-cpu" "core2" "-v"
>>> "-resource-dir"
>>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../lib/clang/3.4"
>>> "-stdlib=libc++" "-fdeprecated-macro" "-fdebug-compilation-dir"
>>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin"
>>> "-ferror-limit" "19" "-fmessage-length" "100" "-stack-protector" "1"
>>> "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-10.9.0"
>>> "-fencode-extended-block-signature" "-fcxx-exceptions" "-fexceptions"
>>> "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-slp" "-x"
>>> "c++" "/tmp/hw.cpp"
>>>
>>>
>>> clang -cc1 version 3.4 based upon LLVM 3.4svn default target
>>> x86_64-apple-darwin13.3.0
>>>
>>> ignoring nonexistent directory
>>> "/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../include/c++/v1"
>>>
>>> ignoring nonexistent directory "/usr/include/c++/v1"
>>>
>>> ignoring nonexistent directory "/usr/include"
>>>
>>> #include "..." search starts here:
>>>
>>> #include <...> search starts here:
>>>
>>>  /usr/local/include
>>>
>>>
>>>  /Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/bin/../lib/clang/3.4/include
>>>
>>>  /System/Library/Frameworks (framework directory)
>>>
>>>  /Library/Frameworks (framework directory)
>>>
>>> End of search list.
>>>
>>> /tmp/hw.cpp:1:10: fatal error: 'stdio.h' file not found
>>>
>>> #include <stdio.h>
>>>
>>>          ^
>>>
>>> 1 error generated.
>>>
>>>
>>> Regards, Anton.
>>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
>
> --
> *Adrián Ortega.*
> *Saludos.*
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140820/fc7218f6/attachment.html>


More information about the cfe-dev mailing list