[LLVMdev] MC ELFObjectWriter backend refactoring

Wesley Peck peckw at wesleypeck.com
Thu Nov 18 08:40:40 PST 2010


I have been working on getting ELF object file writing working for the MBlaze backend. Currently, each supported backend calls ELFObjectWriter::createELFObjectWriter from within the backend's TargetAsmBackend::createObjectWriter method. The createELFObjectWriter method then creates a new backend specific ELFObjectWriter class (either X86ELFObjectWriter or ARMELFObjectWriter) by decoding a given machine type.

The attached patch does some code refactoring so that a backend can create it's own ELFObjectWriter class and instantiate this class directly in TargetAsmBackend::createObjectWriter. This allows backend specific stuff in lib/MC/ELFObjectWriter.cpp to be moved to the backend's directory.

There are obviously several things that could be done differently:
1. The backend specific ELFObjectWriter classes are declared and implemented in X86AsmBackend.cpp and ARMAsmBackend.cpp; it may be better to put these classes in their own files.

2. The ELFObjectWriter base class is declared in llvm/MC/MCObjectWriter.h; it may be better to put this declaration in its own header file.

3. Some of the flags, such as Is64Bit and EMachine, could be virtual methods instead of values passed to the base ELFObjectWriter class.

4. Refactoring of MachObjectWriter and WinCOFFObjectWriter could be done as well.

5. I could just add the MBlaze backend specific stuff into ELFObjectWriter like all of the other backends.

Are their any other opinions on this? I personally prefer all of the MBlaze backend stuff to be contained inside of lib/Target/MBlaze so that I don't have to hunt around the LLVM source tree when I'm implementing/fixing the MBlaze backend. If #5 is preferred instead, then I can re-implement the MBlaze ELF stuff that way instead.

--
Wesley Peck
University of Kansas
SLDG Laboratory


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101118/21ad2bf5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mcelf.patch
Type: application/octet-stream
Size: 45644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101118/21ad2bf5/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101118/21ad2bf5/attachment-0001.html>


More information about the llvm-dev mailing list