[LLVMdev] HELP! PLEASE!
Logan Streondj
streondj at gmail.com
Sat Aug 30 04:13:07 PDT 2014
On Fri, Aug 29, 2014 at 09:40:14AM -0400, John Criswell wrote:
> >Yes, so I'm attempting to get the LLVM API to write to file,
> >or at least to stdout.
> >
> >The main one causing me angst is Module -> print
> >probably because Module -> dump() is so easy,
> >it makes it feel like I'm soo close.
> >Though since dump() goes to stderr it is useless,
> >can't actually be used for outputing the IR.
> >
> >Thus I'm assuming I have to use Module -> print,
> >but it requires a raw_ostream, and an AssemblyAnnotationWriter
> >after much searching I was able to get a raw_ostream defined,
> >but no luck with the AssemblyAnnotationWriter.
>
> The doxygen documentation says that the AssemblyAnnotationWriter is
> optional. I bet it'll just work if you pass a NULL pointer for the
> AssemblyAnnotationWriter argument.
unfortunately that did not work.
in spel.cpp:
void *nullPointer = 0;
raw_fd_ostream ros("-",errorOut);
module -> Module::print(ros,nullPointer);
at compile time:
src/spel.cpp:48:30: error: cannot initialize a parameter of type
'llvm::AssemblyAnnotationWriter *' with an lvalue of type 'void *'
module -> Module::print(ros,nullPointer);
^~~~~~~~~~~
/usr/lib/llvm-3.4/include/llvm/IR/Module.h:574:57: note: passing
argument to parameter 'AAW' here
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
^
1 error generated.
>
> If that works, you could file an enhancement request for the print()
> method to take a default NULL initializer. That would make a lot of
> sense.
are those filed through the bug database?
>
> All that said, writing out disassembled LLVM IR (i.e., LLVM IR
> assembly language) is not terribly useful; you'll end up writing a
> parser for your code to read it back in. If you want to generate
> and transform LLVM IR, you want to do using the LLVM C or C++ API.
> The best place to start is looking at the documentation on how to
> write an LLVM pass and the LLVM Programmer's Manual at the following
> URLs:
>
> http://llvm.org/docs/WritingAnLLVMPass.html
> http://llvm.org/docs/ProgrammersManual.html
>
> The doxygen documentation is great for getting information on the
> fine details of the API: http://llvm.org/doxygen/hierarchy.html.
>
> All compiler analysis and transform is done as LLVM IR passes run by
> a PassManager object. For examples of how to set that up a
> PassManager, you can look at the code in llvm/tools/bugpoint,
> llvm/tools/opt, and llvm/tools/lto.
thanks for the links,
I'm aware of optimization passes from the kaleidascope tutorial,
currently I want it to output even unoptimized code.
Though I do plan to make full use of them,
once i do have the basics functioning.
>
> To parse your input language, you would write a pass that opens the
> source file and generates LLVM IR for the code. You would then use
> WriteBitcodeToFile() to write the resulting LLVM IR to a bitcode
> file. You can then use the llvm-dis tool to disassemble the bitcode
> file into human-readable LLVM IR that you can read for debugging.
not able to get that working either unfortunately.
in spel.cpp:
#include "llvm/Bitcode/ReaderWriter.h"
...
std::string errorOut;
raw_fd_ostream ros("-",errorOut);
WriteBitcodeToFile(module, ros);
at compile time:
/home/elspru/spel/src/spel.cpp:52: undefined reference to
`llvm::WriteBitcodeToFile(llvm::Module const*, llvm::raw_ostream&)'
>
> Regards,
>
> John Criswell
:),
thanks for trying to help.
maybe there are some working examples somewhere?
> >--
> >Logan Streondj
More information about the llvm-dev
mailing list