32 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
35 this, HandleDirective<COFFAsmParser, HandlerMethod>);
39 bool ParseSectionSwitch(
StringRef Section,
55 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(
".text");
56 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(
".data");
57 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(
".bss");
58 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(
".section");
59 addDirectiveHandler<&COFFAsmParser::ParseDirectivePushSection>(
61 addDirectiveHandler<&COFFAsmParser::ParseDirectivePopSection>(
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::ParseDirectiveSymIdx>(
".symidx");
69 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSafeSEH>(
".safeseh");
70 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(
".secidx");
71 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(
".linkonce");
72 addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(
".rva");
73 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
74 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak_anti_dep");
75 addDirectiveHandler<&COFFAsmParser::ParseDirectiveCGProfile>(
".cg_profile");
78 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
80 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
82 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc>(
84 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
86 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
88 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
90 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
92 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
94 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
99 return ParseSectionSwitch(
".text",
114 return ParseSectionSwitch(
".bss",
149 bool ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
153 COFFAsmParser() =
default;
168 StringRef FlagsString,
unsigned *Flags) {
179 Discardable = 1 << 8,
183 bool ReadOnlyRemoved =
false;
184 unsigned SecFlags =
None;
186 for (
char FlagChar : FlagsString) {
194 if (SecFlags & InitData)
195 return TokError(
"conflicting section flags 'b' and 'd'.");
200 SecFlags |= InitData;
201 if (SecFlags & Alloc)
202 return TokError(
"conflicting section flags 'b' and 'd'.");
203 SecFlags &= ~NoWrite;
204 if ((SecFlags & NoLoad) == 0)
214 SecFlags |= Discardable;
218 ReadOnlyRemoved =
false;
220 if ((SecFlags & Code) == 0)
221 SecFlags |= InitData;
222 if ((SecFlags & NoLoad) == 0)
227 SecFlags |= Shared | InitData;
228 SecFlags &= ~NoWrite;
229 if ((SecFlags & NoLoad) == 0)
234 SecFlags &= ~NoWrite;
235 ReadOnlyRemoved =
true;
240 if ((SecFlags & NoLoad) == 0)
242 if (!ReadOnlyRemoved)
247 SecFlags |= NoRead | NoWrite;
255 return TokError(
"unknown flag");
261 if (SecFlags ==
None)
266 if (SecFlags & InitData)
268 if ((SecFlags & Alloc) && (SecFlags & Load) == 0)
270 if (SecFlags & NoLoad)
272 if ((SecFlags & Discardable) ||
275 if ((SecFlags & NoRead) == 0)
277 if ((SecFlags & NoWrite) == 0)
279 if (SecFlags & Shared)
299 if (getParser().parseIdentifier(
Name))
300 return TokError(
"expected identifier in directive");
304 getStreamer().emitSymbolAttribute(
Sym, Attr);
310 return TokError(
"unexpected token in directive");
319bool COFFAsmParser::ParseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
323bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
329bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
335 return TokError(
"unexpected token in section switching directive");
338 getStreamer().switchSection(getContext().getCOFFSection(
353bool COFFAsmParser::ParseDirectiveSection(
StringRef directive,
SMLoc loc) {
354 return parseSectionArguments(directive, loc);
377 return TokError(
"expected identifier in directive");
387 return TokError(
"expected string in directive");
389 StringRef FlagsStr = getTok().getStringContents();
392 if (ParseSectionFlags(
SectionName, FlagsStr, &Flags))
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 return TokError(
"unexpected token in directive");
424 const Triple &
T = getContext().getTargetTriple();
432bool COFFAsmParser::ParseDirectivePushSection(
StringRef directive,
SMLoc loc) {
433 getStreamer().pushSection();
435 if (parseSectionArguments(directive, loc)) {
436 getStreamer().popSection();
444 if (!getStreamer().popSection())
445 return TokError(
".popsection without corresponding .pushsection");
452 if (getParser().parseIdentifier(SymbolName))
453 return TokError(
"expected identifier in directive");
455 MCSymbol *
Sym = getContext().getOrCreateSymbol(SymbolName);
457 getStreamer().beginCOFFSymbolDef(
Sym);
465 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
469 return TokError(
"unexpected token in directive");
472 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
478 if (getParser().parseAbsoluteExpression(
Type))
482 return TokError(
"unexpected token in directive");
485 getStreamer().emitCOFFSymbolType(
Type);
491 getStreamer().endCOFFSymbolDef();
497 if (getParser().parseIdentifier(SymbolID))
498 return TokError(
"expected identifier in directive");
503 OffsetLoc = getLexer().getLoc();
504 if (getParser().parseAbsoluteExpression(
Offset))
509 return TokError(
"unexpected token in directive");
511 if (Offset < 0 || Offset > std::numeric_limits<uint32_t>::max())
514 "invalid '.secrel32' directive offset, can't be less "
515 "than zero or greater than std::numeric_limits<uint32_t>::max()");
520 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
525 auto parseOp = [&]() ->
bool {
527 if (getParser().parseIdentifier(SymbolID))
528 return TokError(
"expected identifier in directive");
533 OffsetLoc = getLexer().getLoc();
534 if (getParser().parseAbsoluteExpression(
Offset))
538 if (
Offset < std::numeric_limits<int32_t>::min() ||
539 Offset > std::numeric_limits<int32_t>::max())
540 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
541 "than -2147483648 or greater than "
546 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
550 if (getParser().parseMany(parseOp))
551 return addErrorSuffix(
" in directive");
557 if (getParser().parseIdentifier(SymbolID))
558 return TokError(
"expected identifier in directive");
561 return TokError(
"unexpected token in directive");
566 getStreamer().emitCOFFSafeSEH(Symbol);
572 if (getParser().parseIdentifier(SymbolID))
573 return TokError(
"expected identifier in directive");
576 return TokError(
"unexpected token in directive");
581 getStreamer().emitCOFFSectionIndex(Symbol);
587 if (getParser().parseIdentifier(SymbolID))
588 return TokError(
"expected identifier in directive");
591 return TokError(
"unexpected token in directive");
596 getStreamer().emitCOFFSymbolIndex(Symbol);
602 StringRef TypeId = getTok().getIdentifier();
615 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
627 if (parseCOMDATType(
Type))
631 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
634 return Error(Loc,
"cannot make section associative with .linkonce");
638 "' is already linkonce");
643 return TokError(
"unexpected token in directive");
648bool COFFAsmParser::ParseSEHDirectiveStartProc(
StringRef,
SMLoc Loc) {
650 if (getParser().parseIdentifier(SymbolID))
654 return TokError(
"unexpected token in directive");
659 getStreamer().emitWinCFIStartProc(Symbol, Loc);
663bool COFFAsmParser::ParseSEHDirectiveEndProc(
StringRef,
SMLoc Loc) {
665 getStreamer().emitWinCFIEndProc(Loc);
669bool COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc(
StringRef,
SMLoc Loc) {
671 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
675bool COFFAsmParser::ParseSEHDirectiveStartChained(
StringRef,
SMLoc Loc) {
677 getStreamer().emitWinCFIStartChained(Loc);
681bool COFFAsmParser::ParseSEHDirectiveEndChained(
StringRef,
SMLoc Loc) {
683 getStreamer().emitWinCFIEndChained(Loc);
687bool COFFAsmParser::ParseSEHDirectiveHandler(
StringRef,
SMLoc Loc) {
689 if (getParser().parseIdentifier(SymbolID))
693 return TokError(
"you must specify one or both of @unwind or @except");
695 bool unwind =
false, except =
false;
696 if (ParseAtUnwindOrAtExcept(unwind, except))
700 if (ParseAtUnwindOrAtExcept(unwind, except))
704 return TokError(
"unexpected token in directive");
706 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
709 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
713bool COFFAsmParser::ParseSEHDirectiveHandlerData(
StringRef,
SMLoc Loc) {
715 getStreamer().emitWinEHHandlerData();
719bool COFFAsmParser::ParseSEHDirectiveAllocStack(
StringRef,
SMLoc Loc) {
721 if (getParser().parseAbsoluteExpression(
Size))
725 return TokError(
"unexpected token in directive");
728 getStreamer().emitWinCFIAllocStack(
Size, Loc);
732bool COFFAsmParser::ParseSEHDirectiveEndProlog(
StringRef,
SMLoc Loc) {
734 getStreamer().emitWinCFIEndProlog(Loc);
738bool COFFAsmParser::ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
741 return TokError(
"a handler attribute must begin with '@' or '%'");
742 SMLoc startLoc = getLexer().getLoc();
744 if (getParser().parseIdentifier(identifier))
745 return Error(startLoc,
"expected @unwind or @except");
746 if (identifier ==
"unwind")
748 else if (identifier ==
"except")
751 return Error(startLoc,
"expected @unwind or @except");
758 return new COFFAsmParser;
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static SectionKind computeSectionKind(unsigned Flags)
COFFYAML::WeakExternalCharacteristics Characteristics
Analysis containing CSE Info
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Lightweight error class with error context and mandatory checking.
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>
MCAsmParser & getParser()
Generic assembler parser interface, for use by target specific assembly parsers.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
This represents a section on Windows.
static bool isImplicitlyDiscardable(StringRef Name)
unsigned getCharacteristics() const
void setSelection(int Selection) const
StringRef getName() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Represents a location in source code.
SectionKind - This is a simple POD value that classifies the properties of a section.
static SectionKind getText()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getReadOnly()
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
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
This is an optimization pass for GlobalISel generic memory operations.
MCAsmParserExtension * createCOFFAsmParser()
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_Invalid
Not a valid directive.