Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 1 | //===- 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" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/StringRef.h" |
| 12 | #include "llvm/ADT/StringSwitch.h" |
| 13 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCContext.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 16 | #include "llvm/MC/MCParser/MCAsmParser.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCSectionMachO.h" |
| 18 | #include "llvm/MC/MCStreamer.h" |
| 19 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MemoryBuffer.h" |
| 21 | #include "llvm/Support/SourceMgr.h" |
| 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | /// \brief Implementation of directive handling which is shared across all |
| 27 | /// Darwin targets. |
| 28 | class DarwinAsmParser : public MCAsmParserExtension { |
Eli Bendersky | 29b9f47 | 2013-01-16 00:50:52 +0000 | [diff] [blame] | 29 | template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)> |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 30 | void addDirectiveHandler(StringRef Directive) { |
Eli Bendersky | 29b9f47 | 2013-01-16 00:50:52 +0000 | [diff] [blame] | 31 | MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair( |
| 32 | this, HandleDirective<DarwinAsmParser, HandlerMethod>); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 33 | getParser().addDirectiveHandler(Directive, Handler); |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 36 | bool ParseSectionSwitch(const char *Segment, const char *Section, |
| 37 | unsigned TAA = 0, unsigned ImplicitAlign = 0, |
| 38 | unsigned StubSize = 0); |
| 39 | |
| 40 | public: |
| 41 | DarwinAsmParser() {} |
| 42 | |
Craig Topper | 59be68f | 2014-03-08 07:14:16 +0000 | [diff] [blame] | 43 | void Initialize(MCAsmParser &Parser) override { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 44 | // Call the base implementation. |
| 45 | this->MCAsmParserExtension::Initialize(Parser); |
| 46 | |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 47 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDesc>(".desc"); |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 48 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveIndirectSymbol>( |
| 49 | ".indirect_symbol"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 50 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveLsym>(".lsym"); |
| 51 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 52 | ".subsections_via_symbols"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 53 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".dump"); |
| 54 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".load"); |
| 55 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSection>(".section"); |
| 56 | addDirectiveHandler<&DarwinAsmParser::ParseDirectivePushSection>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 57 | ".pushsection"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 58 | addDirectiveHandler<&DarwinAsmParser::ParseDirectivePopSection>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 59 | ".popsection"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 60 | addDirectiveHandler<&DarwinAsmParser::ParseDirectivePrevious>(".previous"); |
| 61 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogUnique>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 62 | ".secure_log_unique"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 63 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogReset>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 64 | ".secure_log_reset"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 65 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveTBSS>(".tbss"); |
| 66 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveZerofill>(".zerofill"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 67 | |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 68 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegion>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 69 | ".data_region"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 70 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegionEnd>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 71 | ".end_data_region"); |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 72 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 73 | // Special section directives. |
Rafael Espindola | 3402c05 | 2013-10-02 14:09:29 +0000 | [diff] [blame] | 74 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveBss>(".bss"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 75 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConst>(".const"); |
| 76 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstData>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 77 | ".const_data"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 78 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstructor>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 79 | ".constructor"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 80 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveCString>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 81 | ".cstring"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 82 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveData>(".data"); |
| 83 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDestructor>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 84 | ".destructor"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 85 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDyld>(".dyld"); |
| 86 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit0>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 87 | ".fvmlib_init0"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 88 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit1>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 89 | ".fvmlib_init1"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 90 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 91 | &DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>( |
| 92 | ".lazy_symbol_pointer"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 93 | addDirectiveHandler<&DarwinAsmParser::ParseDirectiveLinkerOption>( |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 94 | ".linker_option"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 95 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 96 | ".literal16"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 97 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 98 | ".literal4"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 99 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral8>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 100 | ".literal8"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 101 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModInitFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 102 | ".mod_init_func"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 103 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModTermFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 104 | ".mod_term_func"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 105 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 106 | &DarwinAsmParser::ParseSectionDirectiveNonLazySymbolPointers>( |
| 107 | ".non_lazy_symbol_pointer"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 108 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatClsMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 109 | ".objc_cat_cls_meth"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 110 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatInstMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 111 | ".objc_cat_inst_meth"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 112 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCategory>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 113 | ".objc_category"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 114 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClass>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 115 | ".objc_class"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 116 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassNames>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 117 | ".objc_class_names"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 118 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassVars>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 119 | ".objc_class_vars"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 120 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 121 | ".objc_cls_meth"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 122 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsRefs>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 123 | ".objc_cls_refs"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 124 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 125 | ".objc_inst_meth"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 126 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 127 | &DarwinAsmParser::ParseSectionDirectiveObjCInstanceVars>( |
| 128 | ".objc_instance_vars"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 129 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMessageRefs>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 130 | ".objc_message_refs"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 131 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMetaClass>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 132 | ".objc_meta_class"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 133 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 134 | &DarwinAsmParser::ParseSectionDirectiveObjCMethVarNames>( |
| 135 | ".objc_meth_var_names"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 136 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 137 | &DarwinAsmParser::ParseSectionDirectiveObjCMethVarTypes>( |
| 138 | ".objc_meth_var_types"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 139 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCModuleInfo>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 140 | ".objc_module_info"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 141 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCProtocol>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 142 | ".objc_protocol"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 143 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 144 | &DarwinAsmParser::ParseSectionDirectiveObjCSelectorStrs>( |
| 145 | ".objc_selector_strs"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 146 | addDirectiveHandler< |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 147 | &DarwinAsmParser::ParseSectionDirectiveObjCStringObject>( |
| 148 | ".objc_string_object"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 149 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSymbols>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 150 | ".objc_symbols"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 151 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectivePICSymbolStub>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 152 | ".picsymbol_stub"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 153 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticConst>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 154 | ".static_const"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 155 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticData>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 156 | ".static_data"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 157 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveSymbolStub>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 158 | ".symbol_stub"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 159 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTData>(".tdata"); |
| 160 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveText>(".text"); |
| 161 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveThreadInitFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 162 | ".thread_init_func"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 163 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTLV>(".tlv"); |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 164 | |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 165 | addDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveIdent>(".ident"); |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame^] | 166 | addDirectiveHandler<&DarwinAsmParser::ParseVersionMin>(".ios_version_min"); |
| 167 | addDirectiveHandler<&DarwinAsmParser::ParseVersionMin>( |
| 168 | ".macosx_version_min"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | bool ParseDirectiveDesc(StringRef, SMLoc); |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 172 | bool ParseDirectiveIndirectSymbol(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 173 | bool ParseDirectiveDumpOrLoad(StringRef, SMLoc); |
| 174 | bool ParseDirectiveLsym(StringRef, SMLoc); |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 175 | bool ParseDirectiveLinkerOption(StringRef, SMLoc); |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 176 | bool ParseDirectiveSection(StringRef, SMLoc); |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 177 | bool ParseDirectivePushSection(StringRef, SMLoc); |
| 178 | bool ParseDirectivePopSection(StringRef, SMLoc); |
| 179 | bool ParseDirectivePrevious(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 180 | bool ParseDirectiveSecureLogReset(StringRef, SMLoc); |
| 181 | bool ParseDirectiveSecureLogUnique(StringRef, SMLoc); |
| 182 | bool ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc); |
| 183 | bool ParseDirectiveTBSS(StringRef, SMLoc); |
| 184 | bool ParseDirectiveZerofill(StringRef, SMLoc); |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 185 | bool ParseDirectiveDataRegion(StringRef, SMLoc); |
| 186 | bool ParseDirectiveDataRegionEnd(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 187 | |
| 188 | // Named Section Directive |
Rafael Espindola | 3402c05 | 2013-10-02 14:09:29 +0000 | [diff] [blame] | 189 | bool ParseSectionDirectiveBss(StringRef, SMLoc) { |
| 190 | return ParseSectionSwitch("__DATA", "__bss"); |
| 191 | } |
| 192 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 193 | bool ParseSectionDirectiveConst(StringRef, SMLoc) { |
| 194 | return ParseSectionSwitch("__TEXT", "__const"); |
| 195 | } |
| 196 | bool ParseSectionDirectiveStaticConst(StringRef, SMLoc) { |
| 197 | return ParseSectionSwitch("__TEXT", "__static_const"); |
| 198 | } |
| 199 | bool ParseSectionDirectiveCString(StringRef, SMLoc) { |
| 200 | return ParseSectionSwitch("__TEXT","__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 201 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 202 | } |
| 203 | bool ParseSectionDirectiveLiteral4(StringRef, SMLoc) { |
| 204 | return ParseSectionSwitch("__TEXT", "__literal4", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 205 | MachO::S_4BYTE_LITERALS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 206 | } |
| 207 | bool ParseSectionDirectiveLiteral8(StringRef, SMLoc) { |
| 208 | return ParseSectionSwitch("__TEXT", "__literal8", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 209 | MachO::S_8BYTE_LITERALS, 8); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 210 | } |
| 211 | bool ParseSectionDirectiveLiteral16(StringRef, SMLoc) { |
| 212 | return ParseSectionSwitch("__TEXT","__literal16", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 213 | MachO::S_16BYTE_LITERALS, 16); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 214 | } |
| 215 | bool ParseSectionDirectiveConstructor(StringRef, SMLoc) { |
| 216 | return ParseSectionSwitch("__TEXT","__constructor"); |
| 217 | } |
| 218 | bool ParseSectionDirectiveDestructor(StringRef, SMLoc) { |
| 219 | return ParseSectionSwitch("__TEXT","__destructor"); |
| 220 | } |
| 221 | bool ParseSectionDirectiveFVMLibInit0(StringRef, SMLoc) { |
| 222 | return ParseSectionSwitch("__TEXT","__fvmlib_init0"); |
| 223 | } |
| 224 | bool ParseSectionDirectiveFVMLibInit1(StringRef, SMLoc) { |
| 225 | return ParseSectionSwitch("__TEXT","__fvmlib_init1"); |
| 226 | } |
| 227 | bool ParseSectionDirectiveSymbolStub(StringRef, SMLoc) { |
| 228 | return ParseSectionSwitch("__TEXT","__symbol_stub", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 229 | MachO::S_SYMBOL_STUBS | |
| 230 | MachO::S_ATTR_PURE_INSTRUCTIONS, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 231 | // FIXME: Different on PPC and ARM. |
| 232 | 0, 16); |
| 233 | } |
| 234 | bool ParseSectionDirectivePICSymbolStub(StringRef, SMLoc) { |
| 235 | return ParseSectionSwitch("__TEXT","__picsymbol_stub", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 236 | MachO::S_SYMBOL_STUBS | |
| 237 | MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 238 | } |
| 239 | bool ParseSectionDirectiveData(StringRef, SMLoc) { |
| 240 | return ParseSectionSwitch("__DATA", "__data"); |
| 241 | } |
| 242 | bool ParseSectionDirectiveStaticData(StringRef, SMLoc) { |
| 243 | return ParseSectionSwitch("__DATA", "__static_data"); |
| 244 | } |
| 245 | bool ParseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) { |
| 246 | return ParseSectionSwitch("__DATA", "__nl_symbol_ptr", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 247 | MachO::S_NON_LAZY_SYMBOL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 248 | } |
| 249 | bool ParseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) { |
| 250 | return ParseSectionSwitch("__DATA", "__la_symbol_ptr", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 251 | MachO::S_LAZY_SYMBOL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 252 | } |
| 253 | bool ParseSectionDirectiveDyld(StringRef, SMLoc) { |
| 254 | return ParseSectionSwitch("__DATA", "__dyld"); |
| 255 | } |
| 256 | bool ParseSectionDirectiveModInitFunc(StringRef, SMLoc) { |
| 257 | return ParseSectionSwitch("__DATA", "__mod_init_func", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 258 | MachO::S_MOD_INIT_FUNC_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 259 | } |
| 260 | bool ParseSectionDirectiveModTermFunc(StringRef, SMLoc) { |
| 261 | return ParseSectionSwitch("__DATA", "__mod_term_func", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 262 | MachO::S_MOD_TERM_FUNC_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 263 | } |
| 264 | bool ParseSectionDirectiveConstData(StringRef, SMLoc) { |
| 265 | return ParseSectionSwitch("__DATA", "__const"); |
| 266 | } |
| 267 | bool ParseSectionDirectiveObjCClass(StringRef, SMLoc) { |
| 268 | return ParseSectionSwitch("__OBJC", "__class", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 269 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 270 | } |
| 271 | bool ParseSectionDirectiveObjCMetaClass(StringRef, SMLoc) { |
| 272 | return ParseSectionSwitch("__OBJC", "__meta_class", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 273 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 274 | } |
| 275 | bool ParseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) { |
| 276 | return ParseSectionSwitch("__OBJC", "__cat_cls_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 277 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 278 | } |
| 279 | bool ParseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) { |
| 280 | return ParseSectionSwitch("__OBJC", "__cat_inst_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 281 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 282 | } |
| 283 | bool ParseSectionDirectiveObjCProtocol(StringRef, SMLoc) { |
| 284 | return ParseSectionSwitch("__OBJC", "__protocol", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 285 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 286 | } |
| 287 | bool ParseSectionDirectiveObjCStringObject(StringRef, SMLoc) { |
| 288 | return ParseSectionSwitch("__OBJC", "__string_object", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 289 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 290 | } |
| 291 | bool ParseSectionDirectiveObjCClsMeth(StringRef, SMLoc) { |
| 292 | return ParseSectionSwitch("__OBJC", "__cls_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 293 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 294 | } |
| 295 | bool ParseSectionDirectiveObjCInstMeth(StringRef, SMLoc) { |
| 296 | return ParseSectionSwitch("__OBJC", "__inst_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 297 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 298 | } |
| 299 | bool ParseSectionDirectiveObjCClsRefs(StringRef, SMLoc) { |
| 300 | return ParseSectionSwitch("__OBJC", "__cls_refs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 301 | MachO::S_ATTR_NO_DEAD_STRIP | |
| 302 | MachO::S_LITERAL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 303 | } |
| 304 | bool ParseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) { |
| 305 | return ParseSectionSwitch("__OBJC", "__message_refs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 306 | MachO::S_ATTR_NO_DEAD_STRIP | |
| 307 | MachO::S_LITERAL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 308 | } |
| 309 | bool ParseSectionDirectiveObjCSymbols(StringRef, SMLoc) { |
| 310 | return ParseSectionSwitch("__OBJC", "__symbols", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 311 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 312 | } |
| 313 | bool ParseSectionDirectiveObjCCategory(StringRef, SMLoc) { |
| 314 | return ParseSectionSwitch("__OBJC", "__category", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 315 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 316 | } |
| 317 | bool ParseSectionDirectiveObjCClassVars(StringRef, SMLoc) { |
| 318 | return ParseSectionSwitch("__OBJC", "__class_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 319 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 320 | } |
| 321 | bool ParseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) { |
| 322 | return ParseSectionSwitch("__OBJC", "__instance_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 323 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 324 | } |
| 325 | bool ParseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) { |
| 326 | return ParseSectionSwitch("__OBJC", "__module_info", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 327 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 328 | } |
| 329 | bool ParseSectionDirectiveObjCClassNames(StringRef, SMLoc) { |
| 330 | return ParseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 331 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 332 | } |
| 333 | bool ParseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) { |
| 334 | return ParseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 335 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 336 | } |
| 337 | bool ParseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) { |
| 338 | return ParseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 339 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 340 | } |
| 341 | bool ParseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) { |
| 342 | return ParseSectionSwitch("__OBJC", "__selector_strs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 343 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 344 | } |
| 345 | bool ParseSectionDirectiveTData(StringRef, SMLoc) { |
| 346 | return ParseSectionSwitch("__DATA", "__thread_data", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 347 | MachO::S_THREAD_LOCAL_REGULAR); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 348 | } |
| 349 | bool ParseSectionDirectiveText(StringRef, SMLoc) { |
| 350 | return ParseSectionSwitch("__TEXT", "__text", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 351 | MachO::S_ATTR_PURE_INSTRUCTIONS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 352 | } |
| 353 | bool ParseSectionDirectiveTLV(StringRef, SMLoc) { |
| 354 | return ParseSectionSwitch("__DATA", "__thread_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 355 | MachO::S_THREAD_LOCAL_VARIABLES); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 356 | } |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 357 | bool ParseSectionDirectiveIdent(StringRef, SMLoc) { |
| 358 | // Darwin silently ignores the .ident directive. |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 359 | getParser().eatToEndOfStatement(); |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 360 | return false; |
| 361 | } |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 362 | bool ParseSectionDirectiveThreadInitFunc(StringRef, SMLoc) { |
| 363 | return ParseSectionSwitch("__DATA", "__thread_init", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 364 | MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 365 | } |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame^] | 366 | bool ParseVersionMin(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 367 | |
| 368 | }; |
| 369 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 370 | } // end anonymous namespace |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 371 | |
| 372 | bool DarwinAsmParser::ParseSectionSwitch(const char *Segment, |
| 373 | const char *Section, |
| 374 | unsigned TAA, unsigned Align, |
| 375 | unsigned StubSize) { |
| 376 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 377 | return TokError("unexpected token in section switching directive"); |
| 378 | Lex(); |
| 379 | |
| 380 | // FIXME: Arch specific. |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 381 | bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS; |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 382 | getStreamer().SwitchSection(getContext().getMachOSection( |
| 383 | Segment, Section, TAA, StubSize, |
| 384 | isText ? SectionKind::getText() |
| 385 | : SectionKind::getDataRel())); |
| 386 | |
| 387 | // Set the implicit alignment, if any. |
| 388 | // |
| 389 | // FIXME: This isn't really what 'as' does; I think it just uses the implicit |
| 390 | // alignment on the section (e.g., if one manually inserts bytes into the |
Bill Wendling | 5391eb6 | 2010-10-19 10:18:23 +0000 | [diff] [blame] | 391 | // section, then just issuing the section switch directive will not realign |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 392 | // the section. However, this is arguably more reasonable behavior, and there |
| 393 | // is no good reason for someone to intentionally emit incorrectly sized |
| 394 | // values into the implicitly aligned sections. |
| 395 | if (Align) |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 396 | getStreamer().EmitValueToAlignment(Align); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 397 | |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | /// ParseDirectiveDesc |
| 402 | /// ::= .desc identifier , expression |
| 403 | bool DarwinAsmParser::ParseDirectiveDesc(StringRef, SMLoc) { |
| 404 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 405 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 406 | return TokError("expected identifier in directive"); |
| 407 | |
| 408 | // Handle the identifier as the key symbol. |
| 409 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 410 | |
| 411 | if (getLexer().isNot(AsmToken::Comma)) |
| 412 | return TokError("unexpected token in '.desc' directive"); |
| 413 | Lex(); |
| 414 | |
| 415 | int64_t DescValue; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 416 | if (getParser().parseAbsoluteExpression(DescValue)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 417 | return true; |
| 418 | |
| 419 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 420 | return TokError("unexpected token in '.desc' directive"); |
| 421 | |
| 422 | Lex(); |
| 423 | |
| 424 | // Set the n_desc field of this Symbol to this DescValue |
| 425 | getStreamer().EmitSymbolDesc(Sym, DescValue); |
| 426 | |
| 427 | return false; |
| 428 | } |
| 429 | |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 430 | /// ParseDirectiveIndirectSymbol |
| 431 | /// ::= .indirect_symbol identifier |
| 432 | bool DarwinAsmParser::ParseDirectiveIndirectSymbol(StringRef, SMLoc Loc) { |
| 433 | const MCSectionMachO *Current = static_cast<const MCSectionMachO*>( |
| 434 | getStreamer().getCurrentSection().first); |
David Majnemer | cd481d3 | 2014-03-07 18:49:54 +0000 | [diff] [blame] | 435 | MachO::SectionType SectionType = Current->getType(); |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 436 | if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS && |
| 437 | SectionType != MachO::S_LAZY_SYMBOL_POINTERS && |
| 438 | SectionType != MachO::S_SYMBOL_STUBS) |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 439 | return Error(Loc, "indirect symbol not in a symbol pointer or stub " |
| 440 | "section"); |
| 441 | |
| 442 | StringRef Name; |
| 443 | if (getParser().parseIdentifier(Name)) |
| 444 | return TokError("expected identifier in .indirect_symbol directive"); |
| 445 | |
| 446 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 447 | |
| 448 | // Assembler local symbols don't make any sense here. Complain loudly. |
| 449 | if (Sym->isTemporary()) |
| 450 | return TokError("non-local symbol required in directive"); |
| 451 | |
| 452 | if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_IndirectSymbol)) |
| 453 | return TokError("unable to emit indirect symbol attribute for: " + Name); |
| 454 | |
| 455 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 456 | return TokError("unexpected token in '.indirect_symbol' directive"); |
| 457 | |
| 458 | Lex(); |
| 459 | |
| 460 | return false; |
| 461 | } |
| 462 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 463 | /// ParseDirectiveDumpOrLoad |
| 464 | /// ::= ( .dump | .load ) "filename" |
| 465 | bool DarwinAsmParser::ParseDirectiveDumpOrLoad(StringRef Directive, |
| 466 | SMLoc IDLoc) { |
| 467 | bool IsDump = Directive == ".dump"; |
| 468 | if (getLexer().isNot(AsmToken::String)) |
| 469 | return TokError("expected string in '.dump' or '.load' directive"); |
| 470 | |
| 471 | Lex(); |
| 472 | |
| 473 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 474 | return TokError("unexpected token in '.dump' or '.load' directive"); |
| 475 | |
| 476 | Lex(); |
| 477 | |
| 478 | // FIXME: If/when .dump and .load are implemented they will be done in the |
| 479 | // the assembly parser and not have any need for an MCStreamer API. |
| 480 | if (IsDump) |
Joerg Sonnenberger | 74ba262 | 2011-05-19 18:00:13 +0000 | [diff] [blame] | 481 | return Warning(IDLoc, "ignoring directive .dump for now"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 482 | else |
Joerg Sonnenberger | 74ba262 | 2011-05-19 18:00:13 +0000 | [diff] [blame] | 483 | return Warning(IDLoc, "ignoring directive .load for now"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 486 | /// ParseDirectiveLinkerOption |
| 487 | /// ::= .linker_option "string" ( , "string" )* |
| 488 | bool DarwinAsmParser::ParseDirectiveLinkerOption(StringRef IDVal, SMLoc) { |
| 489 | SmallVector<std::string, 4> Args; |
| 490 | for (;;) { |
| 491 | if (getLexer().isNot(AsmToken::String)) |
| 492 | return TokError("expected string in '" + Twine(IDVal) + "' directive"); |
| 493 | |
| 494 | std::string Data; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 495 | if (getParser().parseEscapedString(Data)) |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 496 | return true; |
| 497 | |
| 498 | Args.push_back(Data); |
| 499 | |
| 500 | Lex(); |
| 501 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 502 | break; |
| 503 | |
| 504 | if (getLexer().isNot(AsmToken::Comma)) |
| 505 | return TokError("unexpected token in '" + Twine(IDVal) + "' directive"); |
| 506 | Lex(); |
| 507 | } |
| 508 | |
| 509 | getStreamer().EmitLinkerOptions(Args); |
| 510 | return false; |
| 511 | } |
| 512 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 513 | /// ParseDirectiveLsym |
| 514 | /// ::= .lsym identifier , expression |
| 515 | bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) { |
| 516 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 517 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 518 | return TokError("expected identifier in directive"); |
| 519 | |
| 520 | // Handle the identifier as the key symbol. |
| 521 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 522 | |
| 523 | if (getLexer().isNot(AsmToken::Comma)) |
| 524 | return TokError("unexpected token in '.lsym' directive"); |
| 525 | Lex(); |
| 526 | |
| 527 | const MCExpr *Value; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 528 | if (getParser().parseExpression(Value)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 529 | return true; |
| 530 | |
| 531 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 532 | return TokError("unexpected token in '.lsym' directive"); |
| 533 | |
| 534 | Lex(); |
| 535 | |
| 536 | // We don't currently support this directive. |
| 537 | // |
| 538 | // FIXME: Diagnostic location! |
| 539 | (void) Sym; |
| 540 | return TokError("directive '.lsym' is unsupported"); |
| 541 | } |
| 542 | |
| 543 | /// ParseDirectiveSection: |
| 544 | /// ::= .section identifier (',' identifier)* |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 545 | bool DarwinAsmParser::ParseDirectiveSection(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 546 | SMLoc Loc = getLexer().getLoc(); |
| 547 | |
| 548 | StringRef SectionName; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 549 | if (getParser().parseIdentifier(SectionName)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 550 | return Error(Loc, "expected identifier after '.section' directive"); |
| 551 | |
| 552 | // Verify there is a following comma. |
| 553 | if (!getLexer().is(AsmToken::Comma)) |
| 554 | return TokError("unexpected token in '.section' directive"); |
| 555 | |
| 556 | std::string SectionSpec = SectionName; |
| 557 | SectionSpec += ","; |
| 558 | |
| 559 | // Add all the tokens until the end of the line, ParseSectionSpecifier will |
| 560 | // handle this. |
| 561 | StringRef EOL = getLexer().LexUntilEndOfStatement(); |
| 562 | SectionSpec.append(EOL.begin(), EOL.end()); |
| 563 | |
| 564 | Lex(); |
| 565 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 566 | return TokError("unexpected token in '.section' directive"); |
| 567 | Lex(); |
| 568 | |
| 569 | |
| 570 | StringRef Segment, Section; |
Daniel Dunbar | f1d62cf | 2011-03-17 16:25:24 +0000 | [diff] [blame] | 571 | unsigned StubSize; |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 572 | unsigned TAA; |
| 573 | bool TAAParsed; |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 574 | std::string ErrorStr = |
| 575 | MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section, |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 576 | TAA, TAAParsed, StubSize); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 577 | |
| 578 | if (!ErrorStr.empty()) |
| 579 | return Error(Loc, ErrorStr.c_str()); |
| 580 | |
| 581 | // FIXME: Arch specific. |
| 582 | bool isText = Segment == "__TEXT"; // FIXME: Hack. |
| 583 | getStreamer().SwitchSection(getContext().getMachOSection( |
| 584 | Segment, Section, TAA, StubSize, |
| 585 | isText ? SectionKind::getText() |
| 586 | : SectionKind::getDataRel())); |
| 587 | return false; |
| 588 | } |
| 589 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 590 | /// ParseDirectivePushSection: |
| 591 | /// ::= .pushsection identifier (',' identifier)* |
| 592 | bool DarwinAsmParser::ParseDirectivePushSection(StringRef S, SMLoc Loc) { |
| 593 | getStreamer().PushSection(); |
| 594 | |
| 595 | if (ParseDirectiveSection(S, Loc)) { |
| 596 | getStreamer().PopSection(); |
| 597 | return true; |
| 598 | } |
| 599 | |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | /// ParseDirectivePopSection: |
| 604 | /// ::= .popsection |
| 605 | bool DarwinAsmParser::ParseDirectivePopSection(StringRef, SMLoc) { |
| 606 | if (!getStreamer().PopSection()) |
| 607 | return TokError(".popsection without corresponding .pushsection"); |
| 608 | return false; |
| 609 | } |
| 610 | |
| 611 | /// ParseDirectivePrevious: |
| 612 | /// ::= .previous |
| 613 | bool DarwinAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) { |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 614 | MCSectionSubPair PreviousSection = getStreamer().getPreviousSection(); |
| 615 | if (PreviousSection.first == NULL) |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 616 | return TokError(".previous without corresponding .section"); |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 617 | getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second); |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 618 | return false; |
| 619 | } |
| 620 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 621 | /// ParseDirectiveSecureLogUnique |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 622 | /// ::= .secure_log_unique ... message ... |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 623 | bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 624 | StringRef LogMessage = getParser().parseStringToEndOfStatement(); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 625 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 626 | return TokError("unexpected token in '.secure_log_unique' directive"); |
| 627 | |
| 628 | if (getContext().getSecureLogUsed() != false) |
| 629 | return Error(IDLoc, ".secure_log_unique specified multiple times"); |
| 630 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 631 | // Get the secure log path. |
| 632 | const char *SecureLogFile = getContext().getSecureLogFile(); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 633 | if (SecureLogFile == NULL) |
| 634 | return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE " |
| 635 | "environment variable unset."); |
| 636 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 637 | // Open the secure log file if we haven't already. |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 638 | raw_ostream *OS = getContext().getSecureLog(); |
| 639 | if (OS == NULL) { |
| 640 | std::string Err; |
Rafael Espindola | 90c7f1c | 2014-02-24 18:20:12 +0000 | [diff] [blame] | 641 | OS = new raw_fd_ostream(SecureLogFile, Err, |
| 642 | sys::fs::F_Append | sys::fs::F_Text); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 643 | if (!Err.empty()) { |
| 644 | delete OS; |
| 645 | return Error(IDLoc, Twine("can't open secure log file: ") + |
| 646 | SecureLogFile + " (" + Err + ")"); |
| 647 | } |
| 648 | getContext().setSecureLog(OS); |
| 649 | } |
| 650 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 651 | // Write the message. |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 652 | int CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc); |
| 653 | *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier() |
| 654 | << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":" |
| 655 | << LogMessage + "\n"; |
| 656 | |
| 657 | getContext().setSecureLogUsed(true); |
| 658 | |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | /// ParseDirectiveSecureLogReset |
| 663 | /// ::= .secure_log_reset |
| 664 | bool DarwinAsmParser::ParseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) { |
| 665 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 666 | return TokError("unexpected token in '.secure_log_reset' directive"); |
| 667 | |
| 668 | Lex(); |
| 669 | |
| 670 | getContext().setSecureLogUsed(false); |
| 671 | |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | /// ParseDirectiveSubsectionsViaSymbols |
| 676 | /// ::= .subsections_via_symbols |
| 677 | bool DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) { |
| 678 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 679 | return TokError("unexpected token in '.subsections_via_symbols' directive"); |
| 680 | |
| 681 | Lex(); |
| 682 | |
| 683 | getStreamer().EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
| 684 | |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | /// ParseDirectiveTBSS |
| 689 | /// ::= .tbss identifier, size, align |
| 690 | bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) { |
| 691 | SMLoc IDLoc = getLexer().getLoc(); |
| 692 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 693 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 694 | return TokError("expected identifier in directive"); |
| 695 | |
| 696 | // Handle the identifier as the key symbol. |
| 697 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 698 | |
| 699 | if (getLexer().isNot(AsmToken::Comma)) |
| 700 | return TokError("unexpected token in directive"); |
| 701 | Lex(); |
| 702 | |
| 703 | int64_t Size; |
| 704 | SMLoc SizeLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 705 | if (getParser().parseAbsoluteExpression(Size)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 706 | return true; |
| 707 | |
| 708 | int64_t Pow2Alignment = 0; |
| 709 | SMLoc Pow2AlignmentLoc; |
| 710 | if (getLexer().is(AsmToken::Comma)) { |
| 711 | Lex(); |
| 712 | Pow2AlignmentLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 713 | if (getParser().parseAbsoluteExpression(Pow2Alignment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 714 | return true; |
| 715 | } |
| 716 | |
| 717 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 718 | return TokError("unexpected token in '.tbss' directive"); |
| 719 | |
| 720 | Lex(); |
| 721 | |
| 722 | if (Size < 0) |
| 723 | return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than" |
| 724 | "zero"); |
| 725 | |
| 726 | // FIXME: Diagnose overflow. |
| 727 | if (Pow2Alignment < 0) |
| 728 | return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less" |
| 729 | "than zero"); |
| 730 | |
| 731 | if (!Sym->isUndefined()) |
| 732 | return Error(IDLoc, "invalid symbol redefinition"); |
| 733 | |
| 734 | getStreamer().EmitTBSSSymbol(getContext().getMachOSection( |
| 735 | "__DATA", "__thread_bss", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 736 | MachO::S_THREAD_LOCAL_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 737 | 0, SectionKind::getThreadBSS()), |
| 738 | Sym, Size, 1 << Pow2Alignment); |
| 739 | |
| 740 | return false; |
| 741 | } |
| 742 | |
| 743 | /// ParseDirectiveZerofill |
| 744 | /// ::= .zerofill segname , sectname [, identifier , size_expression [ |
| 745 | /// , align_expression ]] |
| 746 | bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) { |
| 747 | StringRef Segment; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 748 | if (getParser().parseIdentifier(Segment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 749 | return TokError("expected segment name after '.zerofill' directive"); |
| 750 | |
| 751 | if (getLexer().isNot(AsmToken::Comma)) |
| 752 | return TokError("unexpected token in directive"); |
| 753 | Lex(); |
| 754 | |
| 755 | StringRef Section; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 756 | if (getParser().parseIdentifier(Section)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 757 | return TokError("expected section name after comma in '.zerofill' " |
| 758 | "directive"); |
| 759 | |
| 760 | // If this is the end of the line all that was wanted was to create the |
| 761 | // the section but with no symbol. |
| 762 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 763 | // Create the zerofill section but no symbol |
| 764 | getStreamer().EmitZerofill(getContext().getMachOSection( |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 765 | Segment, Section, MachO::S_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 766 | 0, SectionKind::getBSS())); |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | if (getLexer().isNot(AsmToken::Comma)) |
| 771 | return TokError("unexpected token in directive"); |
| 772 | Lex(); |
| 773 | |
| 774 | SMLoc IDLoc = getLexer().getLoc(); |
| 775 | StringRef IDStr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 776 | if (getParser().parseIdentifier(IDStr)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 777 | return TokError("expected identifier in directive"); |
| 778 | |
| 779 | // handle the identifier as the key symbol. |
| 780 | MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr); |
| 781 | |
| 782 | if (getLexer().isNot(AsmToken::Comma)) |
| 783 | return TokError("unexpected token in directive"); |
| 784 | Lex(); |
| 785 | |
| 786 | int64_t Size; |
| 787 | SMLoc SizeLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 788 | if (getParser().parseAbsoluteExpression(Size)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 789 | return true; |
| 790 | |
| 791 | int64_t Pow2Alignment = 0; |
| 792 | SMLoc Pow2AlignmentLoc; |
| 793 | if (getLexer().is(AsmToken::Comma)) { |
| 794 | Lex(); |
| 795 | Pow2AlignmentLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 796 | if (getParser().parseAbsoluteExpression(Pow2Alignment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 797 | return true; |
| 798 | } |
| 799 | |
| 800 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 801 | return TokError("unexpected token in '.zerofill' directive"); |
| 802 | |
| 803 | Lex(); |
| 804 | |
| 805 | if (Size < 0) |
| 806 | return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " |
| 807 | "than zero"); |
| 808 | |
| 809 | // NOTE: The alignment in the directive is a power of 2 value, the assembler |
| 810 | // may internally end up wanting an alignment in bytes. |
| 811 | // FIXME: Diagnose overflow. |
| 812 | if (Pow2Alignment < 0) |
| 813 | return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " |
| 814 | "can't be less than zero"); |
| 815 | |
| 816 | if (!Sym->isUndefined()) |
| 817 | return Error(IDLoc, "invalid symbol redefinition"); |
| 818 | |
| 819 | // Create the zerofill Symbol with Size and Pow2Alignment |
| 820 | // |
| 821 | // FIXME: Arch specific. |
| 822 | getStreamer().EmitZerofill(getContext().getMachOSection( |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 823 | Segment, Section, MachO::S_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 824 | 0, SectionKind::getBSS()), |
| 825 | Sym, Size, 1 << Pow2Alignment); |
| 826 | |
| 827 | return false; |
| 828 | } |
| 829 | |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 830 | /// ParseDirectiveDataRegion |
| 831 | /// ::= .data_region [ ( jt8 | jt16 | jt32 ) ] |
| 832 | bool DarwinAsmParser::ParseDirectiveDataRegion(StringRef, SMLoc) { |
| 833 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 834 | Lex(); |
| 835 | getStreamer().EmitDataRegion(MCDR_DataRegion); |
| 836 | return false; |
| 837 | } |
| 838 | StringRef RegionType; |
| 839 | SMLoc Loc = getParser().getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 840 | if (getParser().parseIdentifier(RegionType)) |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 841 | return TokError("expected region type after '.data_region' directive"); |
| 842 | int Kind = StringSwitch<int>(RegionType) |
| 843 | .Case("jt8", MCDR_DataRegionJT8) |
| 844 | .Case("jt16", MCDR_DataRegionJT16) |
| 845 | .Case("jt32", MCDR_DataRegionJT32) |
| 846 | .Default(-1); |
| 847 | if (Kind == -1) |
| 848 | return Error(Loc, "unknown region type in '.data_region' directive"); |
| 849 | Lex(); |
| 850 | |
| 851 | getStreamer().EmitDataRegion((MCDataRegionType)Kind); |
| 852 | return false; |
| 853 | } |
| 854 | |
| 855 | /// ParseDirectiveDataRegionEnd |
| 856 | /// ::= .end_data_region |
| 857 | bool DarwinAsmParser::ParseDirectiveDataRegionEnd(StringRef, SMLoc) { |
| 858 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 859 | return TokError("unexpected token in '.end_data_region' directive"); |
| 860 | |
| 861 | Lex(); |
| 862 | getStreamer().EmitDataRegion(MCDR_DataRegionEnd); |
| 863 | return false; |
| 864 | } |
| 865 | |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame^] | 866 | /// ParseVersionMin |
| 867 | /// ::= .ios_version_min major,minor[,update] |
| 868 | /// ::= .macosx_version_min major,minor[,update] |
| 869 | bool DarwinAsmParser::ParseVersionMin(StringRef Directive, SMLoc) { |
| 870 | int64_t Major = 0, Minor = 0, Update = 0; |
| 871 | int Kind = StringSwitch<int>(Directive) |
| 872 | .Case(".ios_version_min", MCVM_IOSVersionMin) |
| 873 | .Case(".macosx_version_min", MCVM_OSXVersionMin); |
| 874 | // Get the major version number. |
| 875 | if (getLexer().isNot(AsmToken::Integer)) |
| 876 | return TokError("invalid OS major version number"); |
| 877 | Major = getLexer().getTok().getIntVal(); |
| 878 | if (Major > 65535 || Major <= 0) |
| 879 | return TokError("invalid OS major version number"); |
| 880 | Lex(); |
| 881 | if (getLexer().isNot(AsmToken::Comma)) |
| 882 | return TokError("minor OS version number required, comma expected"); |
| 883 | Lex(); |
| 884 | // Get the minor version number. |
| 885 | if (getLexer().isNot(AsmToken::Integer)) |
| 886 | return TokError("invalid OS minor version number"); |
| 887 | Minor = getLexer().getTok().getIntVal(); |
| 888 | if (Minor > 255 || Minor < 0) |
| 889 | return TokError("invalid OS minor version number"); |
| 890 | Lex(); |
| 891 | // Get the update level, if specified |
| 892 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 893 | if (getLexer().isNot(AsmToken::Comma)) |
| 894 | return TokError("invalid update specifier, comma expected"); |
| 895 | Lex(); |
| 896 | if (getLexer().isNot(AsmToken::Integer)) |
| 897 | return TokError("invalid OS update number"); |
| 898 | Update = getLexer().getTok().getIntVal(); |
| 899 | if (Update > 255 || Update < 0) |
| 900 | return TokError("invalid OS update number"); |
| 901 | Lex(); |
| 902 | } |
| 903 | |
| 904 | // We've parsed a correct version specifier, so send it to the streamer. |
| 905 | getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update); |
| 906 | |
| 907 | return false; |
| 908 | } |
| 909 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 910 | namespace llvm { |
| 911 | |
| 912 | MCAsmParserExtension *createDarwinAsmParser() { |
| 913 | return new DarwinAsmParser; |
| 914 | } |
| 915 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 916 | } // end llvm namespace |