blob: 94aa70ef0326aa7659badc4cdb8bccdc7fa854e9 [file] [log] [blame]
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +00001//===- DarwinAsmParser.cpp - Darwin (Mach-O) Assembly Parser --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCParser/MCAsmParserExtension.h"
Rafael Espindolac49ac5e2015-12-16 23:49:14 +000011#include "llvm/ADT/STLExtras.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "llvm/ADT/StringRef.h"
13#include "llvm/ADT/StringSwitch.h"
Akira Hatanaka8ad73992015-10-15 05:28:38 +000014#include "llvm/ADT/Triple.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/Twine.h"
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000016#include "llvm/MC/MCContext.h"
Akira Hatanaka8ad73992015-10-15 05:28:38 +000017#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/MC/MCParser/MCAsmLexer.h"
19#include "llvm/MC/MCParser/MCAsmParser.h"
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000020#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MCStreamer.h"
22#include "llvm/MC/MCSymbol.h"
Benjamin Kramerd59664f2014-04-29 23:26:49 +000023#include "llvm/Support/FileSystem.h"
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000024#include "llvm/Support/MemoryBuffer.h"
25#include "llvm/Support/SourceMgr.h"
26using namespace llvm;
27
28namespace {
29
30/// \brief Implementation of directive handling which is shared across all
31/// Darwin targets.
32class DarwinAsmParser : public MCAsmParserExtension {
Eli Bendersky29b9f472013-01-16 00:50:52 +000033 template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
Jim Grosbachd2037eb2013-02-20 22:21:35 +000034 void addDirectiveHandler(StringRef Directive) {
Eli Bendersky29b9f472013-01-16 00:50:52 +000035 MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
36 this, HandleDirective<DarwinAsmParser, HandlerMethod>);
Jim Grosbachd2037eb2013-02-20 22:21:35 +000037 getParser().addDirectiveHandler(Directive, Handler);
Daniel Dunbar8897d472010-07-18 22:22:07 +000038 }
39
Mehdi Amini215ff8d2016-10-05 01:02:22 +000040 bool parseSectionSwitch(StringRef Segment, StringRef Section,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000041 unsigned TAA = 0, unsigned ImplicitAlign = 0,
42 unsigned StubSize = 0);
43
Tim Northover2d4d1612015-10-28 22:36:05 +000044 SMLoc LastVersionMinDirective;
45
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000046public:
47 DarwinAsmParser() {}
48
Craig Topper59be68f2014-03-08 07:14:16 +000049 void Initialize(MCAsmParser &Parser) override {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000050 // Call the base implementation.
51 this->MCAsmParserExtension::Initialize(Parser);
52
Lang Hamesf9033bb2016-04-11 18:33:45 +000053 addDirectiveHandler<&DarwinAsmParser::parseDirectiveAltEntry>(".alt_entry");
Jim Grosbach319026d2014-03-18 22:09:10 +000054 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(".desc");
55 addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>(
Kevin Enderby3aeada22013-08-28 17:50:59 +000056 ".indirect_symbol");
Jim Grosbach319026d2014-03-18 22:09:10 +000057 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(".lsym");
58 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>(
Daniel Dunbar8897d472010-07-18 22:22:07 +000059 ".subsections_via_symbols");
Jim Grosbach319026d2014-03-18 22:09:10 +000060 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".dump");
61 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".load");
62 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(".section");
63 addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000064 ".pushsection");
Jim Grosbach319026d2014-03-18 22:09:10 +000065 addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000066 ".popsection");
Jim Grosbach319026d2014-03-18 22:09:10 +000067 addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(".previous");
68 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>(
Daniel Dunbar8897d472010-07-18 22:22:07 +000069 ".secure_log_unique");
Jim Grosbach319026d2014-03-18 22:09:10 +000070 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>(
Daniel Dunbar8897d472010-07-18 22:22:07 +000071 ".secure_log_reset");
Jim Grosbach319026d2014-03-18 22:09:10 +000072 addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(".tbss");
73 addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(".zerofill");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000074
Jim Grosbach319026d2014-03-18 22:09:10 +000075 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000076 ".data_region");
Jim Grosbach319026d2014-03-18 22:09:10 +000077 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000078 ".end_data_region");
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000079
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +000080 // Special section directives.
Jim Grosbach319026d2014-03-18 22:09:10 +000081 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(".bss");
82 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(".const");
83 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000084 ".const_data");
Jim Grosbach319026d2014-03-18 22:09:10 +000085 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000086 ".constructor");
Jim Grosbach319026d2014-03-18 22:09:10 +000087 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000088 ".cstring");
Jim Grosbach319026d2014-03-18 22:09:10 +000089 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(".data");
90 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000091 ".destructor");
Jim Grosbach319026d2014-03-18 22:09:10 +000092 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(".dyld");
93 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000094 ".fvmlib_init0");
Jim Grosbach319026d2014-03-18 22:09:10 +000095 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000096 ".fvmlib_init1");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000097 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +000098 &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +000099 ".lazy_symbol_pointer");
Jim Grosbach319026d2014-03-18 22:09:10 +0000100 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>(
Daniel Dunbar16004b82013-01-18 01:25:48 +0000101 ".linker_option");
Jim Grosbach319026d2014-03-18 22:09:10 +0000102 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000103 ".literal16");
Jim Grosbach319026d2014-03-18 22:09:10 +0000104 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000105 ".literal4");
Jim Grosbach319026d2014-03-18 22:09:10 +0000106 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000107 ".literal8");
Jim Grosbach319026d2014-03-18 22:09:10 +0000108 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000109 ".mod_init_func");
Jim Grosbach319026d2014-03-18 22:09:10 +0000110 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000111 ".mod_term_func");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000112 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000113 &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000114 ".non_lazy_symbol_pointer");
Tim Northover5c3140f2016-04-25 21:12:04 +0000115 addDirectiveHandler<
116 &DarwinAsmParser::parseSectionDirectiveThreadLocalVariablePointers>(
117 ".thread_local_variable_pointer");
Jim Grosbach319026d2014-03-18 22:09:10 +0000118 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000119 ".objc_cat_cls_meth");
Jim Grosbach319026d2014-03-18 22:09:10 +0000120 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000121 ".objc_cat_inst_meth");
Jim Grosbach319026d2014-03-18 22:09:10 +0000122 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000123 ".objc_category");
Jim Grosbach319026d2014-03-18 22:09:10 +0000124 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000125 ".objc_class");
Jim Grosbach319026d2014-03-18 22:09:10 +0000126 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000127 ".objc_class_names");
Jim Grosbach319026d2014-03-18 22:09:10 +0000128 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000129 ".objc_class_vars");
Jim Grosbach319026d2014-03-18 22:09:10 +0000130 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000131 ".objc_cls_meth");
Jim Grosbach319026d2014-03-18 22:09:10 +0000132 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000133 ".objc_cls_refs");
Jim Grosbach319026d2014-03-18 22:09:10 +0000134 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000135 ".objc_inst_meth");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000136 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000137 &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000138 ".objc_instance_vars");
Jim Grosbach319026d2014-03-18 22:09:10 +0000139 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000140 ".objc_message_refs");
Jim Grosbach319026d2014-03-18 22:09:10 +0000141 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000142 ".objc_meta_class");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000143 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000144 &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000145 ".objc_meth_var_names");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000146 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000147 &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000148 ".objc_meth_var_types");
Jim Grosbach319026d2014-03-18 22:09:10 +0000149 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000150 ".objc_module_info");
Jim Grosbach319026d2014-03-18 22:09:10 +0000151 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000152 ".objc_protocol");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000153 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000154 &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000155 ".objc_selector_strs");
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000156 addDirectiveHandler<
Jim Grosbach319026d2014-03-18 22:09:10 +0000157 &DarwinAsmParser::parseSectionDirectiveObjCStringObject>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000158 ".objc_string_object");
Jim Grosbach319026d2014-03-18 22:09:10 +0000159 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000160 ".objc_symbols");
Jim Grosbach319026d2014-03-18 22:09:10 +0000161 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000162 ".picsymbol_stub");
Jim Grosbach319026d2014-03-18 22:09:10 +0000163 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000164 ".static_const");
Jim Grosbach319026d2014-03-18 22:09:10 +0000165 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000166 ".static_data");
Jim Grosbach319026d2014-03-18 22:09:10 +0000167 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000168 ".symbol_stub");
Jim Grosbach319026d2014-03-18 22:09:10 +0000169 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(".tdata");
170 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(".text");
171 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>(
Daniel Dunbarb94c5782013-01-18 01:25:25 +0000172 ".thread_init_func");
Jim Grosbach319026d2014-03-18 22:09:10 +0000173 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv");
Jim Grosbach14be61a2011-03-08 19:17:19 +0000174
Jim Grosbach319026d2014-03-18 22:09:10 +0000175 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident");
Tim Northover2d4d1612015-10-28 22:36:05 +0000176 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
177 ".watchos_version_min");
178 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".tvos_version_min");
Jim Grosbach319026d2014-03-18 22:09:10 +0000179 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".ios_version_min");
180 addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
Jim Grosbach448334a2014-03-18 22:09:05 +0000181 ".macosx_version_min");
Tim Northover2d4d1612015-10-28 22:36:05 +0000182
183 LastVersionMinDirective = SMLoc();
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000184 }
185
Lang Hamesf9033bb2016-04-11 18:33:45 +0000186 bool parseDirectiveAltEntry(StringRef, SMLoc);
Jim Grosbach319026d2014-03-18 22:09:10 +0000187 bool parseDirectiveDesc(StringRef, SMLoc);
188 bool parseDirectiveIndirectSymbol(StringRef, SMLoc);
189 bool parseDirectiveDumpOrLoad(StringRef, SMLoc);
190 bool parseDirectiveLsym(StringRef, SMLoc);
191 bool parseDirectiveLinkerOption(StringRef, SMLoc);
192 bool parseDirectiveSection(StringRef, SMLoc);
193 bool parseDirectivePushSection(StringRef, SMLoc);
194 bool parseDirectivePopSection(StringRef, SMLoc);
195 bool parseDirectivePrevious(StringRef, SMLoc);
196 bool parseDirectiveSecureLogReset(StringRef, SMLoc);
197 bool parseDirectiveSecureLogUnique(StringRef, SMLoc);
198 bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
199 bool parseDirectiveTBSS(StringRef, SMLoc);
200 bool parseDirectiveZerofill(StringRef, SMLoc);
201 bool parseDirectiveDataRegion(StringRef, SMLoc);
202 bool parseDirectiveDataRegionEnd(StringRef, SMLoc);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000203
204 // Named Section Directive
Jim Grosbach319026d2014-03-18 22:09:10 +0000205 bool parseSectionDirectiveBss(StringRef, SMLoc) {
206 return parseSectionSwitch("__DATA", "__bss");
Rafael Espindola3402c052013-10-02 14:09:29 +0000207 }
208
Jim Grosbach319026d2014-03-18 22:09:10 +0000209 bool parseSectionDirectiveConst(StringRef, SMLoc) {
210 return parseSectionSwitch("__TEXT", "__const");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000211 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000212 bool parseSectionDirectiveStaticConst(StringRef, SMLoc) {
213 return parseSectionSwitch("__TEXT", "__static_const");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000214 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000215 bool parseSectionDirectiveCString(StringRef, SMLoc) {
216 return parseSectionSwitch("__TEXT","__cstring",
David Majnemer7b583052014-03-07 07:36:05 +0000217 MachO::S_CSTRING_LITERALS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000218 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000219 bool parseSectionDirectiveLiteral4(StringRef, SMLoc) {
220 return parseSectionSwitch("__TEXT", "__literal4",
David Majnemer7b583052014-03-07 07:36:05 +0000221 MachO::S_4BYTE_LITERALS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000222 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000223 bool parseSectionDirectiveLiteral8(StringRef, SMLoc) {
224 return parseSectionSwitch("__TEXT", "__literal8",
David Majnemer7b583052014-03-07 07:36:05 +0000225 MachO::S_8BYTE_LITERALS, 8);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000226 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000227 bool parseSectionDirectiveLiteral16(StringRef, SMLoc) {
228 return parseSectionSwitch("__TEXT","__literal16",
David Majnemer7b583052014-03-07 07:36:05 +0000229 MachO::S_16BYTE_LITERALS, 16);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000230 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000231 bool parseSectionDirectiveConstructor(StringRef, SMLoc) {
232 return parseSectionSwitch("__TEXT","__constructor");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000233 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000234 bool parseSectionDirectiveDestructor(StringRef, SMLoc) {
235 return parseSectionSwitch("__TEXT","__destructor");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000236 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000237 bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) {
238 return parseSectionSwitch("__TEXT","__fvmlib_init0");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000239 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000240 bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) {
241 return parseSectionSwitch("__TEXT","__fvmlib_init1");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000242 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000243 bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
244 return parseSectionSwitch("__TEXT","__symbol_stub",
David Majnemer7b583052014-03-07 07:36:05 +0000245 MachO::S_SYMBOL_STUBS |
246 MachO::S_ATTR_PURE_INSTRUCTIONS,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000247 // FIXME: Different on PPC and ARM.
248 0, 16);
249 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000250 bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
251 return parseSectionSwitch("__TEXT","__picsymbol_stub",
David Majnemer7b583052014-03-07 07:36:05 +0000252 MachO::S_SYMBOL_STUBS |
253 MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000254 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000255 bool parseSectionDirectiveData(StringRef, SMLoc) {
256 return parseSectionSwitch("__DATA", "__data");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000257 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000258 bool parseSectionDirectiveStaticData(StringRef, SMLoc) {
259 return parseSectionSwitch("__DATA", "__static_data");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000260 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000261 bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) {
262 return parseSectionSwitch("__DATA", "__nl_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000263 MachO::S_NON_LAZY_SYMBOL_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000264 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000265 bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) {
266 return parseSectionSwitch("__DATA", "__la_symbol_ptr",
David Majnemer7b583052014-03-07 07:36:05 +0000267 MachO::S_LAZY_SYMBOL_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000268 }
Tim Northover5c3140f2016-04-25 21:12:04 +0000269 bool parseSectionDirectiveThreadLocalVariablePointers(StringRef, SMLoc) {
270 return parseSectionSwitch("__DATA", "__thread_ptr",
271 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, 4);
272 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000273 bool parseSectionDirectiveDyld(StringRef, SMLoc) {
274 return parseSectionSwitch("__DATA", "__dyld");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000275 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000276 bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) {
277 return parseSectionSwitch("__DATA", "__mod_init_func",
David Majnemer7b583052014-03-07 07:36:05 +0000278 MachO::S_MOD_INIT_FUNC_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000279 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000280 bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) {
281 return parseSectionSwitch("__DATA", "__mod_term_func",
David Majnemer7b583052014-03-07 07:36:05 +0000282 MachO::S_MOD_TERM_FUNC_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000283 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000284 bool parseSectionDirectiveConstData(StringRef, SMLoc) {
285 return parseSectionSwitch("__DATA", "__const");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000286 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000287 bool parseSectionDirectiveObjCClass(StringRef, SMLoc) {
288 return parseSectionSwitch("__OBJC", "__class",
David Majnemer7b583052014-03-07 07:36:05 +0000289 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000290 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000291 bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) {
292 return parseSectionSwitch("__OBJC", "__meta_class",
David Majnemer7b583052014-03-07 07:36:05 +0000293 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000294 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000295 bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) {
296 return parseSectionSwitch("__OBJC", "__cat_cls_meth",
David Majnemer7b583052014-03-07 07:36:05 +0000297 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000298 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000299 bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) {
300 return parseSectionSwitch("__OBJC", "__cat_inst_meth",
David Majnemer7b583052014-03-07 07:36:05 +0000301 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000302 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000303 bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) {
304 return parseSectionSwitch("__OBJC", "__protocol",
David Majnemer7b583052014-03-07 07:36:05 +0000305 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000306 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000307 bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) {
308 return parseSectionSwitch("__OBJC", "__string_object",
David Majnemer7b583052014-03-07 07:36:05 +0000309 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000310 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000311 bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) {
312 return parseSectionSwitch("__OBJC", "__cls_meth",
David Majnemer7b583052014-03-07 07:36:05 +0000313 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000314 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000315 bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) {
316 return parseSectionSwitch("__OBJC", "__inst_meth",
David Majnemer7b583052014-03-07 07:36:05 +0000317 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000318 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000319 bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
320 return parseSectionSwitch("__OBJC", "__cls_refs",
David Majnemer7b583052014-03-07 07:36:05 +0000321 MachO::S_ATTR_NO_DEAD_STRIP |
322 MachO::S_LITERAL_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000323 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000324 bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
325 return parseSectionSwitch("__OBJC", "__message_refs",
David Majnemer7b583052014-03-07 07:36:05 +0000326 MachO::S_ATTR_NO_DEAD_STRIP |
327 MachO::S_LITERAL_POINTERS, 4);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000328 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000329 bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
330 return parseSectionSwitch("__OBJC", "__symbols",
David Majnemer7b583052014-03-07 07:36:05 +0000331 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000332 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000333 bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) {
334 return parseSectionSwitch("__OBJC", "__category",
David Majnemer7b583052014-03-07 07:36:05 +0000335 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000336 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000337 bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) {
338 return parseSectionSwitch("__OBJC", "__class_vars",
David Majnemer7b583052014-03-07 07:36:05 +0000339 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000340 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000341 bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) {
342 return parseSectionSwitch("__OBJC", "__instance_vars",
David Majnemer7b583052014-03-07 07:36:05 +0000343 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000344 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000345 bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) {
346 return parseSectionSwitch("__OBJC", "__module_info",
David Majnemer7b583052014-03-07 07:36:05 +0000347 MachO::S_ATTR_NO_DEAD_STRIP);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000348 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000349 bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) {
350 return parseSectionSwitch("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +0000351 MachO::S_CSTRING_LITERALS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000352 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000353 bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) {
354 return parseSectionSwitch("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +0000355 MachO::S_CSTRING_LITERALS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000356 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000357 bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) {
358 return parseSectionSwitch("__TEXT", "__cstring",
David Majnemer7b583052014-03-07 07:36:05 +0000359 MachO::S_CSTRING_LITERALS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000360 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000361 bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) {
362 return parseSectionSwitch("__OBJC", "__selector_strs",
David Majnemer7b583052014-03-07 07:36:05 +0000363 MachO::S_CSTRING_LITERALS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000364 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000365 bool parseSectionDirectiveTData(StringRef, SMLoc) {
366 return parseSectionSwitch("__DATA", "__thread_data",
David Majnemer7b583052014-03-07 07:36:05 +0000367 MachO::S_THREAD_LOCAL_REGULAR);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000368 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000369 bool parseSectionDirectiveText(StringRef, SMLoc) {
370 return parseSectionSwitch("__TEXT", "__text",
David Majnemer7b583052014-03-07 07:36:05 +0000371 MachO::S_ATTR_PURE_INSTRUCTIONS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000372 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000373 bool parseSectionDirectiveTLV(StringRef, SMLoc) {
374 return parseSectionSwitch("__DATA", "__thread_vars",
David Majnemer7b583052014-03-07 07:36:05 +0000375 MachO::S_THREAD_LOCAL_VARIABLES);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000376 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000377 bool parseSectionDirectiveIdent(StringRef, SMLoc) {
Jim Grosbach14be61a2011-03-08 19:17:19 +0000378 // Darwin silently ignores the .ident directive.
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000379 getParser().eatToEndOfStatement();
Jim Grosbach14be61a2011-03-08 19:17:19 +0000380 return false;
381 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000382 bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
383 return parseSectionSwitch("__DATA", "__thread_init",
David Majnemer7b583052014-03-07 07:36:05 +0000384 MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000385 }
Jim Grosbach319026d2014-03-18 22:09:10 +0000386 bool parseVersionMin(StringRef, SMLoc);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000387
388};
389
Bill Wendlingce4fe412012-08-08 06:30:30 +0000390} // end anonymous namespace
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000391
Mehdi Amini215ff8d2016-10-05 01:02:22 +0000392bool DarwinAsmParser::parseSectionSwitch(StringRef Segment, StringRef Section,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000393 unsigned TAA, unsigned Align,
394 unsigned StubSize) {
395 if (getLexer().isNot(AsmToken::EndOfStatement))
396 return TokError("unexpected token in section switching directive");
397 Lex();
398
399 // FIXME: Arch specific.
David Majnemer7b583052014-03-07 07:36:05 +0000400 bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS;
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000401 getStreamer().SwitchSection(getContext().getMachOSection(
Rafael Espindola449711c2015-11-18 06:02:15 +0000402 Segment, Section, TAA, StubSize,
403 isText ? SectionKind::getText() : SectionKind::getData()));
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000404
405 // Set the implicit alignment, if any.
406 //
407 // FIXME: This isn't really what 'as' does; I think it just uses the implicit
408 // alignment on the section (e.g., if one manually inserts bytes into the
Bill Wendling5391eb62010-10-19 10:18:23 +0000409 // section, then just issuing the section switch directive will not realign
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000410 // the section. However, this is arguably more reasonable behavior, and there
411 // is no good reason for someone to intentionally emit incorrectly sized
412 // values into the implicitly aligned sections.
413 if (Align)
Rafael Espindola7b514962014-02-04 18:34:04 +0000414 getStreamer().EmitValueToAlignment(Align);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000415
416 return false;
417}
418
Lang Hamesf9033bb2016-04-11 18:33:45 +0000419/// parseDirectiveAltEntry
420/// ::= .alt_entry identifier
421bool DarwinAsmParser::parseDirectiveAltEntry(StringRef, SMLoc) {
422 StringRef Name;
423 if (getParser().parseIdentifier(Name))
424 return TokError("expected identifier in directive");
425
426 // Look up symbol.
427 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
428
429 if (Sym->isDefined())
430 return TokError(".alt_entry must preceed symbol definition");
431
432 if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_AltEntry))
433 return TokError("unable to emit symbol attribute");
434
435 Lex();
436 return false;
437}
438
Jim Grosbach319026d2014-03-18 22:09:10 +0000439/// parseDirectiveDesc
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000440/// ::= .desc identifier , expression
Jim Grosbach319026d2014-03-18 22:09:10 +0000441bool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000442 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000443 if (getParser().parseIdentifier(Name))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000444 return TokError("expected identifier in directive");
445
446 // Handle the identifier as the key symbol.
Jim Grosbach6f482002015-05-18 18:43:14 +0000447 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000448
449 if (getLexer().isNot(AsmToken::Comma))
450 return TokError("unexpected token in '.desc' directive");
451 Lex();
452
453 int64_t DescValue;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000454 if (getParser().parseAbsoluteExpression(DescValue))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000455 return true;
456
457 if (getLexer().isNot(AsmToken::EndOfStatement))
458 return TokError("unexpected token in '.desc' directive");
459
460 Lex();
461
462 // Set the n_desc field of this Symbol to this DescValue
463 getStreamer().EmitSymbolDesc(Sym, DescValue);
464
465 return false;
466}
467
Jim Grosbach319026d2014-03-18 22:09:10 +0000468/// parseDirectiveIndirectSymbol
Kevin Enderby3aeada22013-08-28 17:50:59 +0000469/// ::= .indirect_symbol identifier
Jim Grosbach319026d2014-03-18 22:09:10 +0000470bool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) {
Eric Christopher445c9522016-10-14 05:47:37 +0000471 const MCSectionMachO *Current = static_cast<const MCSectionMachO *>(
472 getStreamer().getCurrentSectionOnly());
David Majnemercd481d32014-03-07 18:49:54 +0000473 MachO::SectionType SectionType = Current->getType();
David Majnemer7b583052014-03-07 07:36:05 +0000474 if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
475 SectionType != MachO::S_LAZY_SYMBOL_POINTERS &&
Tim Northover5c3140f2016-04-25 21:12:04 +0000476 SectionType != MachO::S_THREAD_LOCAL_VARIABLE_POINTERS &&
David Majnemer7b583052014-03-07 07:36:05 +0000477 SectionType != MachO::S_SYMBOL_STUBS)
Kevin Enderby3aeada22013-08-28 17:50:59 +0000478 return Error(Loc, "indirect symbol not in a symbol pointer or stub "
479 "section");
480
481 StringRef Name;
482 if (getParser().parseIdentifier(Name))
483 return TokError("expected identifier in .indirect_symbol directive");
484
Jim Grosbach6f482002015-05-18 18:43:14 +0000485 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Kevin Enderby3aeada22013-08-28 17:50:59 +0000486
487 // Assembler local symbols don't make any sense here. Complain loudly.
488 if (Sym->isTemporary())
489 return TokError("non-local symbol required in directive");
490
491 if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_IndirectSymbol))
492 return TokError("unable to emit indirect symbol attribute for: " + Name);
493
494 if (getLexer().isNot(AsmToken::EndOfStatement))
495 return TokError("unexpected token in '.indirect_symbol' directive");
496
497 Lex();
498
499 return false;
500}
501
Jim Grosbach319026d2014-03-18 22:09:10 +0000502/// parseDirectiveDumpOrLoad
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000503/// ::= ( .dump | .load ) "filename"
Jim Grosbach319026d2014-03-18 22:09:10 +0000504bool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000505 SMLoc IDLoc) {
506 bool IsDump = Directive == ".dump";
507 if (getLexer().isNot(AsmToken::String))
508 return TokError("expected string in '.dump' or '.load' directive");
509
510 Lex();
511
512 if (getLexer().isNot(AsmToken::EndOfStatement))
513 return TokError("unexpected token in '.dump' or '.load' directive");
514
515 Lex();
516
517 // FIXME: If/when .dump and .load are implemented they will be done in the
518 // the assembly parser and not have any need for an MCStreamer API.
519 if (IsDump)
Joerg Sonnenberger74ba2622011-05-19 18:00:13 +0000520 return Warning(IDLoc, "ignoring directive .dump for now");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000521 else
Joerg Sonnenberger74ba2622011-05-19 18:00:13 +0000522 return Warning(IDLoc, "ignoring directive .load for now");
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000523}
524
Daniel Dunbar16004b82013-01-18 01:25:48 +0000525/// ParseDirectiveLinkerOption
526/// ::= .linker_option "string" ( , "string" )*
Jim Grosbach319026d2014-03-18 22:09:10 +0000527bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
Daniel Dunbar16004b82013-01-18 01:25:48 +0000528 SmallVector<std::string, 4> Args;
529 for (;;) {
530 if (getLexer().isNot(AsmToken::String))
531 return TokError("expected string in '" + Twine(IDVal) + "' directive");
532
533 std::string Data;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000534 if (getParser().parseEscapedString(Data))
Daniel Dunbar16004b82013-01-18 01:25:48 +0000535 return true;
536
537 Args.push_back(Data);
538
Daniel Dunbar16004b82013-01-18 01:25:48 +0000539 if (getLexer().is(AsmToken::EndOfStatement))
540 break;
541
542 if (getLexer().isNot(AsmToken::Comma))
543 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
544 Lex();
545 }
546
547 getStreamer().EmitLinkerOptions(Args);
548 return false;
549}
550
Jim Grosbach319026d2014-03-18 22:09:10 +0000551/// parseDirectiveLsym
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000552/// ::= .lsym identifier , expression
Jim Grosbach319026d2014-03-18 22:09:10 +0000553bool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000554 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000555 if (getParser().parseIdentifier(Name))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000556 return TokError("expected identifier in directive");
557
558 // Handle the identifier as the key symbol.
Jim Grosbach6f482002015-05-18 18:43:14 +0000559 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000560
561 if (getLexer().isNot(AsmToken::Comma))
562 return TokError("unexpected token in '.lsym' directive");
563 Lex();
564
565 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000566 if (getParser().parseExpression(Value))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000567 return true;
568
569 if (getLexer().isNot(AsmToken::EndOfStatement))
570 return TokError("unexpected token in '.lsym' directive");
571
572 Lex();
573
574 // We don't currently support this directive.
575 //
576 // FIXME: Diagnostic location!
577 (void) Sym;
578 return TokError("directive '.lsym' is unsupported");
579}
580
Jim Grosbach319026d2014-03-18 22:09:10 +0000581/// parseDirectiveSection:
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000582/// ::= .section identifier (',' identifier)*
Jim Grosbach319026d2014-03-18 22:09:10 +0000583bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000584 SMLoc Loc = getLexer().getLoc();
585
586 StringRef SectionName;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000587 if (getParser().parseIdentifier(SectionName))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000588 return Error(Loc, "expected identifier after '.section' directive");
589
590 // Verify there is a following comma.
591 if (!getLexer().is(AsmToken::Comma))
592 return TokError("unexpected token in '.section' directive");
593
594 std::string SectionSpec = SectionName;
595 SectionSpec += ",";
596
597 // Add all the tokens until the end of the line, ParseSectionSpecifier will
598 // handle this.
599 StringRef EOL = getLexer().LexUntilEndOfStatement();
600 SectionSpec.append(EOL.begin(), EOL.end());
601
602 Lex();
603 if (getLexer().isNot(AsmToken::EndOfStatement))
604 return TokError("unexpected token in '.section' directive");
605 Lex();
606
607
608 StringRef Segment, Section;
Daniel Dunbarf1d62cf2011-03-17 16:25:24 +0000609 unsigned StubSize;
Stuart Hastings12d53122011-03-19 02:42:31 +0000610 unsigned TAA;
611 bool TAAParsed;
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000612 std::string ErrorStr =
613 MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section,
Stuart Hastings12d53122011-03-19 02:42:31 +0000614 TAA, TAAParsed, StubSize);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000615
616 if (!ErrorStr.empty())
Malcolm Parsons06ac79c2016-11-02 16:43:50 +0000617 return Error(Loc, ErrorStr);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000618
Akira Hatanaka8ad73992015-10-15 05:28:38 +0000619 // Issue a warning if the target is not powerpc and Section is a *coal* section.
620 Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();
621 Triple::ArchType ArchTy = TT.getArch();
622
623 if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
624 StringRef NonCoalSection = StringSwitch<StringRef>(Section)
625 .Case("__textcoal_nt", "__text")
626 .Case("__const_coal", "__const")
627 .Case("__datacoal_nt", "__data")
628 .Default(Section);
629
630 if (!Section.equals(NonCoalSection)) {
631 StringRef SectionVal(Loc.getPointer());
632 size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
633 SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
634 SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
635 getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
636 SMRange(BLoc, ELoc));
637 getParser().Note(Loc, "change section name to \"" + NonCoalSection +
638 "\"", SMRange(BLoc, ELoc));
639 }
640 }
641
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000642 // FIXME: Arch specific.
643 bool isText = Segment == "__TEXT"; // FIXME: Hack.
644 getStreamer().SwitchSection(getContext().getMachOSection(
Rafael Espindola449711c2015-11-18 06:02:15 +0000645 Segment, Section, TAA, StubSize,
646 isText ? SectionKind::getText() : SectionKind::getData()));
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000647 return false;
648}
649
Bill Wendlingce4fe412012-08-08 06:30:30 +0000650/// ParseDirectivePushSection:
651/// ::= .pushsection identifier (',' identifier)*
Jim Grosbach319026d2014-03-18 22:09:10 +0000652bool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) {
Bill Wendlingce4fe412012-08-08 06:30:30 +0000653 getStreamer().PushSection();
654
Jim Grosbach319026d2014-03-18 22:09:10 +0000655 if (parseDirectiveSection(S, Loc)) {
Bill Wendlingce4fe412012-08-08 06:30:30 +0000656 getStreamer().PopSection();
657 return true;
658 }
659
660 return false;
661}
662
663/// ParseDirectivePopSection:
664/// ::= .popsection
Jim Grosbach319026d2014-03-18 22:09:10 +0000665bool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
Bill Wendlingce4fe412012-08-08 06:30:30 +0000666 if (!getStreamer().PopSection())
667 return TokError(".popsection without corresponding .pushsection");
668 return false;
669}
670
671/// ParseDirectivePrevious:
672/// ::= .previous
Jim Grosbach319026d2014-03-18 22:09:10 +0000673bool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) {
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000674 MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
Craig Topper353eda42014-04-24 06:44:33 +0000675 if (!PreviousSection.first)
676 return TokError(".previous without corresponding .section");
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000677 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
Bill Wendlingce4fe412012-08-08 06:30:30 +0000678 return false;
679}
680
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000681/// ParseDirectiveSecureLogUnique
Daniel Dunbar40a564f2010-07-18 20:15:59 +0000682/// ::= .secure_log_unique ... message ...
Jim Grosbach319026d2014-03-18 22:09:10 +0000683bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000684 StringRef LogMessage = getParser().parseStringToEndOfStatement();
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000685 if (getLexer().isNot(AsmToken::EndOfStatement))
686 return TokError("unexpected token in '.secure_log_unique' directive");
687
David Blaikiedc3f01e2015-03-09 01:57:13 +0000688 if (getContext().getSecureLogUsed())
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000689 return Error(IDLoc, ".secure_log_unique specified multiple times");
690
Daniel Dunbar40a564f2010-07-18 20:15:59 +0000691 // Get the secure log path.
692 const char *SecureLogFile = getContext().getSecureLogFile();
Craig Topper353eda42014-04-24 06:44:33 +0000693 if (!SecureLogFile)
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000694 return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE "
695 "environment variable unset.");
696
Daniel Dunbar40a564f2010-07-18 20:15:59 +0000697 // Open the secure log file if we haven't already.
Rafael Espindolac49ac5e2015-12-16 23:49:14 +0000698 raw_fd_ostream *OS = getContext().getSecureLog();
Craig Topper353eda42014-04-24 06:44:33 +0000699 if (!OS) {
Rafael Espindola3fd1e992014-08-25 18:16:47 +0000700 std::error_code EC;
Rafael Espindolac49ac5e2015-12-16 23:49:14 +0000701 auto NewOS = llvm::make_unique<raw_fd_ostream>(
Mehdi Amini215ff8d2016-10-05 01:02:22 +0000702 StringRef(SecureLogFile), EC, sys::fs::F_Append | sys::fs::F_Text);
Rafael Espindolac49ac5e2015-12-16 23:49:14 +0000703 if (EC)
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000704 return Error(IDLoc, Twine("can't open secure log file: ") +
Rafael Espindola3fd1e992014-08-25 18:16:47 +0000705 SecureLogFile + " (" + EC.message() + ")");
Rafael Espindolac49ac5e2015-12-16 23:49:14 +0000706 OS = NewOS.get();
707 getContext().setSecureLog(std::move(NewOS));
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000708 }
709
Daniel Dunbar40a564f2010-07-18 20:15:59 +0000710 // Write the message.
Alp Tokera55b95b2014-07-06 10:33:31 +0000711 unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000712 *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
713 << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":"
714 << LogMessage + "\n";
715
716 getContext().setSecureLogUsed(true);
717
718 return false;
719}
720
721/// ParseDirectiveSecureLogReset
722/// ::= .secure_log_reset
Jim Grosbach319026d2014-03-18 22:09:10 +0000723bool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000724 if (getLexer().isNot(AsmToken::EndOfStatement))
725 return TokError("unexpected token in '.secure_log_reset' directive");
726
727 Lex();
728
729 getContext().setSecureLogUsed(false);
730
731 return false;
732}
733
Jim Grosbach319026d2014-03-18 22:09:10 +0000734/// parseDirectiveSubsectionsViaSymbols
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000735/// ::= .subsections_via_symbols
Jim Grosbach319026d2014-03-18 22:09:10 +0000736bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000737 if (getLexer().isNot(AsmToken::EndOfStatement))
738 return TokError("unexpected token in '.subsections_via_symbols' directive");
739
740 Lex();
741
742 getStreamer().EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
743
744 return false;
745}
746
747/// ParseDirectiveTBSS
748/// ::= .tbss identifier, size, align
Jim Grosbach319026d2014-03-18 22:09:10 +0000749bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000750 SMLoc IDLoc = getLexer().getLoc();
751 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000752 if (getParser().parseIdentifier(Name))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000753 return TokError("expected identifier in directive");
754
755 // Handle the identifier as the key symbol.
Jim Grosbach6f482002015-05-18 18:43:14 +0000756 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000757
758 if (getLexer().isNot(AsmToken::Comma))
759 return TokError("unexpected token in directive");
760 Lex();
761
762 int64_t Size;
763 SMLoc SizeLoc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000764 if (getParser().parseAbsoluteExpression(Size))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000765 return true;
766
767 int64_t Pow2Alignment = 0;
768 SMLoc Pow2AlignmentLoc;
769 if (getLexer().is(AsmToken::Comma)) {
770 Lex();
771 Pow2AlignmentLoc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000772 if (getParser().parseAbsoluteExpression(Pow2Alignment))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000773 return true;
774 }
775
776 if (getLexer().isNot(AsmToken::EndOfStatement))
777 return TokError("unexpected token in '.tbss' directive");
778
779 Lex();
780
781 if (Size < 0)
782 return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than"
783 "zero");
784
785 // FIXME: Diagnose overflow.
786 if (Pow2Alignment < 0)
787 return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less"
788 "than zero");
789
790 if (!Sym->isUndefined())
791 return Error(IDLoc, "invalid symbol redefinition");
792
793 getStreamer().EmitTBSSSymbol(getContext().getMachOSection(
794 "__DATA", "__thread_bss",
David Majnemer7b583052014-03-07 07:36:05 +0000795 MachO::S_THREAD_LOCAL_ZEROFILL,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000796 0, SectionKind::getThreadBSS()),
797 Sym, Size, 1 << Pow2Alignment);
798
799 return false;
800}
801
802/// ParseDirectiveZerofill
803/// ::= .zerofill segname , sectname [, identifier , size_expression [
804/// , align_expression ]]
Jim Grosbach319026d2014-03-18 22:09:10 +0000805bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) {
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000806 StringRef Segment;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000807 if (getParser().parseIdentifier(Segment))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000808 return TokError("expected segment name after '.zerofill' directive");
809
810 if (getLexer().isNot(AsmToken::Comma))
811 return TokError("unexpected token in directive");
812 Lex();
813
814 StringRef Section;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000815 if (getParser().parseIdentifier(Section))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000816 return TokError("expected section name after comma in '.zerofill' "
817 "directive");
818
819 // If this is the end of the line all that was wanted was to create the
820 // the section but with no symbol.
821 if (getLexer().is(AsmToken::EndOfStatement)) {
822 // Create the zerofill section but no symbol
823 getStreamer().EmitZerofill(getContext().getMachOSection(
David Majnemer7b583052014-03-07 07:36:05 +0000824 Segment, Section, MachO::S_ZEROFILL,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000825 0, SectionKind::getBSS()));
826 return false;
827 }
828
829 if (getLexer().isNot(AsmToken::Comma))
830 return TokError("unexpected token in directive");
831 Lex();
832
833 SMLoc IDLoc = getLexer().getLoc();
834 StringRef IDStr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000835 if (getParser().parseIdentifier(IDStr))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000836 return TokError("expected identifier in directive");
837
838 // handle the identifier as the key symbol.
Jim Grosbach6f482002015-05-18 18:43:14 +0000839 MCSymbol *Sym = getContext().getOrCreateSymbol(IDStr);
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000840
841 if (getLexer().isNot(AsmToken::Comma))
842 return TokError("unexpected token in directive");
843 Lex();
844
845 int64_t Size;
846 SMLoc SizeLoc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000847 if (getParser().parseAbsoluteExpression(Size))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000848 return true;
849
850 int64_t Pow2Alignment = 0;
851 SMLoc Pow2AlignmentLoc;
852 if (getLexer().is(AsmToken::Comma)) {
853 Lex();
854 Pow2AlignmentLoc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000855 if (getParser().parseAbsoluteExpression(Pow2Alignment))
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000856 return true;
857 }
858
859 if (getLexer().isNot(AsmToken::EndOfStatement))
860 return TokError("unexpected token in '.zerofill' directive");
861
862 Lex();
863
864 if (Size < 0)
865 return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
866 "than zero");
867
868 // NOTE: The alignment in the directive is a power of 2 value, the assembler
869 // may internally end up wanting an alignment in bytes.
870 // FIXME: Diagnose overflow.
871 if (Pow2Alignment < 0)
872 return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, "
873 "can't be less than zero");
874
875 if (!Sym->isUndefined())
876 return Error(IDLoc, "invalid symbol redefinition");
877
878 // Create the zerofill Symbol with Size and Pow2Alignment
879 //
880 // FIXME: Arch specific.
881 getStreamer().EmitZerofill(getContext().getMachOSection(
David Majnemer7b583052014-03-07 07:36:05 +0000882 Segment, Section, MachO::S_ZEROFILL,
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000883 0, SectionKind::getBSS()),
884 Sym, Size, 1 << Pow2Alignment);
885
886 return false;
887}
888
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000889/// ParseDirectiveDataRegion
890/// ::= .data_region [ ( jt8 | jt16 | jt32 ) ]
Jim Grosbach319026d2014-03-18 22:09:10 +0000891bool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) {
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000892 if (getLexer().is(AsmToken::EndOfStatement)) {
893 Lex();
894 getStreamer().EmitDataRegion(MCDR_DataRegion);
895 return false;
896 }
897 StringRef RegionType;
898 SMLoc Loc = getParser().getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000899 if (getParser().parseIdentifier(RegionType))
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000900 return TokError("expected region type after '.data_region' directive");
901 int Kind = StringSwitch<int>(RegionType)
902 .Case("jt8", MCDR_DataRegionJT8)
903 .Case("jt16", MCDR_DataRegionJT16)
904 .Case("jt32", MCDR_DataRegionJT32)
905 .Default(-1);
906 if (Kind == -1)
907 return Error(Loc, "unknown region type in '.data_region' directive");
908 Lex();
909
910 getStreamer().EmitDataRegion((MCDataRegionType)Kind);
911 return false;
912}
913
914/// ParseDirectiveDataRegionEnd
915/// ::= .end_data_region
Jim Grosbach319026d2014-03-18 22:09:10 +0000916bool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) {
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000917 if (getLexer().isNot(AsmToken::EndOfStatement))
918 return TokError("unexpected token in '.end_data_region' directive");
919
920 Lex();
921 getStreamer().EmitDataRegion(MCDR_DataRegionEnd);
922 return false;
923}
924
Jim Grosbach319026d2014-03-18 22:09:10 +0000925/// parseVersionMin
Jim Grosbach448334a2014-03-18 22:09:05 +0000926/// ::= .ios_version_min major,minor[,update]
927/// ::= .macosx_version_min major,minor[,update]
Tim Northover2d4d1612015-10-28 22:36:05 +0000928bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc) {
Jim Grosbach448334a2014-03-18 22:09:05 +0000929 int64_t Major = 0, Minor = 0, Update = 0;
930 int Kind = StringSwitch<int>(Directive)
Tim Northover2d4d1612015-10-28 22:36:05 +0000931 .Case(".watchos_version_min", MCVM_WatchOSVersionMin)
932 .Case(".tvos_version_min", MCVM_TvOSVersionMin)
Jim Grosbach448334a2014-03-18 22:09:05 +0000933 .Case(".ios_version_min", MCVM_IOSVersionMin)
934 .Case(".macosx_version_min", MCVM_OSXVersionMin);
935 // Get the major version number.
936 if (getLexer().isNot(AsmToken::Integer))
937 return TokError("invalid OS major version number");
938 Major = getLexer().getTok().getIntVal();
939 if (Major > 65535 || Major <= 0)
940 return TokError("invalid OS major version number");
941 Lex();
942 if (getLexer().isNot(AsmToken::Comma))
943 return TokError("minor OS version number required, comma expected");
944 Lex();
945 // Get the minor version number.
946 if (getLexer().isNot(AsmToken::Integer))
947 return TokError("invalid OS minor version number");
948 Minor = getLexer().getTok().getIntVal();
949 if (Minor > 255 || Minor < 0)
950 return TokError("invalid OS minor version number");
951 Lex();
952 // Get the update level, if specified
953 if (getLexer().isNot(AsmToken::EndOfStatement)) {
954 if (getLexer().isNot(AsmToken::Comma))
955 return TokError("invalid update specifier, comma expected");
956 Lex();
957 if (getLexer().isNot(AsmToken::Integer))
958 return TokError("invalid OS update number");
959 Update = getLexer().getTok().getIntVal();
Davide Italianoa8d89f32016-07-05 16:56:09 +0000960 if (Update > 255 || Update < 0)
961 return TokError("invalid OS update number");
Jim Grosbach448334a2014-03-18 22:09:05 +0000962 Lex();
963 }
964
Tim Northover2d4d1612015-10-28 22:36:05 +0000965 const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
966 Triple::OSType ExpectedOS = Triple::UnknownOS;
967 switch ((MCVersionMinType)Kind) {
968 case MCVM_WatchOSVersionMin: ExpectedOS = Triple::WatchOS; break;
969 case MCVM_TvOSVersionMin: ExpectedOS = Triple::TvOS; break;
970 case MCVM_IOSVersionMin: ExpectedOS = Triple::IOS; break;
971 case MCVM_OSXVersionMin: ExpectedOS = Triple::MacOSX; break;
972 }
973 if (T.getOS() != ExpectedOS)
974 Warning(Loc, Directive + " should only be used for " +
975 Triple::getOSTypeName(ExpectedOS) + " targets");
976
977 if (LastVersionMinDirective.isValid()) {
978 Warning(Loc, "overriding previous version_min directive");
979 Note(LastVersionMinDirective, "previous definition is here");
980 }
981 LastVersionMinDirective = Loc;
982
Jim Grosbach448334a2014-03-18 22:09:05 +0000983 // We've parsed a correct version specifier, so send it to the streamer.
984 getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update);
985
986 return false;
987}
988
Daniel Dunbar0cb91cf2010-07-12 20:51:51 +0000989namespace llvm {
990
991MCAsmParserExtension *createDarwinAsmParser() {
992 return new DarwinAsmParser;
993}
994
Bill Wendlingce4fe412012-08-08 06:30:30 +0000995} // end llvm namespace