30 template<
bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
31 void addDirectiveHandler(
StringRef Directive) {
33 this, HandleDirective<DarwinAsmParser, HandlerMethod>);
34 getParser().addDirectiveHandler(Directive, Handler);
37 bool parseSectionSwitch(
const char *Segment,
const char *
Section,
38 unsigned TAA = 0,
unsigned ImplicitAlign = 0,
39 unsigned StubSize = 0);
48 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(
".desc");
49 addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>(
51 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(
".lsym");
52 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>(
53 ".subsections_via_symbols");
54 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(
".dump");
55 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(
".load");
56 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(
".section");
57 addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>(
59 addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>(
61 addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(
".previous");
62 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>(
63 ".secure_log_unique");
64 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>(
66 addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(
".tbss");
67 addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(
".zerofill");
69 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>(
71 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>(
75 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(
".bss");
76 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(
".const");
77 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>(
79 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>(
81 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>(
83 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(
".data");
84 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>(
86 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(
".dyld");
87 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>(
89 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>(
92 &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>(
93 ".lazy_symbol_pointer");
94 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>(
96 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>(
98 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>(
100 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>(
102 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>(
104 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>(
107 &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>(
108 ".non_lazy_symbol_pointer");
109 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>(
110 ".objc_cat_cls_meth");
111 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>(
112 ".objc_cat_inst_meth");
113 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>(
115 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>(
117 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>(
118 ".objc_class_names");
119 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>(
121 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>(
123 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>(
125 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>(
128 &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>(
129 ".objc_instance_vars");
130 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>(
131 ".objc_message_refs");
132 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>(
135 &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>(
136 ".objc_meth_var_names");
138 &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>(
139 ".objc_meth_var_types");
140 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>(
141 ".objc_module_info");
142 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>(
145 &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>(
146 ".objc_selector_strs");
148 &DarwinAsmParser::parseSectionDirectiveObjCStringObject>(
149 ".objc_string_object");
150 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>(
152 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>(
154 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>(
156 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>(
158 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>(
160 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(
".tdata");
161 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(
".text");
162 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>(
163 ".thread_init_func");
164 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(
".tlv");
166 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(
".ident");
167 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
".ios_version_min");
168 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
169 ".macosx_version_min");
191 return parseSectionSwitch(
"__DATA",
"__bss");
195 return parseSectionSwitch(
"__TEXT",
"__const");
198 return parseSectionSwitch(
"__TEXT",
"__static_const");
201 return parseSectionSwitch(
"__TEXT",
"__cstring",
205 return parseSectionSwitch(
"__TEXT",
"__literal4",
209 return parseSectionSwitch(
"__TEXT",
"__literal8",
213 return parseSectionSwitch(
"__TEXT",
"__literal16",
217 return parseSectionSwitch(
"__TEXT",
"__constructor");
220 return parseSectionSwitch(
"__TEXT",
"__destructor");
223 return parseSectionSwitch(
"__TEXT",
"__fvmlib_init0");
226 return parseSectionSwitch(
"__TEXT",
"__fvmlib_init1");
229 return parseSectionSwitch(
"__TEXT",
"__symbol_stub",
236 return parseSectionSwitch(
"__TEXT",
"__picsymbol_stub",
241 return parseSectionSwitch(
"__DATA",
"__data");
244 return parseSectionSwitch(
"__DATA",
"__static_data");
246 bool parseSectionDirectiveNonLazySymbolPointers(
StringRef,
SMLoc) {
247 return parseSectionSwitch(
"__DATA",
"__nl_symbol_ptr",
251 return parseSectionSwitch(
"__DATA",
"__la_symbol_ptr",
255 return parseSectionSwitch(
"__DATA",
"__dyld");
258 return parseSectionSwitch(
"__DATA",
"__mod_init_func",
262 return parseSectionSwitch(
"__DATA",
"__mod_term_func",
266 return parseSectionSwitch(
"__DATA",
"__const");
269 return parseSectionSwitch(
"__OBJC",
"__class",
273 return parseSectionSwitch(
"__OBJC",
"__meta_class",
277 return parseSectionSwitch(
"__OBJC",
"__cat_cls_meth",
281 return parseSectionSwitch(
"__OBJC",
"__cat_inst_meth",
285 return parseSectionSwitch(
"__OBJC",
"__protocol",
289 return parseSectionSwitch(
"__OBJC",
"__string_object",
293 return parseSectionSwitch(
"__OBJC",
"__cls_meth",
297 return parseSectionSwitch(
"__OBJC",
"__inst_meth",
301 return parseSectionSwitch(
"__OBJC",
"__cls_refs",
306 return parseSectionSwitch(
"__OBJC",
"__message_refs",
311 return parseSectionSwitch(
"__OBJC",
"__symbols",
315 return parseSectionSwitch(
"__OBJC",
"__category",
319 return parseSectionSwitch(
"__OBJC",
"__class_vars",
323 return parseSectionSwitch(
"__OBJC",
"__instance_vars",
327 return parseSectionSwitch(
"__OBJC",
"__module_info",
331 return parseSectionSwitch(
"__TEXT",
"__cstring",
335 return parseSectionSwitch(
"__TEXT",
"__cstring",
339 return parseSectionSwitch(
"__TEXT",
"__cstring",
343 return parseSectionSwitch(
"__OBJC",
"__selector_strs",
347 return parseSectionSwitch(
"__DATA",
"__thread_data",
351 return parseSectionSwitch(
"__TEXT",
"__text",
355 return parseSectionSwitch(
"__DATA",
"__thread_vars",
360 getParser().eatToEndOfStatement();
364 return parseSectionSwitch(
"__DATA",
"__thread_init",
373 bool DarwinAsmParser::parseSectionSwitch(
const char *Segment,
375 unsigned TAA,
unsigned Align,
378 return TokError(
"unexpected token in section switching directive");
383 getStreamer().SwitchSection(getContext().getMachOSection(
384 Segment, Section, TAA, StubSize,
397 getStreamer().EmitValueToAlignment(Align);
406 if (getParser().parseIdentifier(Name))
407 return TokError(
"expected identifier in directive");
410 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
413 return TokError(
"unexpected token in '.desc' directive");
417 if (getParser().parseAbsoluteExpression(DescValue))
421 return TokError(
"unexpected token in '.desc' directive");
426 getStreamer().EmitSymbolDesc(Sym, DescValue);
433 bool DarwinAsmParser::parseDirectiveIndirectSymbol(
StringRef,
SMLoc Loc) {
435 getStreamer().getCurrentSection().first);
440 return Error(Loc,
"indirect symbol not in a symbol pointer or stub "
444 if (getParser().parseIdentifier(Name))
445 return TokError(
"expected identifier in .indirect_symbol directive");
447 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
451 return TokError(
"non-local symbol required in directive");
454 return TokError(
"unable to emit indirect symbol attribute for: " + Name);
457 return TokError(
"unexpected token in '.indirect_symbol' directive");
466 bool DarwinAsmParser::parseDirectiveDumpOrLoad(
StringRef Directive,
468 bool IsDump = Directive ==
".dump";
470 return TokError(
"expected string in '.dump' or '.load' directive");
475 return TokError(
"unexpected token in '.dump' or '.load' directive");
482 return Warning(IDLoc,
"ignoring directive .dump for now");
484 return Warning(IDLoc,
"ignoring directive .load for now");
489 bool DarwinAsmParser::parseDirectiveLinkerOption(
StringRef IDVal,
SMLoc) {
493 return TokError(
"expected string in '" +
Twine(IDVal) +
"' directive");
496 if (getParser().parseEscapedString(Data))
506 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
510 getStreamer().EmitLinkerOptions(Args);
518 if (getParser().parseIdentifier(Name))
519 return TokError(
"expected identifier in directive");
522 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
525 return TokError(
"unexpected token in '.lsym' directive");
529 if (getParser().parseExpression(Value))
533 return TokError(
"unexpected token in '.lsym' directive");
541 return TokError(
"directive '.lsym' is unsupported");
547 SMLoc Loc = getLexer().getLoc();
550 if (getParser().parseIdentifier(SectionName))
551 return Error(Loc,
"expected identifier after '.section' directive");
555 return TokError(
"unexpected token in '.section' directive");
557 std::string SectionSpec = SectionName;
562 StringRef EOL = getLexer().LexUntilEndOfStatement();
563 SectionSpec.append(EOL.
begin(), EOL.
end());
567 return TokError(
"unexpected token in '.section' directive");
575 std::string ErrorStr =
577 TAA, TAAParsed, StubSize);
579 if (!ErrorStr.empty())
580 return Error(Loc, ErrorStr.c_str());
583 bool isText = Segment ==
"__TEXT";
584 getStreamer().SwitchSection(getContext().getMachOSection(
585 Segment, Section, TAA, StubSize,
593 bool DarwinAsmParser::parseDirectivePushSection(
StringRef S,
SMLoc Loc) {
594 getStreamer().PushSection();
596 if (parseDirectiveSection(S, Loc)) {
597 getStreamer().PopSection();
606 bool DarwinAsmParser::parseDirectivePopSection(
StringRef,
SMLoc) {
607 if (!getStreamer().PopSection())
608 return TokError(
".popsection without corresponding .pushsection");
614 bool DarwinAsmParser::parseDirectivePrevious(
StringRef DirName,
SMLoc) {
616 if (!PreviousSection.first)
617 return TokError(
".previous without corresponding .section");
618 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
624 bool DarwinAsmParser::parseDirectiveSecureLogUnique(
StringRef,
SMLoc IDLoc) {
625 StringRef LogMessage = getParser().parseStringToEndOfStatement();
627 return TokError(
"unexpected token in '.secure_log_unique' directive");
629 if (getContext().getSecureLogUsed())
630 return Error(IDLoc,
".secure_log_unique specified multiple times");
633 const char *SecureLogFile = getContext().getSecureLogFile();
635 return Error(IDLoc,
".secure_log_unique used but AS_SECURE_LOG_FILE "
636 "environment variable unset.");
646 return Error(IDLoc,
Twine(
"can't open secure log file: ") +
647 SecureLogFile +
" (" + EC.message() +
")");
649 getContext().setSecureLog(OS);
653 unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
654 *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
655 <<
":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) <<
":"
656 << LogMessage +
"\n";
658 getContext().setSecureLogUsed(
true);
665 bool DarwinAsmParser::parseDirectiveSecureLogReset(
StringRef,
SMLoc IDLoc) {
667 return TokError(
"unexpected token in '.secure_log_reset' directive");
671 getContext().setSecureLogUsed(
false);
678 bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(
StringRef,
SMLoc) {
680 return TokError(
"unexpected token in '.subsections_via_symbols' directive");
692 SMLoc IDLoc = getLexer().getLoc();
694 if (getParser().parseIdentifier(Name))
695 return TokError(
"expected identifier in directive");
698 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
701 return TokError(
"unexpected token in directive");
705 SMLoc SizeLoc = getLexer().getLoc();
706 if (getParser().parseAbsoluteExpression(Size))
709 int64_t Pow2Alignment = 0;
710 SMLoc Pow2AlignmentLoc;
713 Pow2AlignmentLoc = getLexer().getLoc();
714 if (getParser().parseAbsoluteExpression(Pow2Alignment))
719 return TokError(
"unexpected token in '.tbss' directive");
724 return Error(SizeLoc,
"invalid '.tbss' directive size, can't be less than"
728 if (Pow2Alignment < 0)
729 return Error(Pow2AlignmentLoc,
"invalid '.tbss' alignment, can't be less"
733 return Error(IDLoc,
"invalid symbol redefinition");
735 getStreamer().EmitTBSSSymbol(getContext().getMachOSection(
736 "__DATA",
"__thread_bss",
739 Sym, Size, 1 << Pow2Alignment);
749 if (getParser().parseIdentifier(Segment))
750 return TokError(
"expected segment name after '.zerofill' directive");
753 return TokError(
"unexpected token in directive");
757 if (getParser().parseIdentifier(Section))
758 return TokError(
"expected section name after comma in '.zerofill' "
765 getStreamer().EmitZerofill(getContext().getMachOSection(
772 return TokError(
"unexpected token in directive");
775 SMLoc IDLoc = getLexer().getLoc();
777 if (getParser().parseIdentifier(IDStr))
778 return TokError(
"expected identifier in directive");
781 MCSymbol *Sym = getContext().getOrCreateSymbol(IDStr);
784 return TokError(
"unexpected token in directive");
788 SMLoc SizeLoc = getLexer().getLoc();
789 if (getParser().parseAbsoluteExpression(Size))
792 int64_t Pow2Alignment = 0;
793 SMLoc Pow2AlignmentLoc;
796 Pow2AlignmentLoc = getLexer().getLoc();
797 if (getParser().parseAbsoluteExpression(Pow2Alignment))
802 return TokError(
"unexpected token in '.zerofill' directive");
807 return Error(SizeLoc,
"invalid '.zerofill' directive size, can't be less "
813 if (Pow2Alignment < 0)
814 return Error(Pow2AlignmentLoc,
"invalid '.zerofill' directive alignment, "
815 "can't be less than zero");
818 return Error(IDLoc,
"invalid symbol redefinition");
823 getStreamer().EmitZerofill(getContext().getMachOSection(
826 Sym, Size, 1 << Pow2Alignment);
833 bool DarwinAsmParser::parseDirectiveDataRegion(
StringRef,
SMLoc) {
840 SMLoc Loc = getParser().getTok().getLoc();
841 if (getParser().parseIdentifier(RegionType))
842 return TokError(
"expected region type after '.data_region' directive");
849 return Error(Loc,
"unknown region type in '.data_region' directive");
858 bool DarwinAsmParser::parseDirectiveDataRegionEnd(
StringRef,
SMLoc) {
860 return TokError(
"unexpected token in '.end_data_region' directive");
870 bool DarwinAsmParser::parseVersionMin(
StringRef Directive,
SMLoc) {
871 int64_t Major = 0, Minor = 0, Update = 0;
877 return TokError(
"invalid OS major version number");
878 Major = getLexer().getTok().getIntVal();
879 if (Major > 65535 || Major <= 0)
880 return TokError(
"invalid OS major version number");
883 return TokError(
"minor OS version number required, comma expected");
887 return TokError(
"invalid OS minor version number");
888 Minor = getLexer().getTok().getIntVal();
889 if (Minor > 255 || Minor < 0)
890 return TokError(
"invalid OS minor version number");
895 return TokError(
"invalid update specifier, comma expected");
898 return TokError(
"invalid OS update number");
899 Update = getLexer().getTok().getIntVal();
900 if (Update > 255 || Update < 0)
901 return TokError(
"invalid OS update number");
914 return new DarwinAsmParser;
void push_back(const T &Elt)
F_Append - When opening a file, if it already exists append to the existing file instead of returning...
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
MCSectionMachO - This represents a section on a Mach-O system (used by Mac OS X). ...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
static SectionKind getDataRel()
MCAsmParserExtension * createDarwinAsmParser()
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
StringSwitch & Case(const char(&S)[N], const T &Value)
S_4BYTE_LITERALS - Section with 4 byte literals.
static SectionKind getBSS()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Base class for the full range of assembler expressions which are needed for parsing.
S_8BYTE_LITERALS - Section with 8 byte literals.
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
A switch()-like statement whose cases are string literals.
S_LITERAL_POINTERS - Section with pointers to literals.
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
.subsections_via_symbols (MachO)
S_THREAD_LOCAL_REGULAR - Thread local data section.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
S_CSTRING_LITERALS - Section with literal C strings.
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
S_ATTR_NO_DEAD_STRIP - No dead stripping.
static SectionKind getThreadBSS()
MachO::SectionType getType() const
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
R Default(const T &Value) const
S_16BYTE_LITERALS - Section with only 16 byte literals.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
The file should be opened in text mode on platforms that make this distinction.
A raw_ostream that writes to a file descriptor.
const ARM::ArchExtKind Kind
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
S_ZEROFILL - Zero fill on demand section.
Represents a location in source code.
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
SectionType
These are the section type and attributes fields.
static SectionKind getText()