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 "ELFWriter.h"
14 #include "llvm/CodeGen/MachineCodeEmitter.h"
19 /// ELFCodeEmitter - This class is used by the ELFWriter to
20 /// emit the code for functions to the ELF file.
21 class ELFCodeEmitter : public MachineCodeEmitter {
24 /// Target machine description
27 /// Section containing code for functions
30 /// Relocations - These are the relocations that the function needs, as
32 std::vector<MachineRelocation> Relocations;
34 /// CPLocations - This is a map of constant pool indices to offsets from the
35 /// start of the section for that constant pool index.
36 std::vector<uintptr_t> CPLocations;
38 /// CPSections - This is a map of constant pool indices to the MachOSection
39 /// containing the constant pool entry for that index.
40 std::vector<unsigned> CPSections;
42 /// MBBLocations - This vector is a mapping from MBB ID's to their address.
43 /// It is filled in by the StartMachineBasicBlock callback and queried by
44 /// the getMachineBasicBlockAddress callback.
45 std::vector<uintptr_t> MBBLocations;
47 /// FnStartPtr - Pointer to the start location of the current function
51 explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM) {}
53 void startFunction(MachineFunction &F);
54 bool finishFunction(MachineFunction &F);
56 void addRelocation(const MachineRelocation &MR) {
57 Relocations.push_back(MR);
60 virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
61 if (MBBLocations.size() <= (unsigned)MBB->getNumber())
62 MBBLocations.resize((MBB->getNumber()+1)*2);
63 MBBLocations[MBB->getNumber()] = getCurrentPCOffset();
66 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) {
67 assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
68 MBBLocations[MBB->getNumber()] && "MBB not emitted!");
69 return MBBLocations[MBB->getNumber()];
72 virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
73 assert(CPLocations.size() > Index && "CP not emitted!");
74 return CPLocations[Index];
77 virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const {
78 assert(0 && "JT not implementated yet!");
82 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
83 assert(0 && "JT not implementated yet!");
87 virtual uintptr_t getLabelAddress(uint64_t Label) const {
88 assert(0 && "Label address not implementated yet!");
93 virtual void emitLabel(uint64_t LabelID) {
94 assert(0 && "emit Label not implementated yet!");
98 /// emitConstantPool - For each constant pool entry, figure out which section
99 /// the constant should live in and emit the constant.
100 void emitConstantPool(MachineConstantPool *MCP);
102 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
104 /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
105 void startGVStub(const GlobalValue* F, unsigned StubSize,
106 unsigned Alignment = 1) {
107 assert(0 && "JIT specific function called!");
110 void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) {
111 assert(0 && "JIT specific function called!");
114 void *finishGVStub(const GlobalValue *F) {
115 assert(0 && "JIT specific function called!");
119 }; // end class ELFCodeEmitter
121 } // end namespace llvm