HELP! PLEASE!

I need help.
I can't get it to work.
I'm crying here, really,
I'm balling my eyes out.

Is there any way for a beginner to get support with using LLVM?
All my queries are just ignored or disregarded on this mailing list.
Why isn't there an llvm mailing list for novices?

This is the only thing that can get my programming language,
to be operation in a reasonable amount of time, AFAIK.
But it's so hard to even get the print function to work,
I just feel like a bunch of useless garbage.

Please help,
I feel terrible.
I haven't cried this much in years.

I can't get Module to print,
there are no examples I can find on the internet.
And I can't get a working instance of AssemblyAnnotationWriter.
I don't understand why it's so hard to do.

Am I really just too stupid?
This is so basic it is beneath your notice.
I don't get it, and it has me tasting salty tears.

Logan Streondj <streondj@gmail.com> writes:

Is there any way for a beginner to get support with using LLVM?
All my queries are just ignored or disregarded on this mailing list.
Why isn't there an llvm mailing list for novices?

I'm afraid I can't be of much help when it comes to the LLVM API as I've
done very little work with it. I have, however, used LLVM fairly
extensively as a free-standing compiler. Pass in LLVM IR to llc/opt, get
a binary out; really couldn't be much simpler. Admittedly the error
messages could be a bit better in the face of malformed source, but for
the most part I'm very impressed with how robust it is.

Perhaps you would be better off starting development in this mode
before jumping into linking against LLVM as a library. There's nothing
wrong with this approach and in fact some industrial strength compilers
do exactly this (the Glasgow Haskell Compiler is one notable example).

Finally, don't feel discouraged; just start with the basics. Get "Hello
World" working with LLVM IR hand-crafted in a text editor and move on
From there. Make sure you keep an eye on the code LLVM produces and
understand why it's doing what it is doing. Modern compilers are very
complex beasts but building up like this you'll get it eventually.

Good luck!

- Ben

Dear Logan,

I went back into my Inbox to find your messages. So far, I've only found one. If I understand it correctly, it asks about getting the Ocaml interface to LLVM working again.

Sadly, I don't use OCaml, and so I can't help you. I would also hazard a guess that the OCaml interface to LLVM may have bit rotted because no one is using it. That would explain why no one has, so far, answered your question (because they don't know the answer).

If you want to use OCaml, I would suggest using an earlier version of LLVM in which the OCaml support worked. There was a project at UPenn that developed semantics for LLVM using Coq/OCaml; you might try to use Google to find that project to see which version of LLVM they used. The paper (which probably lists the version of LLVM that they used) is here: http://www.cs.rutgers.edu/~santosh.nagarakatte/pldi2013.pdf.

Alternatively, you could write the parts of your language that interface with LLVM in C or C++ and write the parts of your language that deal with human-language in OCaml and write your own interface between the two components. This would probably be the best solution in the long-term as C and C++ are the "native" interface for interacting with the LLVM IR.

Finally, please try not to take it personally when your question goes unanswered. While the LLVM community tries to help newcomers, that help is on a volunteer basis, which means that sometimes questions go unanswered because a) people don't know the answer; or b) people don't have time. Questions also go unanswered because they don't provide enough details or are too open-ended

Regards and good luck,

John Criswell

There's no such thing as a stupid question. And you'll get no such
treatment from this crowd, I can assure you. As John said, if no one
replied is probably because no one really knows the answer!

John's proposal is probably the best to find your way around, and once
it's working, feel free to upgrade it to work on modern LLVM and
submit your patches.

cheers,
--renato

>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?

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of Logan Streondj
Subject: Re: [LLVMdev] HELP! PLEASE!

> 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);

You didn't actually try what was suggested. Do this:

        raw_fd_ostream ros("-", errorOut);
        module->print(ros, NULL);

You may need to brush up on C/C++ basics...

- Chuck