Trevor Harmon
2010-Feb-25 19:16 UTC
[LLVMdev] Programmatic compilation of C++ file into bitcode
On Feb 25, 2010, at 1:04 AM, Duncan Sands wrote:> You can add your static analysis to llvm-gcc as an LLVM pass. > If you write it as an LLVM pass then you can also use it from > "opt", which would be convenient.Thanks, that sounds like a good approach. It appears I can get a Module instance simply by inheriting from ModulePass. There's one problem, however. I will at some point want to integrate this analysis tool with other tools. For example, an Eclipse plugin might run the analysis tool and then display the analysis results in an Eclipse window. I suppose the plugin could execute "opt" as a subprocess and then parse the output, but that seems brittle. I'd prefer to define an API in my analysis tool that other tools could then call. That's why I was trying to build upon projects/sample/* instead of lib/Transforms/Hello/*. Is there perhaps some structured mechanism for retrieving the output of an LLVM pass? That is, something better than just parsing the output of "opt"... Thanks, Trevor
Trevor Harmon
2010-Feb-25 22:28 UTC
[LLVMdev] Programmatic compilation of C++ file into bitcode
On Feb 25, 2010, at 11:16 AM, Trevor Harmon wrote:> Is there perhaps some structured mechanism for retrieving the output > of an LLVM pass? That is, something better than just parsing the > output of "opt"...On rereading the opt documentation, I see: "In a few cases, it will ... generate a file with the analysis output, which is usually done when the output is meant for another program." I suppose the format of this file is totally dependent on the analyzer, but what about the location of the file? Is there some convention on where analyzers send their output? Otherwise I'm not sure how the other program can find the output, unless of course the analyzer simply dumps the file to a hard-coded location (/tmp?). Trevor
Trevor Harmon
2010-Feb-25 23:30 UTC
[LLVMdev] Programmatic compilation of C++ file into bitcode
On Feb 25, 2010, at 2:28 PM, Trevor Harmon wrote:> I'm not sure how the other program can find the output, unless > of course the analyzer simply dumps the file to a hard-coded > location (/tmp?).Replying to myself again... After sifting through many of the existing transforms, I discovered that new command-line parameters can be added to opt simply by declaring them in the transform code, such as in this example from Internalize.cpp: static cl::opt<std::string> APIFile("internalize-public-api-file", cl::value_desc("filename"), cl::desc("A file containing list of symbol names to preserve")); So, the calling program can simply pass the name of a file to opt as a parameter, and it will then know exactly where the analyzer will send its output. Trevor
Apparently Analagous Threads
- [LLVMdev] Programmatic compilation of C++ file into bitcode
- [LLVMdev] Programmatic compilation of C++ file into bitcode
- [LLVMdev] Programmatic compilation of C++ file into bitcode
- [LLVMdev] Mapping bitcode to source code
- [LLVMdev] Mapping bitcode to source code