Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 1 | //===-- lib/CodeGen/ELFCodeEmitter.h ----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef ELFCODEEMITTER_H |
| 11 | #define ELFCODEEMITTER_H |
| 12 | |
| 13 | #include "ELFWriter.h" |
| 14 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace llvm { |
| 18 | |
| 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 { |
| 22 | ELFWriter &EW; |
Bruno Cardoso Lopes | a029a27 | 2009-06-07 21:22:38 +0000 | [diff] [blame^] | 23 | |
| 24 | /// Target machine description |
Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 25 | TargetMachine &TM; |
Bruno Cardoso Lopes | a029a27 | 2009-06-07 21:22:38 +0000 | [diff] [blame^] | 26 | |
| 27 | /// Section containing code for functions |
| 28 | ELFSection *ES; |
| 29 | |
| 30 | /// Relocations - These are the relocations that the function needs, as |
| 31 | /// emitted. |
| 32 | std::vector<MachineRelocation> Relocations; |
| 33 | |
| 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; |
| 38 | |
| 39 | /// FnStartPtr - Pointer to the start location of the current function |
| 40 | /// in the buffer |
Bruno Cardoso Lopes | 5d41910 | 2009-06-05 00:22:10 +0000 | [diff] [blame] | 41 | uint8_t *FnStartPtr; |
Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 42 | public: |
Bruno Cardoso Lopes | 5d41910 | 2009-06-05 00:22:10 +0000 | [diff] [blame] | 43 | explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM) {} |
Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 44 | |
| 45 | void startFunction(MachineFunction &F); |
| 46 | bool finishFunction(MachineFunction &F); |
| 47 | |
| 48 | void addRelocation(const MachineRelocation &MR) { |
Bruno Cardoso Lopes | a029a27 | 2009-06-07 21:22:38 +0000 | [diff] [blame^] | 49 | Relocations.push_back(MR); |
Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) { |
Bruno Cardoso Lopes | a029a27 | 2009-06-07 21:22:38 +0000 | [diff] [blame^] | 53 | if (MBBLocations.size() <= (unsigned)MBB->getNumber()) |
| 54 | MBBLocations.resize((MBB->getNumber()+1)*2); |
| 55 | MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); |
| 56 | } |
| 57 | |
| 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()]; |
Bruno Cardoso Lopes | 4cb3143 | 2009-06-03 17:47:27 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const { |
| 65 | assert(0 && "CP not implementated yet!"); |
| 66 | return 0; |
| 67 | } |
| 68 | virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const { |
| 69 | assert(0 && "JT not implementated yet!"); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const { |
| 74 | assert(0 && "JT not implementated yet!"); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | virtual uintptr_t getLabelAddress(uint64_t Label) const { |
| 79 | assert(0 && "Label address not implementated yet!"); |
| 80 | abort(); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | virtual void emitLabel(uint64_t LabelID) { |
| 85 | assert(0 && "emit Label not implementated yet!"); |
| 86 | abort(); |
| 87 | } |
| 88 | |
| 89 | virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { } |
| 90 | |
| 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!"); |
| 95 | abort(); |
| 96 | } |
| 97 | void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) { |
| 98 | assert(0 && "JIT specific function called!"); |
| 99 | abort(); |
| 100 | } |
| 101 | void *finishGVStub(const GlobalValue *F) { |
| 102 | assert(0 && "JIT specific function called!"); |
| 103 | abort(); |
| 104 | return 0; |
| 105 | } |
| 106 | }; // end class ELFCodeEmitter |
| 107 | |
| 108 | } // end namespace llvm |
| 109 | |
| 110 | #endif |
| 111 | |