1 //===-- lib/CodeGen/ELFCodeEmitter.h ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef ELFCODEEMITTER_H
11 #define ELFCODEEMITTER_H
13 #include "llvm/CodeGen/MachineCodeEmitter.h"
20 /// ELFCodeEmitter - This class is used by the ELFWriter to
21 /// emit the code for functions to the ELF file.
22 class ELFCodeEmitter : public MachineCodeEmitter {
25 /// Target machine description
28 /// Section containing code for functions
31 /// Relocations - These are the relocations that the function needs, as
33 std::vector<MachineRelocation> Relocations;
35 /// CPLocations - This is a map of constant pool indices to offsets from the
36 /// start of the section for that constant pool index.
37 std::vector<uintptr_t> CPLocations;
39 /// CPSections - This is a map of constant pool indices to the MachOSection
40 /// containing the constant pool entry for that index.
41 std::vector<unsigned> CPSections;
43 /// JTLocations - This is a map of jump table indices to offsets from the
44 /// start of the section for that jump table index.
45 std::vector<uintptr_t> JTLocations;
47 /// MBBLocations - This vector is a mapping from MBB ID's to their address.
48 /// It is filled in by the StartMachineBasicBlock callback and queried by
49 /// the getMachineBasicBlockAddress callback.
50 std::vector<uintptr_t> MBBLocations;
52 /// FnStartPtr - Pointer to the start location of the current function
56 /// JumpTableSectionIdx - Holds the index of the Jump Table Section
57 unsigned JumpTableSectionIdx;
59 explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM),
60 JumpTableSectionIdx(0) {}
62 void startFunction(MachineFunction &F);
63 bool finishFunction(MachineFunction &F);
65 void addRelocation(const MachineRelocation &MR) {
66 Relocations.push_back(MR);
69 virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
70 if (MBBLocations.size() <= (unsigned)MBB->getNumber())
71 MBBLocations.resize((MBB->getNumber()+1)*2);
72 MBBLocations[MBB->getNumber()] = getCurrentPCOffset();
75 virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
76 assert(CPLocations.size() > Index && "CP not emitted!");
77 return CPLocations[Index];
80 virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const {
81 assert(JTLocations.size() > Index && "JT not emitted!");
82 return JTLocations[Index];
85 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
86 assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
87 MBBLocations[MBB->getNumber()] && "MBB not emitted!");
88 return MBBLocations[MBB->getNumber()];
91 virtual uintptr_t getLabelAddress(uint64_t Label) const {
92 assert(0 && "Label address not implementated yet!");
97 virtual void emitLabel(uint64_t LabelID) {
98 assert(0 && "emit Label not implementated yet!");
102 /// emitConstantPool - For each constant pool entry, figure out which section
103 /// the constant should live in and emit the constant.
104 void emitConstantPool(MachineConstantPool *MCP);
106 /// emitJumpTables - Emit all the jump tables for a given jump table info
107 /// record to the appropriate section.
108 void emitJumpTables(MachineJumpTableInfo *MJTI);
110 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) {}
112 /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
113 void startGVStub(const GlobalValue* F, unsigned StubSize,
114 unsigned Alignment = 1) {
115 assert(0 && "JIT specific function called!");
118 void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) {
119 assert(0 && "JIT specific function called!");
122 void *finishGVStub(const GlobalValue *F) {
123 assert(0 && "JIT specific function called!");
127 }; // end class ELFCodeEmitter
129 } // end namespace llvm