#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCWin64EH.h"
#include "llvm/Support/ErrorHandling.h"
}
void MCStreamer::reset() {
+ DwarfFrameInfos.clear();
for (unsigned i = 0; i < getNumWinFrameInfos(); ++i)
delete WinFrameInfos[i];
WinFrameInfos.clear();
CurrentWinFrameInfo = nullptr;
+ SymbolOrdering.clear();
SectionStack.clear();
SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
}
-static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
- MCContext &Context = OS.getContext();
- assert(!isa<MCSymbolRefExpr>(Expr));
- if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
- return Expr;
-
- MCSymbol *ABS = Context.CreateTempSymbol();
- OS.EmitAssignment(ABS, Expr);
- return MCSymbolRefExpr::Create(ABS, Context);
-}
-
raw_ostream &MCStreamer::GetCommentOS() {
// By default, discard comments.
return nulls();
/// EmitIntValue - Special case of EmitValue that avoids the client having to
/// pass in a MCExpr for constant integers.
void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
- assert(Size <= 8 && "Invalid size");
+ assert(1 <= Size && Size <= 8 && "Invalid size");
assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
"Invalid size");
char buf[8];
EmitBytes(OSE.str());
}
-void MCStreamer::EmitAbsValue(const MCExpr *Value, unsigned Size) {
- const MCExpr *ABS = forceExpAbs(*this, Value);
- EmitValue(ABS, Size);
-}
-
-
void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
const SMLoc &Loc) {
EmitValueImpl(Value, Size, Loc);
MCSymbol *EHSymbol) {
}
-void MCStreamer::InitSections() {
+void MCStreamer::InitSections(bool NoExecStack) {
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
}
Frame.IsSimple = IsSimple;
EmitCFIStartProcImpl(Frame);
+ const MCAsmInfo* MAI = Context.getAsmInfo();
+ if (MAI) {
+ for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
+ if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
+ Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
+ Frame.CurrentCfaRegister = Inst.getRegister();
+ }
+ }
+ }
+
DwarfFrameInfos.push_back(Frame);
}
MCCFIInstruction::createDefCfa(Label, Register, Offset);
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
CurFrame->Instructions.push_back(Instruction);
+ CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
}
void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
MCCFIInstruction::createDefCfaRegister(Label, Register);
MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
CurFrame->Instructions.push_back(Instruction);
+ CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
}
void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
void MCStreamer::EmitBundleLock(bool AlignToEnd) {}
void MCStreamer::FinishImpl() {}
void MCStreamer::EmitBundleUnlock() {}
+
+void MCStreamer::SwitchSection(const MCSection *Section,
+ const MCExpr *Subsection) {
+ assert(Section && "Cannot switch to a null section!");
+ MCSectionSubPair curSection = SectionStack.back().first;
+ SectionStack.back().second = curSection;
+ if (MCSectionSubPair(Section, Subsection) != curSection) {
+ SectionStack.back().first = MCSectionSubPair(Section, Subsection);
+ assert(!Section->hasEnded() && "Section already ended");
+ ChangeSection(Section, Subsection);
+ MCSymbol *Sym = Section->getBeginSymbol();
+ if (Sym && !Sym->isInSection())
+ EmitLabel(Sym);
+ }
+}
+
+MCSymbol *MCStreamer::endSection(const MCSection *Section) {
+ // TODO: keep track of the last subsection so that this symbol appears in the
+ // correct place.
+ MCSymbol *Sym = Section->getEndSymbol(Context);
+ if (Sym->isInSection())
+ return Sym;
+
+ SwitchSection(Section);
+ EmitLabel(Sym);
+ return Sym;
+}