blob: 2ec1f6e873d6310966791f432e4c0269895763bf [file] [log] [blame]
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +00001//===-- 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
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000013#include "llvm/CodeGen/ObjectCodeEmitter.h"
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000014#include <vector>
15
16namespace llvm {
Bruno Cardoso Lopes45f5d642009-07-02 18:29:24 +000017 class ELFWriter;
18 class ELFSection;
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000019
20 /// ELFCodeEmitter - This class is used by the ELFWriter to
21 /// emit the code for functions to the ELF file.
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000022 class ELFCodeEmitter : public ObjectCodeEmitter {
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000023 ELFWriter &EW;
Bruno Cardoso Lopesa029a272009-06-07 21:22:38 +000024
25 /// Target machine description
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000026 TargetMachine &TM;
Bruno Cardoso Lopesa029a272009-06-07 21:22:38 +000027
28 /// Section containing code for functions
29 ELFSection *ES;
30
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000031 /// Relocations - Record relocations needed by the current function
Bruno Cardoso Lopesa029a272009-06-07 21:22:38 +000032 std::vector<MachineRelocation> Relocations;
33
Bruno Cardoso Lopes82a70cc2009-07-21 23:13:26 +000034 /// JTRelocations - Record relocations needed by the relocation
35 /// section.
36 std::vector<MachineRelocation> JTRelocations;
37
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000038 /// FnStartPtr - Function offset from the beginning of ELFSection 'ES'
39 uintptr_t FnStartOff;
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000040 public:
Bruno Cardoso Lopes82a70cc2009-07-21 23:13:26 +000041 explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM) {}
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000042
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000043 /// addRelocation - Register new relocations for this function
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000044 void addRelocation(const MachineRelocation &MR) {
Bruno Cardoso Lopesa029a272009-06-07 21:22:38 +000045 Relocations.push_back(MR);
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000046 }
47
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000048 /// emitConstantPool - For each constant pool entry, figure out which
49 /// section the constant should live in and emit data to it
Bruno Cardoso Lopesa5e0abd2009-06-25 07:36:24 +000050 void emitConstantPool(MachineConstantPool *MCP);
51
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000052 /// emitJumpTables - Emit all the jump tables for a given jump table
53 /// info and record them to the appropriate section.
Bruno Cardoso Lopes0b1308f2009-07-03 04:36:26 +000054 void emitJumpTables(MachineJumpTableInfo *MJTI);
55
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000056 void startFunction(MachineFunction &F);
57 bool finishFunction(MachineFunction &F);
58
59 /// emitLabel - Emits a label
Chris Lattner16112732010-03-14 01:41:15 +000060 virtual void emitLabel(MCSymbol *Label) {
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000061 assert("emitLabel not implemented");
62 }
63
64 /// getLabelAddress - Return the address of the specified LabelID,
65 /// only usable after the LabelID has been emitted.
Chris Lattner16112732010-03-14 01:41:15 +000066 virtual uintptr_t getLabelAddress(MCSymbol *Label) const {
Bruno Cardoso Lopes6933d3e2009-07-06 09:26:48 +000067 assert("getLabelAddress not implemented");
68 return 0;
69 }
70
Bruno Cardoso Lopes0b1308f2009-07-03 04:36:26 +000071 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) {}
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000072
Bruno Cardoso Lopes4cb31432009-06-03 17:47:27 +000073}; // end class ELFCodeEmitter
74
75} // end namespace llvm
76
77#endif
78