[LLVMdev] Passing String to an external function in llvm

David Blaikie dblaikie at gmail.com
Thu Jul 25 13:51:55 PDT 2013


On Thu, Jul 25, 2013 at 1:45 PM, Abhinash Jain <omnia at mailinator.com> wrote:
>> OK - seems you might want to take a few steps back & understand how
>> C++ code is written/structured generally (and/or take a look at other
>> parts of the compiler). You'll need a header file with the declaration
>> of your function & you can include that header file in the
>> hashtable.cpp and testing.cpp - if that sentence doesn't make sense to
>> you yet, please find some general C++ programming resources to provide
>> further detail as such a discussion isn't really on-topic here.
>
> I know it could be a bit frustrating for you to answer such foolish
> question, but am novice to llvm and desperately need some help to resolve
> this issue.
>
> testing.cpp is an instrumentation file of llvm, whereas hashtable.cpp is
> simple c++ code.
>
> I want to insert the function named hashtable() (which is already present in
> hashtable.cpp) after every store instruction.
> So I have to first DECLARE it,  which can be done with getOrInsertFunction()
> in testing.cpp.
> Now since declaration of function hashtable() is like
>
> void hashtable(string expr)    //in hashtable.cpp
>
> So in getOrInsertFunction() I have to pass some more details like
>
> getOrInsertFunction (name of function in IR, Return type of function, List
> of argument for the function, etc.)
> i.e. getOrInsertFunction("_Z14printHashTablev",
> Type::getVoidTy(M.getContext()), ????, ????,);

I'd suggest you try looking at the IR that Clang generates for a call
to this function & produce similar IR yourself. If you're having
trouble figuring out which APIs to call to produce the same IR there
is a "cpp" backend to LLVM that can spit out the LLVM C++ API calls to
produce the same IR, I believe - I don't recall the specifics of how
to invoke it, though.

>
> Now hashtable() function takes string as an argument, so what should I write
> in place of ???? above.
>
> And than how should I actually CALL that hashtable() function with the help
> of methods
> like CallInst::Create, getInstList().insert etc.
>
>
>
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Passing-String-to-an-external-function-in-llvm-tp59798p59818.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



More information about the llvm-dev mailing list