[LLVMdev] Re: Directly generating binary file

Vladimir Prus ghost at cs.msu.su
Mon Feb 27 23:07:19 PST 2006


Chris Lattner wrote:

>> The TargetMachine class has a method 'addPassesToEmitMachineCode', that's
>> suitable for that, but that method also requires an instance of
>> MachineCodeEmitter.
> 
> Actually, you probably want to plug into the addPassesToEmitFile API, when
> FileType is set to ObjectFile.  X86TargetMachine::addPassesToEmitFile
> demonstrates how to do this.

Ok. Note, however, that online HTML docs for "llc", as well as "llc.pod" in
the current CVS don't mention the "filetype" option that is used to control
file format. 

And, should 'addPassesToEmitMachineCode' method be declared deprecated?

>> Any suggestions how I should proceed?
> 
> I'd suggest following the pattern of the ElfWriter.  Basically, the elf
> writer knows about the object file format (ELF in this case, obviously)
> but doesn't know anything specific about the target.  The target handles
> translation of MachineInstr's to relocatable machine code and relocations,
> sending the result to the MachineCodeEmitter.  You can then format it
> according to the requirements of the object file format.
> 
> Alternatively, you could side step all of this and write your own .o file
> writer that doesn't use the MachineCodeEmitter interfaces at all.  If this
> is easiest, go for it.

So far this looks the simplest approach. Especially sincelooking at
ELFCodeEmitter, I see quite a bunch of unimplemented methods.

> Note that *some* assembler format is useful for debugging, writting
> regression tests, etc.

Sure, I plan to have some format that will be output by disassembler, but
don't plan to ever read that format ;-)

- Volodya






More information about the llvm-dev mailing list