32 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
35 this, HandleDirective<COFFAsmParser, HandlerMethod>);
52 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(
".text");
53 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(
".data");
54 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(
".bss");
55 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(
".section");
56 addDirectiveHandler<&COFFAsmParser::ParseDirectivePushSection>(
58 addDirectiveHandler<&COFFAsmParser::ParseDirectivePopSection>(
60 addDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(
".def");
61 addDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(
".scl");
62 addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(
".type");
63 addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(
".endef");
64 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(
".secrel32");
65 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymIdx>(
".symidx");
66 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSafeSEH>(
".safeseh");
67 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(
".secidx");
68 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(
".linkonce");
69 addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(
".rva");
70 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
71 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak_anti_dep");
72 addDirectiveHandler<&COFFAsmParser::ParseDirectiveCGProfile>(
".cg_profile");
75 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
77 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
79 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc>(
81 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
83 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
85 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
87 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
89 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
91 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
141 bool ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
145 COFFAsmParser() =
default;
151 StringRef FlagsString,
unsigned *Flags) {
162 Discardable = 1 << 8,
166 bool ReadOnlyRemoved =
false;
167 unsigned SecFlags =
None;
169 for (
char FlagChar : FlagsString) {
177 if (SecFlags & InitData)
178 return TokError(
"conflicting section flags 'b' and 'd'.");
183 SecFlags |= InitData;
184 if (SecFlags & Alloc)
185 return TokError(
"conflicting section flags 'b' and 'd'.");
186 SecFlags &= ~NoWrite;
187 if ((SecFlags & NoLoad) == 0)
197 SecFlags |= Discardable;
201 ReadOnlyRemoved =
false;
203 if ((SecFlags & Code) == 0)
204 SecFlags |= InitData;
205 if ((SecFlags & NoLoad) == 0)
210 SecFlags |= Shared | InitData;
211 SecFlags &= ~NoWrite;
212 if ((SecFlags & NoLoad) == 0)
217 SecFlags &= ~NoWrite;
218 ReadOnlyRemoved =
true;
223 if ((SecFlags & NoLoad) == 0)
225 if (!ReadOnlyRemoved)
230 SecFlags |= NoRead | NoWrite;
238 return TokError(
"unknown flag");
244 if (SecFlags ==
None)
249 if (SecFlags & InitData)
251 if ((SecFlags & Alloc) && (SecFlags & Load) == 0)
253 if (SecFlags & NoLoad)
255 if ((SecFlags & Discardable) ||
258 if ((SecFlags & NoRead) == 0)
260 if ((SecFlags & NoWrite) == 0)
262 if (SecFlags & Shared)
282 if (getParser().parseIdentifier(
Name))
283 return TokError(
"expected identifier in directive");
287 getStreamer().emitSymbolAttribute(
Sym, Attr);
293 return TokError(
"unexpected token in directive");
302bool COFFAsmParser::ParseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
306bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
311bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
316 return TokError(
"unexpected token in section switching directive");
319 getStreamer().switchSection(getContext().getCOFFSection(
334bool COFFAsmParser::ParseDirectiveSection(
StringRef directive,
SMLoc loc) {
335 return parseSectionArguments(directive, loc);
358 return TokError(
"expected identifier in directive");
368 return TokError(
"expected string in directive");
370 StringRef FlagsStr = getTok().getStringContents();
373 if (ParseSectionFlags(
SectionName, FlagsStr, &Flags))
386 return TokError(
"expected comdat type such as 'discard' or 'largest' "
387 "after protection bits");
389 if (parseCOMDATType(
Type))
393 return TokError(
"expected comma in directive");
396 if (getParser().parseIdentifier(COMDATSymName))
397 return TokError(
"expected identifier in directive");
401 return TokError(
"unexpected token in directive");
404 const Triple &
T = getContext().getTargetTriple();
412bool COFFAsmParser::ParseDirectivePushSection(
StringRef directive,
SMLoc loc) {
413 getStreamer().pushSection();
415 if (parseSectionArguments(directive, loc)) {
416 getStreamer().popSection();
424 if (!getStreamer().popSection())
425 return TokError(
".popsection without corresponding .pushsection");
432 if (getParser().parseIdentifier(SymbolName))
433 return TokError(
"expected identifier in directive");
435 MCSymbol *
Sym = getContext().getOrCreateSymbol(SymbolName);
437 getStreamer().beginCOFFSymbolDef(
Sym);
445 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
449 return TokError(
"unexpected token in directive");
452 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
458 if (getParser().parseAbsoluteExpression(
Type))
462 return TokError(
"unexpected token in directive");
465 getStreamer().emitCOFFSymbolType(
Type);
471 getStreamer().endCOFFSymbolDef();
477 if (getParser().parseIdentifier(SymbolID))
478 return TokError(
"expected identifier in directive");
483 OffsetLoc = getLexer().getLoc();
484 if (getParser().parseAbsoluteExpression(
Offset))
489 return TokError(
"unexpected token in directive");
491 if (Offset < 0 || Offset > std::numeric_limits<uint32_t>::max())
494 "invalid '.secrel32' directive offset, can't be less "
495 "than zero or greater than std::numeric_limits<uint32_t>::max()");
500 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
505 auto parseOp = [&]() ->
bool {
507 if (getParser().parseIdentifier(SymbolID))
508 return TokError(
"expected identifier in directive");
513 OffsetLoc = getLexer().getLoc();
514 if (getParser().parseAbsoluteExpression(
Offset))
518 if (
Offset < std::numeric_limits<int32_t>::min() ||
519 Offset > std::numeric_limits<int32_t>::max())
520 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
521 "than -2147483648 or greater than "
526 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
530 if (getParser().parseMany(parseOp))
531 return addErrorSuffix(
" in directive");
537 if (getParser().parseIdentifier(SymbolID))
538 return TokError(
"expected identifier in directive");
541 return TokError(
"unexpected token in directive");
546 getStreamer().emitCOFFSafeSEH(Symbol);
552 if (getParser().parseIdentifier(SymbolID))
553 return TokError(
"expected identifier in directive");
556 return TokError(
"unexpected token in directive");
561 getStreamer().emitCOFFSectionIndex(Symbol);
567 if (getParser().parseIdentifier(SymbolID))
568 return TokError(
"expected identifier in directive");
571 return TokError(
"unexpected token in directive");
576 getStreamer().emitCOFFSymbolIndex(Symbol);
582 StringRef TypeId = getTok().getIdentifier();
595 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
607 if (parseCOMDATType(
Type))
611 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
614 return Error(Loc,
"cannot make section associative with .linkonce");
618 "' is already linkonce");
623 return TokError(
"unexpected token in directive");
628bool COFFAsmParser::ParseSEHDirectiveStartProc(
StringRef,
SMLoc Loc) {
630 if (getParser().parseIdentifier(SymbolID))
634 return TokError(
"unexpected token in directive");
639 getStreamer().emitWinCFIStartProc(Symbol, Loc);
643bool COFFAsmParser::ParseSEHDirectiveEndProc(
StringRef,
SMLoc Loc) {
645 getStreamer().emitWinCFIEndProc(Loc);
649bool COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc(
StringRef,
SMLoc Loc) {
651 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
655bool COFFAsmParser::ParseSEHDirectiveStartChained(
StringRef,
SMLoc Loc) {
657 getStreamer().emitWinCFIStartChained(Loc);
661bool COFFAsmParser::ParseSEHDirectiveEndChained(
StringRef,
SMLoc Loc) {
663 getStreamer().emitWinCFIEndChained(Loc);
667bool COFFAsmParser::ParseSEHDirectiveHandler(
StringRef,
SMLoc Loc) {
669 if (getParser().parseIdentifier(SymbolID))
673 return TokError(
"you must specify one or both of @unwind or @except");
675 bool unwind =
false, except =
false;
676 if (ParseAtUnwindOrAtExcept(unwind, except))
680 if (ParseAtUnwindOrAtExcept(unwind, except))
684 return TokError(
"unexpected token in directive");
686 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
689 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
693bool COFFAsmParser::ParseSEHDirectiveHandlerData(
StringRef,
SMLoc Loc) {
695 getStreamer().emitWinEHHandlerData();
699bool COFFAsmParser::ParseSEHDirectiveAllocStack(
StringRef,
SMLoc Loc) {
701 if (getParser().parseAbsoluteExpression(
Size))
705 return TokError(
"unexpected token in directive");
708 getStreamer().emitWinCFIAllocStack(
Size, Loc);
712bool COFFAsmParser::ParseSEHDirectiveEndProlog(
StringRef,
SMLoc Loc) {
714 getStreamer().emitWinCFIEndProlog(Loc);
718bool COFFAsmParser::ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
721 return TokError(
"a handler attribute must begin with '@' or '%'");
722 SMLoc startLoc = getLexer().getLoc();
724 if (getParser().parseIdentifier(identifier))
725 return Error(startLoc,
"expected @unwind or @except");
726 if (identifier ==
"unwind")
728 else if (identifier ==
"except")
731 return Error(startLoc,
"expected @unwind or @except");
738 return new COFFAsmParser;
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
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.
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.