36 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
37 void addDirectiveHandler(
StringRef Directive) {
39 this, HandleDirective<COFFAsmParser, HandlerMethod>);
40 getParser().addDirectiveHandler(Directive, Handler);
59 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(
".text");
60 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(
".data");
61 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(
".bss");
62 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(
".section");
63 addDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(
".def");
64 addDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(
".scl");
65 addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(
".type");
66 addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(
".endef");
67 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(
".secrel32");
68 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(
".secidx");
69 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSafeSEH>(
".safeseh");
70 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(
".linkonce");
73 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
75 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
77 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
79 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
81 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
83 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
85 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushReg>(
87 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSetFrame>(
89 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
91 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveReg>(
93 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveXMM>(
95 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushFrame>(
97 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
99 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
103 return ParseSectionSwitch(
".text",
118 return ParseSectionSwitch(
".bss",
151 bool ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
152 bool ParseSEHRegisterNumber(
unsigned &RegNo);
156 COFFAsmParser() =
default;
182 Discardable = 1 << 8,
185 bool ReadOnlyRemoved =
false;
186 unsigned SecFlags =
None;
188 for (
char FlagChar : FlagsString) {
196 if (SecFlags & InitData)
197 return TokError(
"conflicting section flags 'b' and 'd'.");
202 SecFlags |= InitData;
203 if (SecFlags &
Alloc)
204 return TokError(
"conflicting section flags 'b' and 'd'.");
205 SecFlags &= ~NoWrite;
206 if ((SecFlags & NoLoad) == 0)
216 SecFlags |= Discardable;
220 ReadOnlyRemoved =
false;
222 if ((SecFlags & Code) == 0)
223 SecFlags |= InitData;
224 if ((SecFlags & NoLoad) == 0)
229 SecFlags |= Shared | InitData;
230 SecFlags &= ~NoWrite;
231 if ((SecFlags & NoLoad) == 0)
236 SecFlags &= ~NoWrite;
237 ReadOnlyRemoved =
true;
242 if ((SecFlags & NoLoad) == 0)
244 if (!ReadOnlyRemoved)
249 SecFlags |= NoRead | NoWrite;
253 return TokError(
"unknown flag");
259 if (SecFlags ==
None)
264 if (SecFlags & InitData)
266 if ((SecFlags & Alloc) && (SecFlags &
Load) == 0)
268 if (SecFlags & NoLoad)
270 if ((SecFlags & Discardable) ||
273 if ((SecFlags & NoRead) == 0)
275 if ((SecFlags & NoWrite) == 0)
277 if (SecFlags & Shared)
285 bool COFFAsmParser::ParseDirectiveSymbolAttribute(
StringRef Directive,
SMLoc) {
294 if (getParser().parseIdentifier(Name))
295 return TokError(
"expected identifier in directive");
297 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
299 getStreamer().EmitSymbolAttribute(Sym, Attr);
305 return TokError(
"unexpected token in directive");
317 return ParseSectionSwitch(Section, Characteristics, Kind,
"", (
COFF::COMDATType)0);
320 bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
321 unsigned Characteristics,
326 return TokError(
"unexpected token in section switching directive");
329 getStreamer().SwitchSection(getContext().getCOFFSection(
330 Section, Characteristics, Kind, COMDATSymName, Type));
335 bool COFFAsmParser::ParseSectionName(
StringRef &SectionName) {
339 SectionName = getTok().getIdentifier();
362 if (ParseSectionName(SectionName))
363 return TokError(
"expected identifier in directive");
373 return TokError(
"expected string in directive");
375 StringRef FlagsStr = getTok().getStringContents();
378 if (ParseSectionFlags(SectionName, FlagsStr, &Flags))
391 return TokError(
"expected comdat type such as 'discard' or 'largest' "
392 "after protection bits");
394 if (parseCOMDATType(Type))
398 return TokError(
"expected comma in directive");
401 if (getParser().parseIdentifier(COMDATSymName))
402 return TokError(
"expected identifier in directive");
406 return TokError(
"unexpected token in directive");
410 const Triple &
T = getContext().getObjectFileInfo()->getTargetTriple();
414 ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
421 if (getParser().parseIdentifier(SymbolName))
422 return TokError(
"expected identifier in directive");
424 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
426 getStreamer().BeginCOFFSymbolDef(Sym);
434 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
438 return TokError(
"unexpected token in directive");
441 getStreamer().EmitCOFFSymbolStorageClass(SymbolStorageClass);
447 if (getParser().parseAbsoluteExpression(Type))
451 return TokError(
"unexpected token in directive");
454 getStreamer().EmitCOFFSymbolType(Type);
460 getStreamer().EndCOFFSymbolDef();
466 if (getParser().parseIdentifier(SymbolID))
467 return TokError(
"expected identifier in directive");
472 OffsetLoc = getLexer().getLoc();
473 if (getParser().parseAbsoluteExpression(Offset))
478 return TokError(
"unexpected token in directive");
483 "invalid '.secrel32' directive offset, can't be less "
484 "than zero or greater than std::numeric_limits<uint32_t>::max()");
489 getStreamer().EmitCOFFSecRel32(Symbol, Offset);
495 if (getParser().parseIdentifier(SymbolID))
496 return TokError(
"expected identifier in directive");
499 return TokError(
"unexpected token in directive");
501 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
504 getStreamer().EmitCOFFSafeSEH(Symbol);
510 if (getParser().parseIdentifier(SymbolID))
511 return TokError(
"expected identifier in directive");
514 return TokError(
"unexpected token in directive");
516 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
519 getStreamer().EmitCOFFSectionIndex(Symbol);
525 StringRef TypeId = getTok().getIdentifier();
538 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
547 bool COFFAsmParser::ParseDirectiveLinkOnce(
StringRef,
SMLoc Loc) {
550 if (parseCOMDATType(Type))
554 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
557 return Error(Loc,
"cannot make section associative with .linkonce");
561 "' is already linkonce");
566 return TokError(
"unexpected token in directive");
571 bool COFFAsmParser::ParseSEHDirectiveStartProc(
StringRef,
SMLoc) {
573 if (getParser().parseIdentifier(SymbolID))
577 return TokError(
"unexpected token in directive");
579 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
582 getStreamer().EmitWinCFIStartProc(Symbol);
588 getStreamer().EmitWinCFIEndProc();
592 bool COFFAsmParser::ParseSEHDirectiveStartChained(
StringRef,
SMLoc) {
594 getStreamer().EmitWinCFIStartChained();
598 bool COFFAsmParser::ParseSEHDirectiveEndChained(
StringRef,
SMLoc) {
600 getStreamer().EmitWinCFIEndChained();
606 if (getParser().parseIdentifier(SymbolID))
610 return TokError(
"you must specify one or both of @unwind or @except");
612 bool unwind =
false, except =
false;
613 if (ParseAtUnwindOrAtExcept(unwind, except))
617 if (ParseAtUnwindOrAtExcept(unwind, except))
621 return TokError(
"unexpected token in directive");
623 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
626 getStreamer().EmitWinEHHandler(handler, unwind, except);
630 bool COFFAsmParser::ParseSEHDirectiveHandlerData(
StringRef,
SMLoc) {
632 getStreamer().EmitWinEHHandlerData();
638 if (ParseSEHRegisterNumber(Reg))
642 return TokError(
"unexpected token in directive");
645 getStreamer().EmitWinCFIPushReg(Reg);
649 bool COFFAsmParser::ParseSEHDirectiveSetFrame(
StringRef,
SMLoc L) {
652 if (ParseSEHRegisterNumber(Reg))
655 return TokError(
"you must specify a stack pointer offset");
658 SMLoc startLoc = getLexer().getLoc();
659 if (getParser().parseAbsoluteExpression(Off))
663 return Error(startLoc,
"offset is not a multiple of 16");
666 return TokError(
"unexpected token in directive");
669 getStreamer().EmitWinCFISetFrame(Reg, Off);
673 bool COFFAsmParser::ParseSEHDirectiveAllocStack(
StringRef,
SMLoc) {
675 SMLoc startLoc = getLexer().getLoc();
676 if (getParser().parseAbsoluteExpression(Size))
680 return Error(startLoc,
"size is not a multiple of 8");
683 return TokError(
"unexpected token in directive");
686 getStreamer().EmitWinCFIAllocStack(Size);
690 bool COFFAsmParser::ParseSEHDirectiveSaveReg(
StringRef,
SMLoc L) {
693 if (ParseSEHRegisterNumber(Reg))
696 return TokError(
"you must specify an offset on the stack");
699 SMLoc startLoc = getLexer().getLoc();
700 if (getParser().parseAbsoluteExpression(Off))
704 return Error(startLoc,
"size is not a multiple of 8");
707 return TokError(
"unexpected token in directive");
711 getStreamer().EmitWinCFISaveReg(Reg, Off);
717 bool COFFAsmParser::ParseSEHDirectiveSaveXMM(
StringRef,
SMLoc L) {
720 if (ParseSEHRegisterNumber(Reg))
723 return TokError(
"you must specify an offset on the stack");
726 SMLoc startLoc = getLexer().getLoc();
727 if (getParser().parseAbsoluteExpression(Off))
731 return TokError(
"unexpected token in directive");
734 return Error(startLoc,
"offset is not a multiple of 16");
738 getStreamer().EmitWinCFISaveXMM(Reg, Off);
742 bool COFFAsmParser::ParseSEHDirectivePushFrame(
StringRef,
SMLoc) {
746 SMLoc startLoc = getLexer().getLoc();
748 if (!getParser().parseIdentifier(CodeID)) {
749 if (CodeID !=
"code")
750 return Error(startLoc,
"expected @code");
756 return TokError(
"unexpected token in directive");
759 getStreamer().EmitWinCFIPushFrame(Code);
763 bool COFFAsmParser::ParseSEHDirectiveEndProlog(
StringRef,
SMLoc) {
765 getStreamer().EmitWinCFIEndProlog();
769 bool COFFAsmParser::ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
772 return TokError(
"a handler attribute must begin with '@'");
773 SMLoc startLoc = getLexer().getLoc();
775 if (getParser().parseIdentifier(identifier))
776 return Error(startLoc,
"expected @unwind or @except");
777 if (identifier ==
"unwind")
779 else if (identifier ==
"except")
782 return Error(startLoc,
"expected @unwind or @except");
786 bool COFFAsmParser::ParseSEHRegisterNumber(
unsigned &RegNo) {
787 SMLoc startLoc = getLexer().getLoc();
792 if (getParser().getTargetParser().ParseRegister(LLVMRegNo,startLoc,endLoc))
800 const unsigned *NVRegs = TAI.getCalleeSavedRegs();
802 for (i = 0; NVRegs[i] != 0; ++i)
803 if (NVRegs[i] == LLVMRegNo)
806 return Error(startLoc,
"expected non-volatile register");
811 return Error(startLoc,
"register can't be represented in SEH unwind info");
816 if (getParser().parseAbsoluteExpression(n))
819 return Error(startLoc,
"register number is too high");
829 return new COFFAsmParser;
static SectionKind getData()
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
void setSelection(int Selection) const
static SectionKind computeSectionKind(unsigned Flags)
This represents a section on Windows.
static SectionKind getBSS()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Reg
All possible values of the reg field in the ModR/M byte.
int getSEHRegNum(unsigned RegNum) const
Map a target register to an equivalent SEH register number.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
A switch()-like statement whose cases are string literals.
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
SectionKind - This is a simple POD value that classifies the properties of a section.
MCAsmParserExtension * createCOFFAsmParser()
unsigned getCharacteristics() const
Triple - Helper class for working with autoconf configuration names.
StringRef getSectionName() const
SymbolStorageClass
Storage class tells where and what the symbol represents.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static std::vector< std::string > Flags
COFFYAML::WeakExternalCharacteristics Characteristics
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
static SectionKind getReadOnly()
static SectionKind getText()