31 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
32 void addDirectiveHandler(StringRef Directive) {
34 this, HandleDirective<COFFAsmParser, HandlerMethod>);
35 getParser().addDirectiveHandler(Directive, Handler);
38 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics);
40 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics,
44 bool parseSectionName(StringRef &SectionName);
47 void Initialize(MCAsmParser &Parser)
override {
51 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveText>(
".text");
52 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveData>(
".data");
53 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveBSS>(
".bss");
54 addDirectiveHandler<&COFFAsmParser::parseDirectiveSection>(
".section");
55 addDirectiveHandler<&COFFAsmParser::parseDirectivePushSection>(
57 addDirectiveHandler<&COFFAsmParser::parseDirectivePopSection>(
59 addDirectiveHandler<&COFFAsmParser::parseDirectiveDef>(
".def");
60 addDirectiveHandler<&COFFAsmParser::parseDirectiveScl>(
".scl");
61 addDirectiveHandler<&COFFAsmParser::parseDirectiveType>(
".type");
62 addDirectiveHandler<&COFFAsmParser::parseDirectiveEndef>(
".endef");
63 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecRel32>(
".secrel32");
64 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymIdx>(
".symidx");
65 addDirectiveHandler<&COFFAsmParser::parseDirectiveSafeSEH>(
".safeseh");
66 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecIdx>(
".secidx");
67 addDirectiveHandler<&COFFAsmParser::parseDirectiveLinkOnce>(
".linkonce");
68 addDirectiveHandler<&COFFAsmParser::parseDirectiveRVA>(
".rva");
69 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
".weak");
70 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
72 addDirectiveHandler<&COFFAsmParser::parseDirectiveCGProfile>(
".cg_profile");
73 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecNum>(
".secnum");
74 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecOffset>(
".secoffset");
77 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartProc>(
79 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProc>(
81 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc>(
83 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartChained>(
85 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndChained>(
87 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandler>(
89 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandlerData>(
91 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveAllocStack>(
93 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProlog>(
95 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveBeginEpilog>(
96 ".seh_startepilogue");
97 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndEpilog>(
99 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindV2Start>(
100 ".seh_unwindv2start");
101 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindVersion>(
102 ".seh_unwindversion");
105 bool parseSectionDirectiveText(StringRef, SMLoc) {
111 bool parseSectionDirectiveData(StringRef, SMLoc) {
117 bool parseSectionDirectiveBSS(StringRef, SMLoc) {
123 bool parseDirectiveSection(StringRef, SMLoc);
124 bool parseSectionArguments(StringRef, SMLoc);
125 bool parseDirectivePushSection(StringRef, SMLoc);
126 bool parseDirectivePopSection(StringRef, SMLoc);
127 bool parseDirectiveDef(StringRef, SMLoc);
128 bool parseDirectiveScl(StringRef, SMLoc);
129 bool parseDirectiveType(StringRef, SMLoc);
130 bool parseDirectiveEndef(StringRef, SMLoc);
131 bool parseDirectiveSecRel32(StringRef, SMLoc);
132 bool parseDirectiveSecIdx(StringRef, SMLoc);
133 bool parseDirectiveSafeSEH(StringRef, SMLoc);
134 bool parseDirectiveSymIdx(StringRef, SMLoc);
136 bool parseDirectiveLinkOnce(StringRef, SMLoc);
137 bool parseDirectiveRVA(StringRef, SMLoc);
138 bool parseDirectiveCGProfile(StringRef, SMLoc);
139 bool parseDirectiveSecNum(StringRef, SMLoc);
140 bool parseDirectiveSecOffset(StringRef, SMLoc);
143 bool parseSEHDirectiveStartProc(StringRef, SMLoc);
144 bool parseSEHDirectiveEndProc(StringRef, SMLoc);
145 bool parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc);
146 bool parseSEHDirectiveStartChained(StringRef, SMLoc);
147 bool parseSEHDirectiveEndChained(StringRef, SMLoc);
148 bool parseSEHDirectiveHandler(StringRef, SMLoc);
149 bool parseSEHDirectiveHandlerData(StringRef, SMLoc);
150 bool parseSEHDirectiveAllocStack(StringRef, SMLoc);
151 bool parseSEHDirectiveEndProlog(StringRef, SMLoc);
152 bool ParseSEHDirectiveBeginEpilog(StringRef, SMLoc);
153 bool ParseSEHDirectiveEndEpilog(StringRef, SMLoc);
154 bool ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc);
155 bool ParseSEHDirectiveUnwindVersion(StringRef, SMLoc);
157 bool parseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
158 bool parseDirectiveSymbolAttribute(StringRef Directive, SMLoc);
161 COFFAsmParser() =
default;
167 StringRef FlagsString,
unsigned *Flags) {
178 Discardable = 1 << 8,
182 bool ReadOnlyRemoved =
false;
183 unsigned SecFlags =
None;
185 for (
char FlagChar : FlagsString) {
193 if (SecFlags & InitData)
194 return TokError(
"conflicting section flags 'b' and 'd'.");
199 SecFlags |= InitData;
200 if (SecFlags &
Alloc)
201 return TokError(
"conflicting section flags 'b' and 'd'.");
202 SecFlags &= ~NoWrite;
203 if ((SecFlags & NoLoad) == 0)
213 SecFlags |= Discardable;
217 ReadOnlyRemoved =
false;
219 if ((SecFlags & Code) == 0)
220 SecFlags |= InitData;
221 if ((SecFlags & NoLoad) == 0)
226 SecFlags |=
Shared | InitData;
227 SecFlags &= ~NoWrite;
228 if ((SecFlags & NoLoad) == 0)
233 SecFlags &= ~NoWrite;
234 ReadOnlyRemoved =
true;
239 if ((SecFlags & NoLoad) == 0)
241 if (!ReadOnlyRemoved)
246 SecFlags |= NoRead | NoWrite;
254 return TokError(
"unknown flag");
260 if (SecFlags ==
None)
265 if (SecFlags & InitData)
267 if ((SecFlags &
Alloc) && (SecFlags & Load) == 0)
269 if (SecFlags & NoLoad)
271 if ((SecFlags & Discardable) ||
274 if ((SecFlags & NoRead) == 0)
276 if ((SecFlags & NoWrite) == 0)
278 if (SecFlags & Shared)
288bool COFFAsmParser::parseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
289 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
299 return TokError(
"expected identifier in directive");
301 getStreamer().emitSymbolAttribute(Sym, Attr);
307 return TokError(
"unexpected token in directive");
316bool COFFAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
320bool COFFAsmParser::parseSectionSwitch(StringRef Section,
321 unsigned Characteristics) {
322 return parseSectionSwitch(Section, Characteristics,
"", (
COFF::COMDATType)0,
326bool COFFAsmParser::parseSectionSwitch(StringRef Section,
327 unsigned Characteristics,
328 StringRef COMDATSymName,
332 return TokError(
"unexpected token in section switching directive");
335 getStreamer().switchSection(
getContext().getCOFFSection(
336 Section, Characteristics, COMDATSymName,
Type, UniqueID));
341bool COFFAsmParser::parseSectionName(StringRef &SectionName) {
350bool COFFAsmParser::parseDirectiveSection(StringRef directive, SMLoc loc) {
351 return parseSectionArguments(directive, loc);
370bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
373 if (parseSectionName(SectionName))
374 return TokError(
"expected identifier in directive");
384 return TokError(
"expected string in directive");
386 StringRef FlagsStr = getTok().getStringContents();
394 StringRef COMDATSymName;
396 getLexer().peekTok().getString() !=
"unique") {
403 return TokError(
"expected comdat type such as 'discard' or 'largest' "
404 "after protection bits");
406 if (parseCOMDATType(
Type))
410 return TokError(
"expected comma in directive");
413 if (getParser().parseIdentifier(COMDATSymName))
414 return TokError(
"expected identifier in directive");
418 if (maybeParseUniqueID(UniqueID))
422 return TokError(
"unexpected token in directive");
429 parseSectionSwitch(SectionName, Flags, COMDATSymName,
Type, UniqueID);
433bool COFFAsmParser::parseDirectivePushSection(StringRef directive, SMLoc loc) {
434 getStreamer().pushSection();
436 if (parseSectionArguments(directive, loc)) {
437 getStreamer().popSection();
444bool COFFAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
445 if (!getStreamer().popSection())
446 return TokError(
".popsection without corresponding .pushsection");
450bool COFFAsmParser::parseDirectiveDef(StringRef, SMLoc) {
454 return TokError(
"expected identifier in directive");
456 getStreamer().beginCOFFSymbolDef(Sym);
462bool COFFAsmParser::parseDirectiveScl(StringRef, SMLoc) {
464 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
468 return TokError(
"unexpected token in directive");
471 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
475bool COFFAsmParser::parseDirectiveType(StringRef, SMLoc) {
477 if (getParser().parseAbsoluteExpression(
Type))
481 return TokError(
"unexpected token in directive");
484 getStreamer().emitCOFFSymbolType(
Type);
488bool COFFAsmParser::parseDirectiveEndef(StringRef, SMLoc) {
490 getStreamer().endCOFFSymbolDef();
494bool COFFAsmParser::parseDirectiveSecRel32(StringRef, SMLoc) {
497 return TokError(
"expected identifier in directive");
502 OffsetLoc = getLexer().getLoc();
503 if (getParser().parseAbsoluteExpression(
Offset))
508 return TokError(
"unexpected token in directive");
513 "invalid '.secrel32' directive offset, can't be less "
514 "than zero or greater than std::numeric_limits<uint32_t>::max()");
517 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
521bool COFFAsmParser::parseDirectiveRVA(StringRef, SMLoc) {
522 auto parseOp = [&]() ->
bool {
525 return TokError(
"expected identifier in directive");
530 OffsetLoc = getLexer().getLoc();
531 if (getParser().parseAbsoluteExpression(
Offset))
535 if (
Offset < std::numeric_limits<int32_t>::min() ||
536 Offset > std::numeric_limits<int32_t>::max())
537 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
538 "than -2147483648 or greater than "
541 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
545 if (getParser().parseMany(parseOp))
546 return addErrorSuffix(
" in directive");
550bool COFFAsmParser::parseDirectiveSafeSEH(StringRef, SMLoc) {
553 return TokError(
"expected identifier in directive");
556 return TokError(
"unexpected token in directive");
559 getStreamer().emitCOFFSafeSEH(Symbol);
563bool COFFAsmParser::parseDirectiveSecIdx(StringRef, SMLoc) {
566 return TokError(
"expected identifier in directive");
569 return TokError(
"unexpected token in directive");
572 getStreamer().emitCOFFSectionIndex(Symbol);
576bool COFFAsmParser::parseDirectiveSymIdx(StringRef, SMLoc) {
579 return TokError(
"expected identifier in directive");
582 return TokError(
"unexpected token in directive");
585 getStreamer().emitCOFFSymbolIndex(Symbol);
589bool COFFAsmParser::parseDirectiveSecNum(StringRef, SMLoc) {
592 return TokError(
"expected identifier in directive");
595 return TokError(
"unexpected token in directive");
598 getStreamer().emitCOFFSecNumber(Symbol);
602bool COFFAsmParser::parseDirectiveSecOffset(StringRef, SMLoc) {
605 return TokError(
"expected identifier in directive");
608 return TokError(
"unexpected token in directive");
611 getStreamer().emitCOFFSecOffset(Symbol);
617 StringRef TypeId = getTok().getIdentifier();
619 Type = StringSwitch<COFF::COMDATType>(TypeId)
630 return TokError(Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
639bool COFFAsmParser::parseDirectiveLinkOnce(StringRef, SMLoc Loc) {
642 if (parseCOMDATType(
Type))
645 const MCSectionCOFF *Current =
646 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
649 return Error(Loc,
"cannot make section associative with .linkonce");
652 return Error(Loc, Twine(
"section '") + Current->
getName() +
653 "' is already linkonce");
658 return TokError(
"unexpected token in directive");
663bool COFFAsmParser::parseSEHDirectiveStartProc(StringRef, SMLoc Loc) {
669 return TokError(
"unexpected token in directive");
672 getStreamer().emitWinCFIStartProc(Symbol, Loc);
676bool COFFAsmParser::parseSEHDirectiveEndProc(StringRef, SMLoc Loc) {
678 getStreamer().emitWinCFIEndProc(Loc);
682bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc Loc) {
684 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
688bool COFFAsmParser::parseSEHDirectiveStartChained(StringRef, SMLoc Loc) {
690 getStreamer().emitWinCFIStartChained(Loc);
694bool COFFAsmParser::parseSEHDirectiveEndChained(StringRef, SMLoc Loc) {
696 getStreamer().emitWinCFIEndChained(Loc);
700bool COFFAsmParser::parseSEHDirectiveHandler(StringRef, SMLoc Loc) {
706 return TokError(
"you must specify one or both of @unwind or @except");
708 bool unwind =
false, except =
false;
709 if (parseAtUnwindOrAtExcept(unwind, except))
713 if (parseAtUnwindOrAtExcept(unwind, except))
717 return TokError(
"unexpected token in directive");
720 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
724bool COFFAsmParser::parseSEHDirectiveHandlerData(StringRef, SMLoc Loc) {
726 getStreamer().emitWinEHHandlerData();
730bool COFFAsmParser::parseSEHDirectiveAllocStack(StringRef, SMLoc Loc) {
732 if (getParser().parseAbsoluteExpression(
Size))
736 return TokError(
"unexpected token in directive");
739 getStreamer().emitWinCFIAllocStack(
Size, Loc);
743bool COFFAsmParser::parseSEHDirectiveEndProlog(StringRef, SMLoc Loc) {
745 getStreamer().emitWinCFIEndProlog(Loc);
749bool COFFAsmParser::ParseSEHDirectiveBeginEpilog(StringRef, SMLoc Loc) {
751 getStreamer().emitWinCFIBeginEpilogue(Loc);
755bool COFFAsmParser::ParseSEHDirectiveEndEpilog(StringRef, SMLoc Loc) {
757 getStreamer().emitWinCFIEndEpilogue(Loc);
761bool COFFAsmParser::ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc Loc) {
763 getStreamer().emitWinCFIUnwindV2Start(Loc);
767bool COFFAsmParser::ParseSEHDirectiveUnwindVersion(StringRef, SMLoc Loc) {
769 if (getParser().parseIntToken(
Version,
"expected unwind version number"))
773 return Error(Loc,
"invalid unwind version");
776 return TokError(
"unexpected token in directive");
779 getStreamer().emitWinCFIUnwindVersion(
Version, Loc);
783bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
784 StringRef identifier;
786 return TokError(
"a handler attribute must begin with '@' or '%'");
787 SMLoc startLoc = getLexer().getLoc();
789 if (getParser().parseIdentifier(identifier))
790 return Error(startLoc,
"expected @unwind or @except");
791 if (identifier ==
"unwind")
793 else if (identifier ==
"except")
796 return Error(startLoc,
"expected @unwind or @except");
803 return new COFFAsmParser;
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.