30 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
31 void addDirectiveHandler(StringRef Directive) {
33 this, HandleDirective<COFFAsmParser, HandlerMethod>);
34 getParser().addDirectiveHandler(Directive, Handler);
37 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics);
39 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics,
43 bool parseSectionName(StringRef &SectionName);
46 void Initialize(MCAsmParser &Parser)
override {
50 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveText>(
".text");
51 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveData>(
".data");
52 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveBSS>(
".bss");
53 addDirectiveHandler<&COFFAsmParser::parseDirectiveSection>(
".section");
54 addDirectiveHandler<&COFFAsmParser::parseDirectivePushSection>(
56 addDirectiveHandler<&COFFAsmParser::parseDirectivePopSection>(
58 addDirectiveHandler<&COFFAsmParser::parseDirectiveDef>(
".def");
59 addDirectiveHandler<&COFFAsmParser::parseDirectiveScl>(
".scl");
60 addDirectiveHandler<&COFFAsmParser::parseDirectiveType>(
".type");
61 addDirectiveHandler<&COFFAsmParser::parseDirectiveEndef>(
".endef");
62 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecRel32>(
".secrel32");
63 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymIdx>(
".symidx");
64 addDirectiveHandler<&COFFAsmParser::parseDirectiveSafeSEH>(
".safeseh");
65 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecIdx>(
".secidx");
66 addDirectiveHandler<&COFFAsmParser::parseDirectiveLinkOnce>(
".linkonce");
67 addDirectiveHandler<&COFFAsmParser::parseDirectiveRVA>(
".rva");
68 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
".weak");
69 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
71 addDirectiveHandler<&COFFAsmParser::parseDirectiveCGProfile>(
".cg_profile");
72 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecNum>(
".secnum");
73 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecOffset>(
".secoffset");
76 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartProc>(
78 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProc>(
80 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc>(
82 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveSplitChained>(
84 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandler>(
86 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandlerData>(
88 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveAllocStack>(
90 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProlog>(
92 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveBeginEpilog>(
93 ".seh_startepilogue");
94 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndEpilog>(
96 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindV2Start>(
97 ".seh_unwindv2start");
98 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindVersion>(
99 ".seh_unwindversion");
102 bool parseSectionDirectiveText(StringRef, SMLoc) {
108 bool parseSectionDirectiveData(StringRef, SMLoc) {
114 bool parseSectionDirectiveBSS(StringRef, SMLoc) {
120 bool parseDirectiveSection(StringRef, SMLoc);
121 bool parseSectionArguments(StringRef, SMLoc);
122 bool parseDirectivePushSection(StringRef, SMLoc);
123 bool parseDirectivePopSection(StringRef, SMLoc);
124 bool parseDirectiveDef(StringRef, SMLoc);
125 bool parseDirectiveScl(StringRef, SMLoc);
126 bool parseDirectiveType(StringRef, SMLoc);
127 bool parseDirectiveEndef(StringRef, SMLoc);
128 bool parseDirectiveSecRel32(StringRef, SMLoc);
129 bool parseDirectiveSecIdx(StringRef, SMLoc);
130 bool parseDirectiveSafeSEH(StringRef, SMLoc);
131 bool parseDirectiveSymIdx(StringRef, SMLoc);
133 bool parseDirectiveLinkOnce(StringRef, SMLoc);
134 bool parseDirectiveRVA(StringRef, SMLoc);
135 bool parseDirectiveCGProfile(StringRef, SMLoc);
136 bool parseDirectiveSecNum(StringRef, SMLoc);
137 bool parseDirectiveSecOffset(StringRef, SMLoc);
140 bool parseSEHDirectiveStartProc(StringRef, SMLoc);
141 bool parseSEHDirectiveEndProc(StringRef, SMLoc);
142 bool parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc);
143 bool parseSEHDirectiveSplitChained(StringRef, SMLoc);
144 bool parseSEHDirectiveHandler(StringRef, SMLoc);
145 bool parseSEHDirectiveHandlerData(StringRef, SMLoc);
146 bool parseSEHDirectiveAllocStack(StringRef, SMLoc);
147 bool parseSEHDirectiveEndProlog(StringRef, SMLoc);
148 bool ParseSEHDirectiveBeginEpilog(StringRef, SMLoc);
149 bool ParseSEHDirectiveEndEpilog(StringRef, SMLoc);
150 bool ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc);
151 bool ParseSEHDirectiveUnwindVersion(StringRef, SMLoc);
153 bool parseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
154 bool parseDirectiveSymbolAttribute(StringRef Directive, SMLoc);
157 COFFAsmParser() =
default;
163 StringRef FlagsString,
unsigned *Flags) {
174 Discardable = 1 << 8,
178 bool ReadOnlyRemoved =
false;
179 unsigned SecFlags =
None;
181 for (
char FlagChar : FlagsString) {
189 if (SecFlags & InitData)
190 return TokError(
"conflicting section flags 'b' and 'd'.");
195 SecFlags |= InitData;
196 if (SecFlags &
Alloc)
197 return TokError(
"conflicting section flags 'b' and 'd'.");
198 SecFlags &= ~NoWrite;
199 if ((SecFlags & NoLoad) == 0)
209 SecFlags |= Discardable;
213 ReadOnlyRemoved =
false;
215 if ((SecFlags & Code) == 0)
216 SecFlags |= InitData;
217 if ((SecFlags & NoLoad) == 0)
222 SecFlags |=
Shared | InitData;
223 SecFlags &= ~NoWrite;
224 if ((SecFlags & NoLoad) == 0)
229 SecFlags &= ~NoWrite;
230 ReadOnlyRemoved =
true;
235 if ((SecFlags & NoLoad) == 0)
237 if (!ReadOnlyRemoved)
242 SecFlags |= NoRead | NoWrite;
250 return TokError(
"unknown flag");
256 if (SecFlags ==
None)
261 if (SecFlags & InitData)
263 if ((SecFlags &
Alloc) && (SecFlags & Load) == 0)
265 if (SecFlags & NoLoad)
267 if ((SecFlags & Discardable) ||
270 if ((SecFlags & NoRead) == 0)
272 if ((SecFlags & NoWrite) == 0)
274 if (SecFlags & Shared)
284bool COFFAsmParser::parseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
285 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
295 return TokError(
"expected identifier in directive");
297 getStreamer().emitSymbolAttribute(Sym, Attr);
303 return TokError(
"unexpected token in directive");
312bool COFFAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
316bool COFFAsmParser::parseSectionSwitch(StringRef Section,
317 unsigned Characteristics) {
318 return parseSectionSwitch(Section, Characteristics,
"", (
COFF::COMDATType)0,
322bool COFFAsmParser::parseSectionSwitch(StringRef Section,
323 unsigned Characteristics,
324 StringRef COMDATSymName,
328 return TokError(
"unexpected token in section switching directive");
331 getStreamer().switchSection(
getContext().getCOFFSection(
332 Section, Characteristics, COMDATSymName,
Type, UniqueID));
337bool COFFAsmParser::parseSectionName(StringRef &SectionName) {
346bool COFFAsmParser::parseDirectiveSection(StringRef directive, SMLoc loc) {
347 return parseSectionArguments(directive, loc);
366bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
369 if (parseSectionName(SectionName))
370 return TokError(
"expected identifier in directive");
380 return TokError(
"expected string in directive");
382 StringRef FlagsStr = getTok().getStringContents();
390 StringRef COMDATSymName;
392 getLexer().peekTok().getString() !=
"unique") {
399 return TokError(
"expected comdat type such as 'discard' or 'largest' "
400 "after protection bits");
402 if (parseCOMDATType(
Type))
406 return TokError(
"expected comma in directive");
409 if (getParser().parseIdentifier(COMDATSymName))
410 return TokError(
"expected identifier in directive");
414 if (maybeParseUniqueID(UniqueID))
418 return TokError(
"unexpected token in directive");
425 parseSectionSwitch(SectionName, Flags, COMDATSymName,
Type, UniqueID);
429bool COFFAsmParser::parseDirectivePushSection(StringRef directive, SMLoc loc) {
430 getStreamer().pushSection();
432 if (parseSectionArguments(directive, loc)) {
433 getStreamer().popSection();
440bool COFFAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
441 if (!getStreamer().popSection())
442 return TokError(
".popsection without corresponding .pushsection");
446bool COFFAsmParser::parseDirectiveDef(StringRef, SMLoc) {
450 return TokError(
"expected identifier in directive");
452 getStreamer().beginCOFFSymbolDef(Sym);
458bool COFFAsmParser::parseDirectiveScl(StringRef, SMLoc) {
460 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
464 return TokError(
"unexpected token in directive");
467 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
471bool COFFAsmParser::parseDirectiveType(StringRef, SMLoc) {
473 if (getParser().parseAbsoluteExpression(
Type))
477 return TokError(
"unexpected token in directive");
480 getStreamer().emitCOFFSymbolType(
Type);
484bool COFFAsmParser::parseDirectiveEndef(StringRef, SMLoc) {
486 getStreamer().endCOFFSymbolDef();
490bool COFFAsmParser::parseDirectiveSecRel32(StringRef, SMLoc) {
493 return TokError(
"expected identifier in directive");
498 OffsetLoc = getLexer().getLoc();
499 if (getParser().parseAbsoluteExpression(
Offset))
504 return TokError(
"unexpected token in directive");
509 "invalid '.secrel32' directive offset, can't be less "
510 "than zero or greater than std::numeric_limits<uint32_t>::max()");
513 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
517bool COFFAsmParser::parseDirectiveRVA(StringRef, SMLoc) {
518 auto parseOp = [&]() ->
bool {
521 return TokError(
"expected identifier in directive");
526 OffsetLoc = getLexer().getLoc();
527 if (getParser().parseAbsoluteExpression(
Offset))
531 if (
Offset < std::numeric_limits<int32_t>::min() ||
532 Offset > std::numeric_limits<int32_t>::max())
533 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
534 "than -2147483648 or greater than "
537 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
541 if (getParser().parseMany(parseOp))
542 return addErrorSuffix(
" in directive");
546bool COFFAsmParser::parseDirectiveSafeSEH(StringRef, SMLoc) {
549 return TokError(
"expected identifier in directive");
552 return TokError(
"unexpected token in directive");
555 getStreamer().emitCOFFSafeSEH(Symbol);
559bool COFFAsmParser::parseDirectiveSecIdx(StringRef, SMLoc) {
562 return TokError(
"expected identifier in directive");
565 return TokError(
"unexpected token in directive");
568 getStreamer().emitCOFFSectionIndex(Symbol);
572bool COFFAsmParser::parseDirectiveSymIdx(StringRef, SMLoc) {
575 return TokError(
"expected identifier in directive");
578 return TokError(
"unexpected token in directive");
581 getStreamer().emitCOFFSymbolIndex(Symbol);
585bool COFFAsmParser::parseDirectiveSecNum(StringRef, SMLoc) {
588 return TokError(
"expected identifier in directive");
591 return TokError(
"unexpected token in directive");
594 getStreamer().emitCOFFSecNumber(Symbol);
598bool COFFAsmParser::parseDirectiveSecOffset(StringRef, SMLoc) {
601 return TokError(
"expected identifier in directive");
604 return TokError(
"unexpected token in directive");
607 getStreamer().emitCOFFSecOffset(Symbol);
613 StringRef TypeId = getTok().getIdentifier();
615 Type = StringSwitch<COFF::COMDATType>(TypeId)
626 return TokError(Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
635bool COFFAsmParser::parseDirectiveLinkOnce(StringRef, SMLoc Loc) {
638 if (parseCOMDATType(
Type))
641 const MCSectionCOFF *Current =
642 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
645 return Error(Loc,
"cannot make section associative with .linkonce");
648 return Error(Loc, Twine(
"section '") + Current->
getName() +
649 "' is already linkonce");
654 return TokError(
"unexpected token in directive");
659bool COFFAsmParser::parseSEHDirectiveStartProc(StringRef, SMLoc Loc) {
665 return TokError(
"unexpected token in directive");
668 getStreamer().emitWinCFIStartProc(Symbol, Loc);
672bool COFFAsmParser::parseSEHDirectiveEndProc(StringRef, SMLoc Loc) {
674 getStreamer().emitWinCFIEndProc(Loc);
678bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc Loc) {
680 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
684bool COFFAsmParser::parseSEHDirectiveSplitChained(StringRef, SMLoc Loc) {
686 getStreamer().emitWinCFISplitChained(Loc);
690bool COFFAsmParser::parseSEHDirectiveHandler(StringRef, SMLoc Loc) {
696 return TokError(
"you must specify one or both of @unwind or @except");
698 bool unwind =
false, except =
false;
699 if (parseAtUnwindOrAtExcept(unwind, except))
703 if (parseAtUnwindOrAtExcept(unwind, except))
707 return TokError(
"unexpected token in directive");
710 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
714bool COFFAsmParser::parseSEHDirectiveHandlerData(StringRef, SMLoc Loc) {
716 getStreamer().emitWinEHHandlerData();
720bool COFFAsmParser::parseSEHDirectiveAllocStack(StringRef, SMLoc Loc) {
722 if (getParser().parseAbsoluteExpression(
Size))
726 return TokError(
"unexpected token in directive");
729 getStreamer().emitWinCFIAllocStack(
Size, Loc);
733bool COFFAsmParser::parseSEHDirectiveEndProlog(StringRef, SMLoc Loc) {
735 getStreamer().emitWinCFIEndProlog(Loc);
739bool COFFAsmParser::ParseSEHDirectiveBeginEpilog(StringRef, SMLoc Loc) {
741 getStreamer().emitWinCFIBeginEpilogue(Loc);
745bool COFFAsmParser::ParseSEHDirectiveEndEpilog(StringRef, SMLoc Loc) {
747 getStreamer().emitWinCFIEndEpilogue(Loc);
751bool COFFAsmParser::ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc Loc) {
753 getStreamer().emitWinCFIUnwindV2Start(Loc);
757bool COFFAsmParser::ParseSEHDirectiveUnwindVersion(StringRef, SMLoc Loc) {
759 if (getParser().parseIntToken(
Version,
"expected unwind version number"))
763 return Error(Loc,
"invalid unwind version");
766 return TokError(
"unexpected token in directive");
769 getStreamer().emitWinCFIUnwindVersion(
Version, Loc);
773bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
774 StringRef identifier;
776 return TokError(
"a handler attribute must begin with '@' or '%'");
777 SMLoc startLoc = getLexer().getLoc();
779 if (getParser().parseIdentifier(identifier))
780 return Error(startLoc,
"expected @unwind or @except");
781 if (identifier ==
"unwind")
783 else if (identifier ==
"except")
786 return Error(startLoc,
"expected @unwind or @except");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
AMDGPU Prepare AGPR Alloc
Analysis containing CSE Info
static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr, bool *UseLastGroup)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool parseDirectiveCGProfile(StringRef, SMLoc)
parseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
static bool isImplicitlyDiscardable(StringRef Name)
unsigned getCharacteristics() const
void setSelection(int Selection) const
static constexpr unsigned NonUniqueID
StringRef getName() const
StringRef - Represent a constant reference to a string, i.e.
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_CNT_INITIALIZED_DATA
SymbolStorageClass
Storage class tells where and what the symbol represents.
@ IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_NEWEST
@ IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_ANY
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
NodeAddr< CodeNode * > Code
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
MCAsmParserExtension * createCOFFAsmParser()
FunctionAddr VTableAddr uintptr_t uintptr_t Version
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_Invalid
Not a valid directive.