19c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar//===- DarwinAsmParser.cpp - Darwin (Mach-O) Assembly Parser --------------===// 29c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// 39c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// The LLVM Compiler Infrastructure 49c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// 59c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// This file is distributed under the University of Illinois Open Source 69c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// License. See LICENSE.TXT for details. 79c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar// 89c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar//===----------------------------------------------------------------------===// 99c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 109c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/MC/MCParser/MCAsmParserExtension.h" 11d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/StringRef.h" 12d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/StringSwitch.h" 13d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/Twine.h" 149c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/MC/MCContext.h" 15d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/MC/MCParser/MCAsmLexer.h" 16d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/MC/MCParser/MCAsmParser.h" 179c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/MC/MCSectionMachO.h" 189c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/MC/MCStreamer.h" 199c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/MC/MCSymbol.h" 20dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines#include "llvm/Support/FileSystem.h" 219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/Support/MemoryBuffer.h" 229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar#include "llvm/Support/SourceMgr.h" 239c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbarusing namespace llvm; 249c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbarnamespace { 269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// \brief Implementation of directive handling which is shared across all 289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// Darwin targets. 299c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbarclass DarwinAsmParser : public MCAsmParserExtension { 30171192f149dce679cd520f85ffced4789448b017Eli Bendersky template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)> 31cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach void addDirectiveHandler(StringRef Directive) { 32171192f149dce679cd520f85ffced4789448b017Eli Bendersky MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair( 33171192f149dce679cd520f85ffced4789448b017Eli Bendersky this, HandleDirective<DarwinAsmParser, HandlerMethod>); 34cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach getParser().addDirectiveHandler(Directive, Handler); 351edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar } 361edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar 3736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionSwitch(const char *Segment, const char *Section, 389c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar unsigned TAA = 0, unsigned ImplicitAlign = 0, 399c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar unsigned StubSize = 0); 409c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 419c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbarpublic: 429c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar DarwinAsmParser() {} 439c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void Initialize(MCAsmParser &Parser) override { 459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Call the base implementation. 469c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar this->MCAsmParserExtension::Initialize(Parser); 479c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(".desc"); 4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>( 504f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby ".indirect_symbol"); 5136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(".lsym"); 5236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>( 531edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar ".subsections_via_symbols"); 5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".dump"); 5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".load"); 5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(".section"); 5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>( 589b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".pushsection"); 5936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>( 609b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".popsection"); 6136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(".previous"); 6236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>( 631edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar ".secure_log_unique"); 6436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>( 651edf6ca2cbb4b01db44683d5e9479a240cfcf497Daniel Dunbar ".secure_log_reset"); 6636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(".tbss"); 6736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(".zerofill"); 689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>( 709b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".data_region"); 7136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>( 729b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".end_data_region"); 733e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach 749c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Special section directives. 7536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(".bss"); 7636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(".const"); 7736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>( 789b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".const_data"); 7936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>( 809b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".constructor"); 8136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>( 829b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".cstring"); 8336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(".data"); 8436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>( 859b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".destructor"); 8636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(".dyld"); 8736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>( 889b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".fvmlib_init0"); 8936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>( 909b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".fvmlib_init1"); 91cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 9236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>( 939b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".lazy_symbol_pointer"); 9436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>( 95cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar ".linker_option"); 9636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>( 979b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".literal16"); 9836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>( 999b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".literal4"); 10036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>( 1019b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".literal8"); 10236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>( 1039b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".mod_init_func"); 10436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>( 1059b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".mod_term_func"); 106cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 10736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>( 1089b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".non_lazy_symbol_pointer"); 10936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>( 1109b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_cat_cls_meth"); 11136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>( 1129b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_cat_inst_meth"); 11336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>( 1149b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_category"); 11536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>( 1169b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_class"); 11736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>( 1189b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_class_names"); 11936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>( 1209b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_class_vars"); 12136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>( 1229b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_cls_meth"); 12336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>( 1249b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_cls_refs"); 12536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>( 1269b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_inst_meth"); 127cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 12836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>( 1299b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_instance_vars"); 13036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>( 1319b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_message_refs"); 13236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>( 1339b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_meta_class"); 134cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 13536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>( 1369b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_meth_var_names"); 137cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 13836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>( 1399b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_meth_var_types"); 14036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>( 1419b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_module_info"); 14236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>( 1439b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_protocol"); 144cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 14536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>( 1469b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_selector_strs"); 147cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach addDirectiveHandler< 14836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines &DarwinAsmParser::parseSectionDirectiveObjCStringObject>( 1499b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_string_object"); 15036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>( 1519b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".objc_symbols"); 15236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>( 1539b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".picsymbol_stub"); 15436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>( 1559b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".static_const"); 15636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>( 1579b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".static_data"); 15836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>( 1599b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".symbol_stub"); 16036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(".tdata"); 16136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(".text"); 16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>( 1639b6a44712a0caef8617adba857f065c5b48b1f45Daniel Dunbar ".thread_init_func"); 16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv"); 16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 16636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident"); 16736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".ios_version_min"); 16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines addDirectiveHandler<&DarwinAsmParser::parseVersionMin>( 16936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ".macosx_version_min"); 17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveDesc(StringRef, SMLoc); 17336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveIndirectSymbol(StringRef, SMLoc); 17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveDumpOrLoad(StringRef, SMLoc); 17536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveLsym(StringRef, SMLoc); 17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveLinkerOption(StringRef, SMLoc); 17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveSection(StringRef, SMLoc); 17836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectivePushSection(StringRef, SMLoc); 17936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectivePopSection(StringRef, SMLoc); 18036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectivePrevious(StringRef, SMLoc); 18136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveSecureLogReset(StringRef, SMLoc); 18236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveSecureLogUnique(StringRef, SMLoc); 18336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc); 18436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveTBSS(StringRef, SMLoc); 18536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveZerofill(StringRef, SMLoc); 18636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveDataRegion(StringRef, SMLoc); 18736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseDirectiveDataRegionEnd(StringRef, SMLoc); 1889c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 1899c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Named Section Directive 19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveBss(StringRef, SMLoc) { 19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__bss"); 19286b4f1a96fc1bc8890398d20b0153b7d434b835cRafael Espindola } 19386b4f1a96fc1bc8890398d20b0153b7d434b835cRafael Espindola 19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveConst(StringRef, SMLoc) { 19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__const"); 1969c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 19736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveStaticConst(StringRef, SMLoc) { 19836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__static_const"); 1999c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 20036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveCString(StringRef, SMLoc) { 20136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__cstring", 20236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_CSTRING_LITERALS); 2039c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 20436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveLiteral4(StringRef, SMLoc) { 20536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__literal4", 20636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_4BYTE_LITERALS, 4); 2079c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 20836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveLiteral8(StringRef, SMLoc) { 20936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__literal8", 21036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_8BYTE_LITERALS, 8); 2119c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 21236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveLiteral16(StringRef, SMLoc) { 21336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__literal16", 21436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_16BYTE_LITERALS, 16); 2159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 21636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveConstructor(StringRef, SMLoc) { 21736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__constructor"); 2189c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 21936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveDestructor(StringRef, SMLoc) { 22036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__destructor"); 2219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 22236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) { 22336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__fvmlib_init0"); 2249c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 22536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) { 22636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__fvmlib_init1"); 2279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 22836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) { 22936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__symbol_stub", 23036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_SYMBOL_STUBS | 23136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_PURE_INSTRUCTIONS, 2329c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Different on PPC and ARM. 2339c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 0, 16); 2349c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 23536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) { 23636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT","__picsymbol_stub", 23736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_SYMBOL_STUBS | 23836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26); 2399c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 24036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveData(StringRef, SMLoc) { 24136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__data"); 2429c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 24336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveStaticData(StringRef, SMLoc) { 24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__static_data"); 2459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 24636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) { 24736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__nl_symbol_ptr", 24836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_NON_LAZY_SYMBOL_POINTERS, 4); 2499c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 25036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) { 25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__la_symbol_ptr", 25236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_LAZY_SYMBOL_POINTERS, 4); 2539c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 25436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveDyld(StringRef, SMLoc) { 25536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__dyld"); 2569c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 25736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) { 25836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__mod_init_func", 25936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_MOD_INIT_FUNC_POINTERS, 4); 2609c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 26136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) { 26236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__mod_term_func", 26336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_MOD_TERM_FUNC_POINTERS, 4); 2649c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 26536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveConstData(StringRef, SMLoc) { 26636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__const"); 2679c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 26836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCClass(StringRef, SMLoc) { 26936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__class", 27036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2719c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 27236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) { 27336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__meta_class", 27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) { 27736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__cat_cls_meth", 27836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 28036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) { 28136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__cat_inst_meth", 28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 28436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) { 28536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__protocol", 28636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2879c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 28836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) { 28936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__string_object", 29036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2919c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 29236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) { 29336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__cls_meth", 29436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2959c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 29636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) { 29736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__inst_meth", 29836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 2999c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 30036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) { 30136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__cls_refs", 30236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP | 30336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_LITERAL_POINTERS, 4); 3049c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 30536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) { 30636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__message_refs", 30736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP | 30836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_LITERAL_POINTERS, 4); 3099c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 31036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) { 31136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__symbols", 31236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 3139c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 31436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) { 31536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__category", 31636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 3179c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 31836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) { 31936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__class_vars", 32036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 3219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 32236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) { 32336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__instance_vars", 32436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 3259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 32636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) { 32736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__module_info", 32836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_NO_DEAD_STRIP); 3299c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 33036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) { 33136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__cstring", 33236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_CSTRING_LITERALS); 3339c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 33436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) { 33536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__cstring", 33636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_CSTRING_LITERALS); 3379c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 33836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) { 33936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__cstring", 34036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_CSTRING_LITERALS); 3419c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 34236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) { 34336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__OBJC", "__selector_strs", 34436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_CSTRING_LITERALS); 3459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 34636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveTData(StringRef, SMLoc) { 34736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__thread_data", 34836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_THREAD_LOCAL_REGULAR); 3499c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 35036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveText(StringRef, SMLoc) { 35136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__TEXT", "__text", 35236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_ATTR_PURE_INSTRUCTIONS); 3539c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 35436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveTLV(StringRef, SMLoc) { 35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__thread_vars", 35636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_THREAD_LOCAL_VARIABLES); 3579c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveIdent(StringRef, SMLoc) { 3598270da8bafb90141ec513e6c71dfcbeb3cb6fe74Jim Grosbach // Darwin silently ignores the .ident directive. 360cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach getParser().eatToEndOfStatement(); 3618270da8bafb90141ec513e6c71dfcbeb3cb6fe74Jim Grosbach return false; 3628270da8bafb90141ec513e6c71dfcbeb3cb6fe74Jim Grosbach } 36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) { 36436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return parseSectionSwitch("__DATA", "__thread_init", 36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS); 3669c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool parseVersionMin(StringRef, SMLoc); 3689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 3699c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar}; 3709c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 371ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling} // end anonymous namespace 3729c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 37336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseSectionSwitch(const char *Segment, 3749c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar const char *Section, 3759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar unsigned TAA, unsigned Align, 3769c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar unsigned StubSize) { 3779c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 3789c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in section switching directive"); 3799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 3809c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 3819c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Arch specific. 38236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS; 3839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().SwitchSection(getContext().getMachOSection( 3849c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Segment, Section, TAA, StubSize, 3859c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar isText ? SectionKind::getText() 3869c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar : SectionKind::getDataRel())); 3879c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 3889c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Set the implicit alignment, if any. 3899c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // 3909c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: This isn't really what 'as' does; I think it just uses the implicit 3919c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // alignment on the section (e.g., if one manually inserts bytes into the 392cf2561d1116b00c7b33649ac6481490a119d5aaeBill Wendling // section, then just issuing the section switch directive will not realign 3939c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // the section. However, this is arguably more reasonable behavior, and there 3949c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // is no good reason for someone to intentionally emit incorrectly sized 3959c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // values into the implicitly aligned sections. 3969c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (Align) 39736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines getStreamer().EmitValueToAlignment(Align); 3989c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 3999c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 4009c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 4019c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveDesc 4039c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .desc identifier , expression 40436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) { 4059c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Name; 406cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(Name)) 4079c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected identifier in directive"); 4089c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4099c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Handle the identifier as the key symbol. 4109c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); 4119c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4129c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 4139c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.desc' directive"); 4149c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 4159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4169c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar int64_t DescValue; 417cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseAbsoluteExpression(DescValue)) 4189c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 4199c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4209c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 4219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.desc' directive"); 4229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4239c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 4249c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Set the n_desc field of this Symbol to this DescValue 4269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().EmitSymbolDesc(Sym, DescValue); 4279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 4299c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 4309c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 43136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveIndirectSymbol 4324f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby/// ::= .indirect_symbol identifier 43336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) { 4344f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby const MCSectionMachO *Current = static_cast<const MCSectionMachO*>( 4354f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby getStreamer().getCurrentSection().first); 43636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::SectionType SectionType = Current->getType(); 43736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS && 43836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines SectionType != MachO::S_LAZY_SYMBOL_POINTERS && 43936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines SectionType != MachO::S_SYMBOL_STUBS) 4404f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return Error(Loc, "indirect symbol not in a symbol pointer or stub " 4414f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby "section"); 4424f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4434f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby StringRef Name; 4444f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby if (getParser().parseIdentifier(Name)) 4454f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return TokError("expected identifier in .indirect_symbol directive"); 4464f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4474f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); 4484f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4494f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby // Assembler local symbols don't make any sense here. Complain loudly. 4504f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby if (Sym->isTemporary()) 4514f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return TokError("non-local symbol required in directive"); 4524f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4534f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_IndirectSymbol)) 4544f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return TokError("unable to emit indirect symbol attribute for: " + Name); 4554f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4564f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby if (getLexer().isNot(AsmToken::EndOfStatement)) 4574f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return TokError("unexpected token in '.indirect_symbol' directive"); 4584f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4594f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby Lex(); 4604f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 4614f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby return false; 4624f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby} 4634f066b6db8a7a95b206725aecf99a64fd6e9415cKevin Enderby 46436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveDumpOrLoad 4659c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= ( .dump | .load ) "filename" 46636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive, 4679c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc IDLoc) { 4689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar bool IsDump = Directive == ".dump"; 4699c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::String)) 4709c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected string in '.dump' or '.load' directive"); 4719c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4729c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 4739c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4749c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 4759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.dump' or '.load' directive"); 4769c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4779c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 4789c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 4799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: If/when .dump and .load are implemented they will be done in the 4809c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // the assembly parser and not have any need for an MCStreamer API. 4819c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (IsDump) 482f8cd708f14a7a172d51899b68809510ae0c4c4c8Joerg Sonnenberger return Warning(IDLoc, "ignoring directive .dump for now"); 4839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar else 484f8cd708f14a7a172d51899b68809510ae0c4c4c8Joerg Sonnenberger return Warning(IDLoc, "ignoring directive .load for now"); 4859c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 4869c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 487cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar/// ParseDirectiveLinkerOption 488cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar/// ::= .linker_option "string" ( , "string" )* 48936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) { 490cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar SmallVector<std::string, 4> Args; 491cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar for (;;) { 492cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar if (getLexer().isNot(AsmToken::String)) 493cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar return TokError("expected string in '" + Twine(IDVal) + "' directive"); 494cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 495cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar std::string Data; 496cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseEscapedString(Data)) 497cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar return true; 498cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 499cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar Args.push_back(Data); 500cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 501cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar Lex(); 502cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar if (getLexer().is(AsmToken::EndOfStatement)) 503cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar break; 504cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 505cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 506cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar return TokError("unexpected token in '" + Twine(IDVal) + "' directive"); 507cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar Lex(); 508cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar } 509cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 510cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar getStreamer().EmitLinkerOptions(Args); 511cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar return false; 512cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar} 513cddd236e8a5acb80e9a0e79dc63f6cfaa8205b86Daniel Dunbar 51436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveLsym 5159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .lsym identifier , expression 51636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) { 5179c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Name; 518cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(Name)) 5199c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected identifier in directive"); 5209c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Handle the identifier as the key symbol. 5229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); 5239c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5249c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 5259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.lsym' directive"); 5269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 5279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar const MCExpr *Value; 529cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseExpression(Value)) 5309c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 5319c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5329c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 5339c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.lsym' directive"); 5349c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5359c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 5369c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5379c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // We don't currently support this directive. 5389c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // 5399c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Diagnostic location! 5409c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar (void) Sym; 5419c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("directive '.lsym' is unsupported"); 5429c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 5439c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 54436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveSection: 5459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .section identifier (',' identifier)* 54636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) { 5479c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc Loc = getLexer().getLoc(); 5489c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5499c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef SectionName; 550cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(SectionName)) 5519c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(Loc, "expected identifier after '.section' directive"); 5529c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5539c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Verify there is a following comma. 5549c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (!getLexer().is(AsmToken::Comma)) 5559c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.section' directive"); 5569c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5579c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar std::string SectionSpec = SectionName; 5589c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SectionSpec += ","; 5599c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5609c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Add all the tokens until the end of the line, ParseSectionSpecifier will 5619c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // handle this. 5629c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef EOL = getLexer().LexUntilEndOfStatement(); 5639c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SectionSpec.append(EOL.begin(), EOL.end()); 5649c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5659c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 5669c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 5679c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.section' directive"); 5689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 5699c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5709c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5719c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Segment, Section; 5728d06ffca9b72ebef7f5b8830b7ccbd9dd74f8e18Daniel Dunbar unsigned StubSize; 57365c8bca78854712ab2bf135c2008ed455ef0c9b7Stuart Hastings unsigned TAA; 57465c8bca78854712ab2bf135c2008ed455ef0c9b7Stuart Hastings bool TAAParsed; 5759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar std::string ErrorStr = 5769c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section, 57765c8bca78854712ab2bf135c2008ed455ef0c9b7Stuart Hastings TAA, TAAParsed, StubSize); 5789c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (!ErrorStr.empty()) 5809c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(Loc, ErrorStr.c_str()); 5819c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 5829c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Arch specific. 5839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar bool isText = Segment == "__TEXT"; // FIXME: Hack. 5849c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().SwitchSection(getContext().getMachOSection( 5859c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Segment, Section, TAA, StubSize, 5869c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar isText ? SectionKind::getText() 5879c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar : SectionKind::getDataRel())); 5889c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 5899c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 5909c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 591ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ParseDirectivePushSection: 592ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ::= .pushsection identifier (',' identifier)* 59336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) { 594ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling getStreamer().PushSection(); 595ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling 59636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (parseDirectiveSection(S, Loc)) { 597ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling getStreamer().PopSection(); 598ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling return true; 599ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling } 600ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling 601ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling return false; 602ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling} 603ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling 604ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ParseDirectivePopSection: 605ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ::= .popsection 60636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) { 607ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling if (!getStreamer().PopSection()) 608ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling return TokError(".popsection without corresponding .pushsection"); 609ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling return false; 610ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling} 611ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling 612ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ParseDirectivePrevious: 613ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling/// ::= .previous 61436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) { 615df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne MCSectionSubPair PreviousSection = getStreamer().getPreviousSection(); 616dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines if (!PreviousSection.first) 617dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return TokError(".previous without corresponding .section"); 618df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second); 619ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling return false; 620ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling} 621ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling 6229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ParseDirectiveSecureLogUnique 6236a46d571b461246e36f82c146e17bf614d2114eaDaniel Dunbar/// ::= .secure_log_unique ... message ... 62436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) { 625cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach StringRef LogMessage = getParser().parseStringToEndOfStatement(); 6269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 6279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.secure_log_unique' directive"); 6289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6294c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar if (getContext().getSecureLogUsed()) 6309c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(IDLoc, ".secure_log_unique specified multiple times"); 6319c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6326a46d571b461246e36f82c146e17bf614d2114eaDaniel Dunbar // Get the secure log path. 6336a46d571b461246e36f82c146e17bf614d2114eaDaniel Dunbar const char *SecureLogFile = getContext().getSecureLogFile(); 634dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines if (!SecureLogFile) 6359c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE " 6369c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "environment variable unset."); 6379c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6386a46d571b461246e36f82c146e17bf614d2114eaDaniel Dunbar // Open the secure log file if we haven't already. 6399c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar raw_ostream *OS = getContext().getSecureLog(); 640dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines if (!OS) { 64137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines std::error_code EC; 64237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines OS = new raw_fd_ostream(SecureLogFile, EC, 64336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines sys::fs::F_Append | sys::fs::F_Text); 64437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines if (EC) { 6459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar delete OS; 6469c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(IDLoc, Twine("can't open secure log file: ") + 64737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines SecureLogFile + " (" + EC.message() + ")"); 6489c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 6499c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getContext().setSecureLog(OS); 6509c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 6519c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6526a46d571b461246e36f82c146e17bf614d2114eaDaniel Dunbar // Write the message. 653c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc); 6549c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier() 6559c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":" 6569c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar << LogMessage + "\n"; 6579c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6589c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getContext().setSecureLogUsed(true); 6599c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6609c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 6619c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 6629c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6639c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ParseDirectiveSecureLogReset 6649c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .secure_log_reset 66536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) { 6669c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 6679c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.secure_log_reset' directive"); 6689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6699c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 6709c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6719c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getContext().setSecureLogUsed(false); 6729c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6739c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 6749c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 6759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 67636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseDirectiveSubsectionsViaSymbols 6779c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .subsections_via_symbols 67836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) { 6799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 6809c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.subsections_via_symbols' directive"); 6819c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6829c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 6839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6849c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); 6859c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6869c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 6879c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 6889c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6899c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ParseDirectiveTBSS 6909c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .tbss identifier, size, align 69136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) { 6929c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc IDLoc = getLexer().getLoc(); 6939c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Name; 694cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(Name)) 6959c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected identifier in directive"); 6969c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 6979c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Handle the identifier as the key symbol. 6989c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); 6999c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7009c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 7019c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in directive"); 7029c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7039c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7049c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar int64_t Size; 7059c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc SizeLoc = getLexer().getLoc(); 706cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseAbsoluteExpression(Size)) 7079c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 7089c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7099c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar int64_t Pow2Alignment = 0; 7109c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc Pow2AlignmentLoc; 7119c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().is(AsmToken::Comma)) { 7129c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7139c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Pow2AlignmentLoc = getLexer().getLoc(); 714cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseAbsoluteExpression(Pow2Alignment)) 7159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 7169c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 7179c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7189c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 7199c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.tbss' directive"); 7209c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7239c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (Size < 0) 7249c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than" 7259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "zero"); 7269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Diagnose overflow. 7289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (Pow2Alignment < 0) 7299c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less" 7309c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "than zero"); 7319c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7329c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (!Sym->isUndefined()) 7339c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(IDLoc, "invalid symbol redefinition"); 7349c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7359c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().EmitTBSSSymbol(getContext().getMachOSection( 7369c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "__DATA", "__thread_bss", 73736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachO::S_THREAD_LOCAL_ZEROFILL, 7389c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 0, SectionKind::getThreadBSS()), 7399c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Sym, Size, 1 << Pow2Alignment); 7409c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7419c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 7429c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 7439c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7449c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ParseDirectiveZerofill 7459c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// ::= .zerofill segname , sectname [, identifier , size_expression [ 7469c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar/// , align_expression ]] 74736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) { 7489c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Segment; 749cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(Segment)) 7509c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected segment name after '.zerofill' directive"); 7519c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7529c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 7539c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in directive"); 7549c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7559c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7569c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef Section; 757cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(Section)) 7589c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected section name after comma in '.zerofill' " 7599c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "directive"); 7609c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7619c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // If this is the end of the line all that was wanted was to create the 7629c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // the section but with no symbol. 7639c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().is(AsmToken::EndOfStatement)) { 7649c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Create the zerofill section but no symbol 7659c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().EmitZerofill(getContext().getMachOSection( 76636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Segment, Section, MachO::S_ZEROFILL, 7679c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 0, SectionKind::getBSS())); 7689c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 7699c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 7709c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7719c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 7729c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in directive"); 7739c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7749c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7759c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc IDLoc = getLexer().getLoc(); 7769c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar StringRef IDStr; 777cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(IDStr)) 7789c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("expected identifier in directive"); 7799c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7809c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // handle the identifier as the key symbol. 7819c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr); 7829c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7839c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::Comma)) 7849c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in directive"); 7859c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7869c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7879c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar int64_t Size; 7889c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc SizeLoc = getLexer().getLoc(); 789cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseAbsoluteExpression(Size)) 7909c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 7919c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 7929c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar int64_t Pow2Alignment = 0; 7939c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar SMLoc Pow2AlignmentLoc; 7949c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().is(AsmToken::Comma)) { 7959c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 7969c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Pow2AlignmentLoc = getLexer().getLoc(); 797cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseAbsoluteExpression(Pow2Alignment)) 7989c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return true; 7999c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar } 8009c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8019c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (getLexer().isNot(AsmToken::EndOfStatement)) 8029c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return TokError("unexpected token in '.zerofill' directive"); 8039c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8049c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Lex(); 8059c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8069c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (Size < 0) 8079c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " 8089c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "than zero"); 8099c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8109c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // NOTE: The alignment in the directive is a power of 2 value, the assembler 8119c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // may internally end up wanting an alignment in bytes. 8129c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Diagnose overflow. 8139c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (Pow2Alignment < 0) 8149c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " 8159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar "can't be less than zero"); 8169c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8179c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar if (!Sym->isUndefined()) 8189c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return Error(IDLoc, "invalid symbol redefinition"); 8199c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8209c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // Create the zerofill Symbol with Size and Pow2Alignment 8219c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // 8229c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar // FIXME: Arch specific. 8239c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar getStreamer().EmitZerofill(getContext().getMachOSection( 82436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Segment, Section, MachO::S_ZEROFILL, 8259c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 0, SectionKind::getBSS()), 8269c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar Sym, Size, 1 << Pow2Alignment); 8279c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8289c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return false; 8299c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 8309c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 8313e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach/// ParseDirectiveDataRegion 8323e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach/// ::= .data_region [ ( jt8 | jt16 | jt32 ) ] 83336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) { 8343e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach if (getLexer().is(AsmToken::EndOfStatement)) { 8353e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach Lex(); 8363e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach getStreamer().EmitDataRegion(MCDR_DataRegion); 8373e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return false; 8383e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach } 8393e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach StringRef RegionType; 8403e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach SMLoc Loc = getParser().getTok().getLoc(); 841cb2ae3d98e3bb36e5813f8f69b00d39efd026dcdJim Grosbach if (getParser().parseIdentifier(RegionType)) 8423e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return TokError("expected region type after '.data_region' directive"); 8433e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach int Kind = StringSwitch<int>(RegionType) 8443e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach .Case("jt8", MCDR_DataRegionJT8) 8453e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach .Case("jt16", MCDR_DataRegionJT16) 8463e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach .Case("jt32", MCDR_DataRegionJT32) 8473e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach .Default(-1); 8483e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach if (Kind == -1) 8493e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return Error(Loc, "unknown region type in '.data_region' directive"); 8503e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach Lex(); 8513e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach 8523e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach getStreamer().EmitDataRegion((MCDataRegionType)Kind); 8533e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return false; 8543e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach} 8553e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach 8563e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach/// ParseDirectiveDataRegionEnd 8573e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach/// ::= .end_data_region 85836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) { 8593e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach if (getLexer().isNot(AsmToken::EndOfStatement)) 8603e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return TokError("unexpected token in '.end_data_region' directive"); 8613e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach 8623e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach Lex(); 8633e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach getStreamer().EmitDataRegion(MCDR_DataRegionEnd); 8643e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach return false; 8653e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach} 8663e96531186ba574b0c25a4be62d24b8b7d752c9fJim Grosbach 86736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// parseVersionMin 86836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// ::= .ios_version_min major,minor[,update] 86936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// ::= .macosx_version_min major,minor[,update] 87036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc) { 87136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int64_t Major = 0, Minor = 0, Update = 0; 87236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int Kind = StringSwitch<int>(Directive) 87336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines .Case(".ios_version_min", MCVM_IOSVersionMin) 87436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines .Case(".macosx_version_min", MCVM_OSXVersionMin); 87536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Get the major version number. 87636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::Integer)) 87736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS major version number"); 87836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Major = getLexer().getTok().getIntVal(); 87936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (Major > 65535 || Major <= 0) 88036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS major version number"); 88136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Lex(); 88236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::Comma)) 88336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("minor OS version number required, comma expected"); 88436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Lex(); 88536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Get the minor version number. 88636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::Integer)) 88736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS minor version number"); 88836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Minor = getLexer().getTok().getIntVal(); 88936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (Minor > 255 || Minor < 0) 89036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS minor version number"); 89136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Lex(); 89236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Get the update level, if specified 89336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::EndOfStatement)) { 89436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::Comma)) 89536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid update specifier, comma expected"); 89636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Lex(); 89736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (getLexer().isNot(AsmToken::Integer)) 89836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS update number"); 89936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Update = getLexer().getTok().getIntVal(); 90036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (Update > 255 || Update < 0) 90136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TokError("invalid OS update number"); 90236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Lex(); 90336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 90436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 90536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // We've parsed a correct version specifier, so send it to the streamer. 90636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update); 90736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 90836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return false; 90936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 91036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 9119c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbarnamespace llvm { 9129c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 9139c23d7f25ec2132292208799386e993cf661dfb5Daniel DunbarMCAsmParserExtension *createDarwinAsmParser() { 9149c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar return new DarwinAsmParser; 9159c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar} 9169c23d7f25ec2132292208799386e993cf661dfb5Daniel Dunbar 917ef920552d4fb0959097f1c165cfc81c69db19934Bill Wendling} // end llvm namespace 918