Get LLVM assembler for a function.

We can get the llvm assembler for a Module with something as simple as

      std::ofstream f("code.llvm");
      f << *M;

Is there a method for obtaining the llvm assembler of a given Function?

I think something like "F->print(f);" will do the right thing.

-Eli

Hello Eli.

Eli Friedman <eli.friedman@gmail.com> writes:

Is there a method for obtaining the llvm assembler of a given Function?

I think something like "F->print(f);" will do the right thing.

Nope. It prints nothing at all.

      mainF->print(std::cout);

I've been using F.dump().

-Jim

Óscar Fuentes <ofv@wanadoo.es> writes:

Is there a method for obtaining the llvm assembler of a given Function?

I think something like "F->print(f);" will do the right thing.

Nope. It prints nothing at all.

      mainF->print(std::cout);

Thanks Eli and Jim.

Both methods work. My compiler was using a different backend and thus
ignoring the llvm part.

Eli Friedman <eli.friedman@gmail.com> writes:

I think something like "F->print(f);" will do the right thing.

BTW, what's the reason for `print' and `dump' not being listed on the
doxygen page of Function?

Probably that they're inherited from Value.

-Eli

Eli Friedman <eli.friedman@gmail.com> writes:

BTW, what's the reason for `print' and `dump' not being listed on the
doxygen page of Function?

Probably that they're inherited from Value.

So if we want to know the interface of a class we must navigate through
all its parents?

Now I know why I feel so confused while reading doxygen docs :slight_smile:

In addition to the other answers, f << *F works too.

Dan

Hello Dan.

Dan Gohman <gohman@apple.com> writes:

Is there a method for obtaining the llvm assembler of a given
Function?

In addition to the other answers, f << *F works too.

From that code, I expected to see the declaration of the function. So

checked and it prints the declaration if the function is empty (no
instructions added yet) and the disassembly if it has instructions. That
makes sense, but sometimes it is useful to output just the declaration. I
guess there is a method for that somewhere. In the meantime, outputting
the function's type and name can do the job.