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 /// MBBLocations - This vector is a mapping from MBB ID's to their address.
35 /// It is filled in by the StartMachineBasicBlock callback and queried by
36 /// the getMachineBasicBlockAddress callback.
37 std::vector<uintptr_t> MBBLocations;
39 /// FnStartPtr - Pointer to the start location of the current function
43 explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM) {}
45 void startFunction(MachineFunction &F);
46 bool finishFunction(MachineFunction &F);
48 void addRelocation(const MachineRelocation &MR) {
49 Relocations.push_back(MR);
52 virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
53 if (MBBLocations.size() <= (unsigned)MBB->getNumber())
54 MBBLocations.resize((MBB->getNumber()+1)*2);
55 MBBLocations[MBB->getNumber()] = getCurrentPCOffset();
58 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) {
59 assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
60 MBBLocations[MBB->getNumber()] && "MBB not emitted!");
61 return MBBLocations[MBB->getNumber()];
64 virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
65 assert(0 && "CP not implementated yet!");
68 virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const {
69 assert(0 && "JT not implementated yet!");
73 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
74 assert(0 && "JT not implementated yet!");
78 virtual uintptr_t getLabelAddress(uint64_t Label) const {
79 assert(0 && "Label address not implementated yet!");
84 virtual void emitLabel(uint64_t LabelID) {
85 assert(0 && "emit Label not implementated yet!");
89 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
91 /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
92 void startGVStub(const GlobalValue* F, unsigned StubSize,
93 unsigned Alignment = 1) {
94 assert(0 && "JIT specific function called!");
97 void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) {
98 assert(0 && "JIT specific function called!");
101 void *finishGVStub(const GlobalValue *F) {
102 assert(0 && "JIT specific function called!");
106 }; // end class ELFCodeEmitter
108 } // end namespace llvm