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)
298 if (getParser().parseIdentifier(Name))
299 return TokError(
"expected identifier in directive");
303 getStreamer().emitSymbolAttribute(Sym, Attr);
309 return TokError(
"unexpected token in directive");
318bool COFFAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
322bool COFFAsmParser::parseSectionSwitch(StringRef Section,
323 unsigned Characteristics) {
324 return parseSectionSwitch(Section, Characteristics,
"", (
COFF::COMDATType)0,
328bool COFFAsmParser::parseSectionSwitch(StringRef Section,
329 unsigned Characteristics,
330 StringRef COMDATSymName,
334 return TokError(
"unexpected token in section switching directive");
337 getStreamer().switchSection(
getContext().getCOFFSection(
338 Section, Characteristics, COMDATSymName,
Type, UniqueID));
343bool COFFAsmParser::parseSectionName(StringRef &SectionName) {
352bool COFFAsmParser::parseDirectiveSection(StringRef directive, SMLoc loc) {
353 return parseSectionArguments(directive, loc);
372bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
375 if (parseSectionName(SectionName))
376 return TokError(
"expected identifier in directive");
386 return TokError(
"expected string in directive");
388 StringRef FlagsStr = getTok().getStringContents();
396 StringRef COMDATSymName;
398 getLexer().peekTok().getString() !=
"unique") {
405 return TokError(
"expected comdat type such as 'discard' or 'largest' "
406 "after protection bits");
408 if (parseCOMDATType(
Type))
412 return TokError(
"expected comma in directive");
415 if (getParser().parseIdentifier(COMDATSymName))
416 return TokError(
"expected identifier in directive");
420 if (maybeParseUniqueID(UniqueID))
424 return TokError(
"unexpected token in directive");
431 parseSectionSwitch(SectionName, Flags, COMDATSymName,
Type, UniqueID);
435bool COFFAsmParser::parseDirectivePushSection(StringRef directive, SMLoc loc) {
436 getStreamer().pushSection();
438 if (parseSectionArguments(directive, loc)) {
439 getStreamer().popSection();
446bool COFFAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
447 if (!getStreamer().popSection())
448 return TokError(
".popsection without corresponding .pushsection");
452bool COFFAsmParser::parseDirectiveDef(StringRef, SMLoc) {
455 if (getParser().parseIdentifier(SymbolName))
456 return TokError(
"expected identifier in directive");
460 getStreamer().beginCOFFSymbolDef(Sym);
466bool COFFAsmParser::parseDirectiveScl(StringRef, SMLoc) {
468 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
472 return TokError(
"unexpected token in directive");
475 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
479bool COFFAsmParser::parseDirectiveType(StringRef, SMLoc) {
481 if (getParser().parseAbsoluteExpression(
Type))
485 return TokError(
"unexpected token in directive");
488 getStreamer().emitCOFFSymbolType(
Type);
492bool COFFAsmParser::parseDirectiveEndef(StringRef, SMLoc) {
494 getStreamer().endCOFFSymbolDef();
498bool COFFAsmParser::parseDirectiveSecRel32(StringRef, SMLoc) {
500 if (getParser().parseIdentifier(SymbolID))
501 return TokError(
"expected identifier in directive");
506 OffsetLoc = getLexer().getLoc();
507 if (getParser().parseAbsoluteExpression(
Offset))
512 return TokError(
"unexpected token in directive");
517 "invalid '.secrel32' directive offset, can't be less "
518 "than zero or greater than std::numeric_limits<uint32_t>::max()");
523 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
527bool COFFAsmParser::parseDirectiveRVA(StringRef, SMLoc) {
528 auto parseOp = [&]() ->
bool {
530 if (getParser().parseIdentifier(SymbolID))
531 return TokError(
"expected identifier in directive");
536 OffsetLoc = getLexer().getLoc();
537 if (getParser().parseAbsoluteExpression(
Offset))
541 if (
Offset < std::numeric_limits<int32_t>::min() ||
542 Offset > std::numeric_limits<int32_t>::max())
543 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
544 "than -2147483648 or greater than "
549 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
553 if (getParser().parseMany(parseOp))
554 return addErrorSuffix(
" in directive");
558bool COFFAsmParser::parseDirectiveSafeSEH(StringRef, SMLoc) {
560 if (getParser().parseIdentifier(SymbolID))
561 return TokError(
"expected identifier in directive");
564 return TokError(
"unexpected token in directive");
569 getStreamer().emitCOFFSafeSEH(Symbol);
573bool COFFAsmParser::parseDirectiveSecIdx(StringRef, SMLoc) {
575 if (getParser().parseIdentifier(SymbolID))
576 return TokError(
"expected identifier in directive");
579 return TokError(
"unexpected token in directive");
584 getStreamer().emitCOFFSectionIndex(Symbol);
588bool COFFAsmParser::parseDirectiveSymIdx(StringRef, SMLoc) {
590 if (getParser().parseIdentifier(SymbolID))
591 return TokError(
"expected identifier in directive");
594 return TokError(
"unexpected token in directive");
599 getStreamer().emitCOFFSymbolIndex(Symbol);
603bool COFFAsmParser::parseDirectiveSecNum(StringRef, SMLoc) {
605 if (getParser().parseIdentifier(SymbolID))
606 return TokError(
"expected identifier in directive");
609 return TokError(
"unexpected token in directive");
614 getStreamer().emitCOFFSecNumber(Symbol);
618bool COFFAsmParser::parseDirectiveSecOffset(StringRef, SMLoc) {
620 if (getParser().parseIdentifier(SymbolID))
621 return TokError(
"expected identifier in directive");
624 return TokError(
"unexpected token in directive");
629 getStreamer().emitCOFFSecOffset(Symbol);
635 StringRef TypeId = getTok().getIdentifier();
637 Type = StringSwitch<COFF::COMDATType>(TypeId)
648 return TokError(Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
657bool COFFAsmParser::parseDirectiveLinkOnce(StringRef, SMLoc Loc) {
660 if (parseCOMDATType(
Type))
663 const MCSectionCOFF *Current =
664 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
667 return Error(Loc,
"cannot make section associative with .linkonce");
670 return Error(Loc, Twine(
"section '") + Current->
getName() +
671 "' is already linkonce");
676 return TokError(
"unexpected token in directive");
681bool COFFAsmParser::parseSEHDirectiveStartProc(StringRef, SMLoc Loc) {
683 if (getParser().parseIdentifier(SymbolID))
687 return TokError(
"unexpected token in directive");
692 getStreamer().emitWinCFIStartProc(Symbol, Loc);
696bool COFFAsmParser::parseSEHDirectiveEndProc(StringRef, SMLoc Loc) {
698 getStreamer().emitWinCFIEndProc(Loc);
702bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc Loc) {
704 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
708bool COFFAsmParser::parseSEHDirectiveStartChained(StringRef, SMLoc Loc) {
710 getStreamer().emitWinCFIStartChained(Loc);
714bool COFFAsmParser::parseSEHDirectiveEndChained(StringRef, SMLoc Loc) {
716 getStreamer().emitWinCFIEndChained(Loc);
720bool COFFAsmParser::parseSEHDirectiveHandler(StringRef, SMLoc Loc) {
722 if (getParser().parseIdentifier(SymbolID))
726 return TokError(
"you must specify one or both of @unwind or @except");
728 bool unwind =
false, except =
false;
729 if (parseAtUnwindOrAtExcept(unwind, except))
733 if (parseAtUnwindOrAtExcept(unwind, except))
737 return TokError(
"unexpected token in directive");
742 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
746bool COFFAsmParser::parseSEHDirectiveHandlerData(StringRef, SMLoc Loc) {
748 getStreamer().emitWinEHHandlerData();
752bool COFFAsmParser::parseSEHDirectiveAllocStack(StringRef, SMLoc Loc) {
754 if (getParser().parseAbsoluteExpression(
Size))
758 return TokError(
"unexpected token in directive");
761 getStreamer().emitWinCFIAllocStack(
Size, Loc);
765bool COFFAsmParser::parseSEHDirectiveEndProlog(StringRef, SMLoc Loc) {
767 getStreamer().emitWinCFIEndProlog(Loc);
771bool COFFAsmParser::ParseSEHDirectiveBeginEpilog(StringRef, SMLoc Loc) {
773 getStreamer().emitWinCFIBeginEpilogue(Loc);
777bool COFFAsmParser::ParseSEHDirectiveEndEpilog(StringRef, SMLoc Loc) {
779 getStreamer().emitWinCFIEndEpilogue(Loc);
783bool COFFAsmParser::ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc Loc) {
785 getStreamer().emitWinCFIUnwindV2Start(Loc);
789bool COFFAsmParser::ParseSEHDirectiveUnwindVersion(StringRef, SMLoc Loc) {
791 if (getParser().parseIntToken(
Version,
"expected unwind version number"))
795 return Error(Loc,
"invalid unwind version");
798 return TokError(
"unexpected token in directive");
801 getStreamer().emitWinCFIUnwindVersion(
Version, Loc);
805bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
806 StringRef identifier;
808 return TokError(
"a handler attribute must begin with '@' or '%'");
809 SMLoc startLoc = getLexer().getLoc();
811 if (getParser().parseIdentifier(identifier))
812 return Error(startLoc,
"expected @unwind or @except");
813 if (identifier ==
"unwind")
815 else if (identifier ==
"except")
818 return Error(startLoc,
"expected @unwind or @except");
825 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.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ 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
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.