Abhinash Jain
2013-Jul-25 18:40 UTC
[LLVMdev] Passing String to an external function in llvm
I have one file named hashtable.cpp whose link is "http://pastebin.com/Cq2Qy50C" and one llvm pass named testing.cpp whose link is "http://pastebin.com/E3RemxLF" Now on this testing.cpp pass I have computed the string named "expr" which I want to pass to the function named hashtable(string) in hashtable.cpp (on line 106 of testing.cpp)> looking at simple examples of code compiled by Clang should give you an > idea of what instructions you need to emit.I did try but not able to pass the string. If you could go through my code it will be of great help. Thanx -- View this message in context: http://llvm.1065342.n5.nabble.com/Passing-String-to-an-external-function-in-llvm-tp59798p59812.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
David Blaikie
2013-Jul-25 20:05 UTC
[LLVMdev] Passing String to an external function in llvm
On Thu, Jul 25, 2013 at 11:40 AM, Abhinash Jain <omnia at mailinator.com> wrote:> I have one file named hashtable.cpp whose link is > "http://pastebin.com/Cq2Qy50C" > > and one llvm pass named testing.cpp whose link is > "http://pastebin.com/E3RemxLF" > > Now on this testing.cpp pass I have computed the string named "expr" which I > want to pass to the function named hashtable(string) in hashtable.cpp (on > line 106 of testing.cpp) > > >> looking at simple examples of code compiled by Clang should give you an >> idea of what instructions you need to emit. > > I did try but not able to pass the string. > > If you could go through my code it will be of great help. ThanxOK - 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. - David
Abhinash Jain
2013-Jul-25 20:45 UTC
[LLVMdev] Passing String to an external function in llvm
> 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()), ????, ????,); 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.
Reasonably Related Threads
- [LLVMdev] Passing String to an external function in llvm
- [LLVMdev] Passing String to an external function in llvm
- [LLVMdev] Passing String to an external function in llvm
- [LLVMdev] Passing an array to an external function
- [LLVMdev] Insert a function call in the code