#include "llvm/Target/TargetAsmInfo.h"
namespace llvm {
+ class MCContext;
/// SectionKind - This is a simple POD value that classifies the properties of
/// a section. A global variable is classified into the deepest possible
virtual ~TargetLoweringObjectFile();
+ /// Initialize - this method must be called before any actual lowering is
+ /// done. This specifies the current context for codegen, and gives the
+ /// lowering implementations a chance to set up their default sections.
+ virtual void Initialize(MCContext &Ctx, const TargetMachine &TM) {}
+
+
const Section *getTextSection() const { return TextSection; }
const Section *getDataSection() const { return DataSection; }
class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
bool AtIsCommentChar; // True if @ is the comment character on this target.
+ bool HasCrazyBSS;
public:
/// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
/// is "@".
- TargetLoweringObjectFileELF(bool AtIsCommentChar = false,
+ TargetLoweringObjectFileELF(bool atIsCommentChar = false,
// FIXME: REMOVE AFTER UNIQUING IS FIXED.
- bool HasCrazyBSS = false);
+ bool hasCrazyBSS = false)
+ : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
+
+ virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
+
/// getSectionForMergeableConstant - Given a mergeable constant with the
/// specified size and relocation information, return a section that it
const Section *MergeableConst16Section;
};
+
+
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
const Section *TextCoalSection;
const Section *ConstTextCoalSection;
const Section *EightByteConstantSection;
const Section *SixteenByteConstantSection;
public:
- TargetLoweringObjectFileMachO(const TargetMachine &TM);
+
+ virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
+
virtual const Section *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
public:
- TargetLoweringObjectFileCOFF();
+ virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
+
virtual void getSectionFlagsAsString(SectionKind Kind,
SmallVectorImpl<char> &Str) const;
}
bool AsmPrinter::doInitialization(Module &M) {
+ // Initialize TargetLoweringObjectFile.
+ const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
+ .Initialize(OutContext, TM);
+
Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix(),
TAI->getLinkerPrivateGlobalPrefix());
#include "llvm/CodeGen/ObjectCodeEmitter.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetELFWriterInfo.h"
ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm)
: MachineFunctionPass(&ID), O(o), TM(tm),
+ OutContext(*new MCContext()),
is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64),
isLittleEndian(TM.getTargetData()->isLittleEndian()),
ElfHdr(isLittleEndian, is64Bit) {
ELFWriter::~ELFWriter() {
delete ElfCE;
+ delete &OutContext;
}
// doInitialization - Emit the file header and all of the global variables for
// the module to the ELF file.
bool ELFWriter::doInitialization(Module &M) {
+ // Initialize TargetLoweringObjectFile.
+ const TargetLoweringObjectFile &TLOF =
+ TM.getTargetLowering()->getObjFileLowering();
+ const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(OutContext, TM);
+
Mang = new Mangler(M);
// ELF Header
class TargetELFWriterInfo;
class raw_ostream;
class SectionKind;
+ class MCContext;
typedef std::vector<ELFSym*>::iterator ELFSymIter;
typedef std::vector<ELFSection*>::iterator ELFSectionIter;
/// Target machine description.
TargetMachine &TM;
+ MCContext &OutContext;
+
/// Target Elf Writer description.
const TargetELFWriterInfo *TEW;
static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) {
if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin())
- return new TargetLoweringObjectFileMachO(TM);
+ return new TargetLoweringObjectFileMachO();
return new TargetLoweringObjectFileELF(true);
}
static TargetLoweringObjectFile *CreateTLOF(const PPCTargetMachine &TM) {
if (TM.getSubtargetImpl()->isDarwin())
- return new TargetLoweringObjectFileMachO(TM);
+ return new TargetLoweringObjectFileMachO();
return new TargetLoweringObjectFileELF(false, true);
}
// ELF
//===----------------------------------------------------------------------===//
-TargetLoweringObjectFileELF::TargetLoweringObjectFileELF(bool atIsCommentChar,
- bool HasCrazyBSS)
- : AtIsCommentChar(atIsCommentChar) {
-
+void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
+ const TargetMachine &TM) {
if (!HasCrazyBSS)
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
else
// MachO
//===----------------------------------------------------------------------===//
-TargetLoweringObjectFileMachO::
-TargetLoweringObjectFileMachO(const TargetMachine &TM) {
+void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
+ const TargetMachine &TM) {
TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
// COFF
//===----------------------------------------------------------------------===//
-TargetLoweringObjectFileCOFF::TargetLoweringObjectFileCOFF() {
+void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
+ const TargetMachine &TM) {
TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
}
switch (TM.getSubtarget<X86Subtarget>().TargetType) {
default: llvm_unreachable("unknown subtarget type");
case X86Subtarget::isDarwin:
- return new TargetLoweringObjectFileMachO(TM);
+ return new TargetLoweringObjectFileMachO();
case X86Subtarget::isELF:
return new TargetLoweringObjectFileELF();
case X86Subtarget::isMingw: