29 template<
bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
30 void addDirectiveHandler(
StringRef Directive) {
32 this, HandleDirective<DarwinAsmParser, HandlerMethod>);
33 getParser().addDirectiveHandler(Directive, Handler);
36 bool ParseSectionSwitch(
const char *Segment,
const char *
Section,
37 unsigned TAA = 0,
unsigned ImplicitAlign = 0,
38 unsigned StubSize = 0);
47 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDesc>(
".desc");
48 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveIndirectSymbol>(
50 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveLsym>(
".lsym");
51 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols>(
52 ".subsections_via_symbols");
53 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(
".dump");
54 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(
".load");
55 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSection>(
".section");
56 addDirectiveHandler<&DarwinAsmParser::ParseDirectivePushSection>(
58 addDirectiveHandler<&DarwinAsmParser::ParseDirectivePopSection>(
60 addDirectiveHandler<&DarwinAsmParser::ParseDirectivePrevious>(
".previous");
61 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogUnique>(
62 ".secure_log_unique");
63 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogReset>(
65 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveTBSS>(
".tbss");
66 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveZerofill>(
".zerofill");
68 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegion>(
70 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegionEnd>(
74 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveBss>(
".bss");
75 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConst>(
".const");
76 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstData>(
78 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstructor>(
80 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveCString>(
82 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveData>(
".data");
83 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDestructor>(
85 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDyld>(
".dyld");
86 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit0>(
88 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit1>(
91 &DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>(
92 ".lazy_symbol_pointer");
93 addDirectiveHandler<&DarwinAsmParser::ParseDirectiveLinkerOption>(
95 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>(
97 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>(
99 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral8>(
101 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModInitFunc>(
103 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModTermFunc>(
106 &DarwinAsmParser::ParseSectionDirectiveNonLazySymbolPointers>(
107 ".non_lazy_symbol_pointer");
108 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatClsMeth>(
109 ".objc_cat_cls_meth");
110 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatInstMeth>(
111 ".objc_cat_inst_meth");
112 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCategory>(
114 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClass>(
116 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassNames>(
117 ".objc_class_names");
118 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassVars>(
120 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsMeth>(
122 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsRefs>(
124 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstMeth>(
127 &DarwinAsmParser::ParseSectionDirectiveObjCInstanceVars>(
128 ".objc_instance_vars");
129 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMessageRefs>(
130 ".objc_message_refs");
131 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMetaClass>(
134 &DarwinAsmParser::ParseSectionDirectiveObjCMethVarNames>(
135 ".objc_meth_var_names");
137 &DarwinAsmParser::ParseSectionDirectiveObjCMethVarTypes>(
138 ".objc_meth_var_types");
139 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCModuleInfo>(
140 ".objc_module_info");
141 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCProtocol>(
144 &DarwinAsmParser::ParseSectionDirectiveObjCSelectorStrs>(
145 ".objc_selector_strs");
147 &DarwinAsmParser::ParseSectionDirectiveObjCStringObject>(
148 ".objc_string_object");
149 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSymbols>(
151 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectivePICSymbolStub>(
153 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticConst>(
155 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticData>(
157 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveSymbolStub>(
159 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTData>(
".tdata");
160 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveText>(
".text");
161 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveThreadInitFunc>(
162 ".thread_init_func");
163 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTLV>(
".tlv");
165 addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveIdent>(
".ident");
187 return ParseSectionSwitch(
"__DATA",
"__bss");
191 return ParseSectionSwitch(
"__TEXT",
"__const");
194 return ParseSectionSwitch(
"__TEXT",
"__static_const");
197 return ParseSectionSwitch(
"__TEXT",
"__cstring",
201 return ParseSectionSwitch(
"__TEXT",
"__literal4",
205 return ParseSectionSwitch(
"__TEXT",
"__literal8",
209 return ParseSectionSwitch(
"__TEXT",
"__literal16",
213 return ParseSectionSwitch(
"__TEXT",
"__constructor");
216 return ParseSectionSwitch(
"__TEXT",
"__destructor");
219 return ParseSectionSwitch(
"__TEXT",
"__fvmlib_init0");
222 return ParseSectionSwitch(
"__TEXT",
"__fvmlib_init1");
225 return ParseSectionSwitch(
"__TEXT",
"__symbol_stub",
227 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
232 return ParseSectionSwitch(
"__TEXT",
"__picsymbol_stub",
234 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
237 return ParseSectionSwitch(
"__DATA",
"__data");
240 return ParseSectionSwitch(
"__DATA",
"__static_data");
242 bool ParseSectionDirectiveNonLazySymbolPointers(
StringRef,
SMLoc) {
243 return ParseSectionSwitch(
"__DATA",
"__nl_symbol_ptr",
247 return ParseSectionSwitch(
"__DATA",
"__la_symbol_ptr",
251 return ParseSectionSwitch(
"__DATA",
"__dyld");
254 return ParseSectionSwitch(
"__DATA",
"__mod_init_func",
258 return ParseSectionSwitch(
"__DATA",
"__mod_term_func",
262 return ParseSectionSwitch(
"__DATA",
"__const");
265 return ParseSectionSwitch(
"__OBJC",
"__class",
266 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
269 return ParseSectionSwitch(
"__OBJC",
"__meta_class",
270 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
273 return ParseSectionSwitch(
"__OBJC",
"__cat_cls_meth",
274 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
277 return ParseSectionSwitch(
"__OBJC",
"__cat_inst_meth",
278 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
281 return ParseSectionSwitch(
"__OBJC",
"__protocol",
282 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
285 return ParseSectionSwitch(
"__OBJC",
"__string_object",
286 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
289 return ParseSectionSwitch(
"__OBJC",
"__cls_meth",
290 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
293 return ParseSectionSwitch(
"__OBJC",
"__inst_meth",
294 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
297 return ParseSectionSwitch(
"__OBJC",
"__cls_refs",
298 MCSectionMachO::S_ATTR_NO_DEAD_STRIP |
302 return ParseSectionSwitch(
"__OBJC",
"__message_refs",
303 MCSectionMachO::S_ATTR_NO_DEAD_STRIP |
307 return ParseSectionSwitch(
"__OBJC",
"__symbols",
308 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
311 return ParseSectionSwitch(
"__OBJC",
"__category",
312 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
315 return ParseSectionSwitch(
"__OBJC",
"__class_vars",
316 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
319 return ParseSectionSwitch(
"__OBJC",
"__instance_vars",
320 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
323 return ParseSectionSwitch(
"__OBJC",
"__module_info",
324 MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
327 return ParseSectionSwitch(
"__TEXT",
"__cstring",
331 return ParseSectionSwitch(
"__TEXT",
"__cstring",
335 return ParseSectionSwitch(
"__TEXT",
"__cstring",
339 return ParseSectionSwitch(
"__OBJC",
"__selector_strs",
343 return ParseSectionSwitch(
"__DATA",
"__thread_data",
347 return ParseSectionSwitch(
"__TEXT",
"__text",
348 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
351 return ParseSectionSwitch(
"__DATA",
"__thread_vars",
356 getParser().eatToEndOfStatement();
360 return ParseSectionSwitch(
"__DATA",
"__thread_init",
368 bool DarwinAsmParser::ParseSectionSwitch(
const char *Segment,
370 unsigned TAA,
unsigned Align,
373 return TokError(
"unexpected token in section switching directive");
377 bool isText = TAA & MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS;
378 getStreamer().SwitchSection(getContext().getMachOSection(
379 Segment, Section, TAA, StubSize,
392 getStreamer().EmitValueToAlignment(Align, 0, 1, 0);
401 if (getParser().parseIdentifier(Name))
402 return TokError(
"expected identifier in directive");
405 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
408 return TokError(
"unexpected token in '.desc' directive");
412 if (getParser().parseAbsoluteExpression(DescValue))
416 return TokError(
"unexpected token in '.desc' directive");
421 getStreamer().EmitSymbolDesc(Sym, DescValue);
428 bool DarwinAsmParser::ParseDirectiveIndirectSymbol(
StringRef,
SMLoc Loc) {
430 getStreamer().getCurrentSection().first);
435 return Error(Loc,
"indirect symbol not in a symbol pointer or stub "
439 if (getParser().parseIdentifier(Name))
440 return TokError(
"expected identifier in .indirect_symbol directive");
442 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
446 return TokError(
"non-local symbol required in directive");
449 return TokError(
"unable to emit indirect symbol attribute for: " + Name);
452 return TokError(
"unexpected token in '.indirect_symbol' directive");
461 bool DarwinAsmParser::ParseDirectiveDumpOrLoad(
StringRef Directive,
463 bool IsDump = Directive ==
".dump";
465 return TokError(
"expected string in '.dump' or '.load' directive");
470 return TokError(
"unexpected token in '.dump' or '.load' directive");
477 return Warning(IDLoc,
"ignoring directive .dump for now");
479 return Warning(IDLoc,
"ignoring directive .load for now");
484 bool DarwinAsmParser::ParseDirectiveLinkerOption(
StringRef IDVal,
SMLoc) {
488 return TokError(
"expected string in '" +
Twine(IDVal) +
"' directive");
491 if (getParser().parseEscapedString(Data))
501 return TokError(
"unexpected token in '" +
Twine(IDVal) +
"' directive");
505 getStreamer().EmitLinkerOptions(Args);
513 if (getParser().parseIdentifier(Name))
514 return TokError(
"expected identifier in directive");
517 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
520 return TokError(
"unexpected token in '.lsym' directive");
524 if (getParser().parseExpression(Value))
528 return TokError(
"unexpected token in '.lsym' directive");
536 return TokError(
"directive '.lsym' is unsupported");
542 SMLoc Loc = getLexer().getLoc();
545 if (getParser().parseIdentifier(SectionName))
546 return Error(Loc,
"expected identifier after '.section' directive");
550 return TokError(
"unexpected token in '.section' directive");
552 std::string SectionSpec = SectionName;
557 StringRef EOL = getLexer().LexUntilEndOfStatement();
558 SectionSpec.append(EOL.
begin(), EOL.
end());
562 return TokError(
"unexpected token in '.section' directive");
570 std::string ErrorStr =
572 TAA, TAAParsed, StubSize);
574 if (!ErrorStr.empty())
575 return Error(Loc, ErrorStr.c_str());
578 bool isText = Segment ==
"__TEXT";
579 getStreamer().SwitchSection(getContext().getMachOSection(
580 Segment, Section, TAA, StubSize,
588 bool DarwinAsmParser::ParseDirectivePushSection(
StringRef S,
SMLoc Loc) {
589 getStreamer().PushSection();
591 if (ParseDirectiveSection(S, Loc)) {
592 getStreamer().PopSection();
601 bool DarwinAsmParser::ParseDirectivePopSection(
StringRef,
SMLoc) {
602 if (!getStreamer().PopSection())
603 return TokError(
".popsection without corresponding .pushsection");
609 bool DarwinAsmParser::ParseDirectivePrevious(
StringRef DirName,
SMLoc) {
611 if (PreviousSection.first == NULL)
612 return TokError(
".previous without corresponding .section");
613 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
619 bool DarwinAsmParser::ParseDirectiveSecureLogUnique(
StringRef,
SMLoc IDLoc) {
620 StringRef LogMessage = getParser().parseStringToEndOfStatement();
622 return TokError(
"unexpected token in '.secure_log_unique' directive");
624 if (getContext().getSecureLogUsed() !=
false)
625 return Error(IDLoc,
".secure_log_unique specified multiple times");
628 const char *SecureLogFile = getContext().getSecureLogFile();
629 if (SecureLogFile == NULL)
630 return Error(IDLoc,
".secure_log_unique used but AS_SECURE_LOG_FILE "
631 "environment variable unset.");
640 return Error(IDLoc,
Twine(
"can't open secure log file: ") +
641 SecureLogFile +
" (" + Err +
")");
643 getContext().setSecureLog(OS);
647 int CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
648 *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
649 <<
":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) <<
":"
650 << LogMessage +
"\n";
652 getContext().setSecureLogUsed(
true);
659 bool DarwinAsmParser::ParseDirectiveSecureLogReset(
StringRef,
SMLoc IDLoc) {
661 return TokError(
"unexpected token in '.secure_log_reset' directive");
665 getContext().setSecureLogUsed(
false);
672 bool DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols(
StringRef,
SMLoc) {
674 return TokError(
"unexpected token in '.subsections_via_symbols' directive");
686 SMLoc IDLoc = getLexer().getLoc();
688 if (getParser().parseIdentifier(Name))
689 return TokError(
"expected identifier in directive");
692 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
695 return TokError(
"unexpected token in directive");
699 SMLoc SizeLoc = getLexer().getLoc();
700 if (getParser().parseAbsoluteExpression(Size))
703 int64_t Pow2Alignment = 0;
704 SMLoc Pow2AlignmentLoc;
707 Pow2AlignmentLoc = getLexer().getLoc();
708 if (getParser().parseAbsoluteExpression(Pow2Alignment))
713 return TokError(
"unexpected token in '.tbss' directive");
718 return Error(SizeLoc,
"invalid '.tbss' directive size, can't be less than"
722 if (Pow2Alignment < 0)
723 return Error(Pow2AlignmentLoc,
"invalid '.tbss' alignment, can't be less"
727 return Error(IDLoc,
"invalid symbol redefinition");
729 getStreamer().EmitTBSSSymbol(getContext().getMachOSection(
730 "__DATA",
"__thread_bss",
733 Sym, Size, 1 << Pow2Alignment);
743 if (getParser().parseIdentifier(Segment))
744 return TokError(
"expected segment name after '.zerofill' directive");
747 return TokError(
"unexpected token in directive");
751 if (getParser().parseIdentifier(Section))
752 return TokError(
"expected section name after comma in '.zerofill' "
759 getStreamer().EmitZerofill(getContext().getMachOSection(
766 return TokError(
"unexpected token in directive");
769 SMLoc IDLoc = getLexer().getLoc();
771 if (getParser().parseIdentifier(IDStr))
772 return TokError(
"expected identifier in directive");
775 MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr);
778 return TokError(
"unexpected token in directive");
782 SMLoc SizeLoc = getLexer().getLoc();
783 if (getParser().parseAbsoluteExpression(Size))
786 int64_t Pow2Alignment = 0;
787 SMLoc Pow2AlignmentLoc;
790 Pow2AlignmentLoc = getLexer().getLoc();
791 if (getParser().parseAbsoluteExpression(Pow2Alignment))
796 return TokError(
"unexpected token in '.zerofill' directive");
801 return Error(SizeLoc,
"invalid '.zerofill' directive size, can't be less "
807 if (Pow2Alignment < 0)
808 return Error(Pow2AlignmentLoc,
"invalid '.zerofill' directive alignment, "
809 "can't be less than zero");
812 return Error(IDLoc,
"invalid symbol redefinition");
817 getStreamer().EmitZerofill(getContext().getMachOSection(
820 Sym, Size, 1 << Pow2Alignment);
827 bool DarwinAsmParser::ParseDirectiveDataRegion(
StringRef,
SMLoc) {
834 SMLoc Loc = getParser().getTok().getLoc();
835 if (getParser().parseIdentifier(RegionType))
836 return TokError(
"expected region type after '.data_region' directive");
843 return Error(Loc,
"unknown region type in '.data_region' directive");
852 bool DarwinAsmParser::ParseDirectiveDataRegionEnd(
StringRef,
SMLoc) {
854 return TokError(
"unexpected token in '.end_data_region' directive");
864 return new DarwinAsmParser;
void push_back(const T &Elt)
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser. The extension should use the AsmParser i...
static SectionKind getDataRel()
MCAsmParserExtension * createDarwinAsmParser()
StringSwitch & Case(const char(&S)[N], const T &Value)
static SectionKind getBSS()
A switch()-like statement whose cases are string literals.
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
.subsections_via_symbols (MachO)
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
static SectionKind getThreadBSS()
std::pair< const MCSection *, const MCExpr * > MCSectionSubPair
R Default(const T &Value) const
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
LLVM Value Representation.
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Represents a location in source code.
static SectionKind getText()