llvm.org GIT mirror llvm / 2a65dd3
ARM: consolidate MachO checks for ARM asm parser This consolidates the duplicated MachO checks in the directive parsing for various directives that are unsupported for Mach-O. The error message change is unimportant as this restores the behaviour to that prior to the addition of the new directive handling. Furthermore, use a more direct check for MachO targeting rather than an indirect feature check of the assembler. Also simplify the test execution command to avoid temporary files. Further more, perform the check in both object and assembly emission. Whether all non-applicable directives are handled is another question. .fnstart is marked as being unsupported, however, the complementary .fnend is not. The additional unwinding directives are also still honoured. This change does not change that, though, it would be good to validate and mark them as being unsupported if they are unsupported for the MachO emission. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205678 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 6 years ago
2 changed file(s) with 42 addition(s) and 93 deletion(s). Raw diff Collapse all Expand all
79747974
79757975 /// parseDirective parses the arm specific directives
79767976 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7977 const MCObjectFileInfo::Environment Format =
7978 getContext().getObjectFileInfo()->getObjectFileType();
7979 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
7980
79777981 StringRef IDVal = DirectiveID.getIdentifier();
79787982 if (IDVal == ".word")
79797983 return parseLiteralValues(4, DirectiveID.getLoc());
79917995 return parseDirectiveSyntax(DirectiveID.getLoc());
79927996 else if (IDVal == ".unreq")
79937997 return parseDirectiveUnreq(DirectiveID.getLoc());
7994 else if (IDVal == ".arch")
7995 return parseDirectiveArch(DirectiveID.getLoc());
7996 else if (IDVal == ".eabi_attribute")
7997 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7998 else if (IDVal == ".cpu")
7999 return parseDirectiveCPU(DirectiveID.getLoc());
8000 else if (IDVal == ".fpu")
8001 return parseDirectiveFPU(DirectiveID.getLoc());
8002 else if (IDVal == ".fnstart")
8003 return parseDirectiveFnStart(DirectiveID.getLoc());
80047998 else if (IDVal == ".fnend")
80057999 return parseDirectiveFnEnd(DirectiveID.getLoc());
80068000 else if (IDVal == ".cantunwind")
80178011 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
80188012 else if (IDVal == ".vsave")
80198013 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
8020 else if (IDVal == ".inst")
8021 return parseDirectiveInst(DirectiveID.getLoc());
8022 else if (IDVal == ".inst.n")
8023 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8024 else if (IDVal == ".inst.w")
8025 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
80268014 else if (IDVal == ".ltorg" || IDVal == ".pool")
80278015 return parseDirectiveLtorg(DirectiveID.getLoc());
80288016 else if (IDVal == ".even")
80318019 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
80328020 else if (IDVal == ".unwind_raw")
80338021 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
8034 else if (IDVal == ".tlsdescseq")
8035 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
80368022 else if (IDVal == ".movsp")
80378023 return parseDirectiveMovSP(DirectiveID.getLoc());
8038 else if (IDVal == ".object_arch")
8039 return parseDirectiveObjectArch(DirectiveID.getLoc());
80408024 else if (IDVal == ".arch_extension")
80418025 return parseDirectiveArchExtension(DirectiveID.getLoc());
80428026 else if (IDVal == ".align")
80438027 return parseDirectiveAlign(DirectiveID.getLoc());
80448028 else if (IDVal == ".thumb_set")
80458029 return parseDirectiveThumbSet(DirectiveID.getLoc());
8030
8031 if (!IsMachO) {
8032 if (IDVal == ".arch")
8033 return parseDirectiveArch(DirectiveID.getLoc());
8034 else if (IDVal == ".cpu")
8035 return parseDirectiveCPU(DirectiveID.getLoc());
8036 else if (IDVal == ".eabi_attribute")
8037 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8038 else if (IDVal == ".fpu")
8039 return parseDirectiveFPU(DirectiveID.getLoc());
8040 else if (IDVal == ".fnstart")
8041 return parseDirectiveFnStart(DirectiveID.getLoc());
8042 else if (IDVal == ".inst")
8043 return parseDirectiveInst(DirectiveID.getLoc());
8044 else if (IDVal == ".inst.n")
8045 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8046 else if (IDVal == ".inst.w")
8047 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8048 else if (IDVal == ".object_arch")
8049 return parseDirectiveObjectArch(DirectiveID.getLoc());
8050 else if (IDVal == ".tlsdescseq")
8051 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8052 }
8053
80468054 return true;
80478055 }
80488056
83058313 /// parseDirectiveArch
83068314 /// ::= .arch token
83078315 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8308 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8309 bool isMachO = MAI->hasSubsectionsViaSymbols();
8310 if (isMachO) {
8311 Error(L, ".arch directive not valid for Mach-O");
8312 Parser.eatToEndOfStatement();
8313 return false;
8314 }
8315
83168316 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
83178317
83188318 unsigned ID = StringSwitch(Arch)
83368336 /// ::= .eabi_attribute int, int [, "str"]
83378337 /// ::= .eabi_attribute Tag_name, int [, "str"]
83388338 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8339 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8340 bool isMachO = MAI->hasSubsectionsViaSymbols();
8341 if (isMachO) {
8342 Error(L, ".eabi_attribute directive not valid for Mach-O");
8343 Parser.eatToEndOfStatement();
8344 return false;
8345 }
8346
83478339 int64_t Tag;
83488340 SMLoc TagLoc;
83498341 TagLoc = Parser.getTok().getLoc();
84498441 /// parseDirectiveCPU
84508442 /// ::= .cpu str
84518443 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8452 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8453 bool isMachO = MAI->hasSubsectionsViaSymbols();
8454 if (isMachO) {
8455 Error(L, ".cpu directive not valid for Mach-O");
8456 Parser.eatToEndOfStatement();
8457 return false;
8458 }
8459
84608444 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
84618445 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
84628446 return false;
84658449 /// parseDirectiveFPU
84668450 /// ::= .fpu str
84678451 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8468 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8469 bool isMachO = MAI->hasSubsectionsViaSymbols();
8470 if (isMachO) {
8471 Error(L, ".fpu directive not valid for Mach-O");
8472 Parser.eatToEndOfStatement();
8473 return false;
8474 }
8475
84768452 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
84778453
84788454 unsigned ID = StringSwitch(FPU)
84928468 /// parseDirectiveFnStart
84938469 /// ::= .fnstart
84948470 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8495 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8496 bool isMachO = MAI->hasSubsectionsViaSymbols();
8497 if (isMachO) {
8498 Error(L, ".fnstart directive not valid for Mach-O");
8499 Parser.eatToEndOfStatement();
8500 return false;
8501 }
8502
85038471 if (UC.hasFnStart()) {
85048472 Error(L, ".fnstart starts before the end of previous one");
85058473 UC.emitFnStartLocNotes();
87798747 /// ::= .inst.n opcode [, ...]
87808748 /// ::= .inst.w opcode [, ...]
87818749 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8782 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8783 bool isMachO = MAI->hasSubsectionsViaSymbols();
8784 if (isMachO) {
8785 Error(Loc, ".inst directive not valid for Mach-O");
8786 Parser.eatToEndOfStatement();
8787 return false;
8788 }
8789
87908750 int Width;
87918751
87928752 if (isThumb()) {
90358995 /// parseDirectiveTLSDescSeq
90368996 /// ::= .tlsdescseq tls-variable
90378997 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9038 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
9039 bool isMachO = MAI->hasSubsectionsViaSymbols();
9040 if (isMachO) {
9041 Error(L, ".tlsdescseq directive not valid for Mach-O");
9042 Parser.eatToEndOfStatement();
9043 return false;
9044 }
9045
90468998 if (getLexer().isNot(AsmToken::Identifier)) {
90478999 TokError("expected variable after '.tlsdescseq' directive");
90489000 Parser.eatToEndOfStatement();
91309082 /// parseDirectiveObjectArch
91319083 /// ::= .object_arch name
91329084 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9133 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
9134 bool isMachO = MAI->hasSubsectionsViaSymbols();
9135 if (isMachO) {
9136 Error(L, ".object_arch directive not valid for Mach-O");
9137 Parser.eatToEndOfStatement();
9138 return false;
9139 }
9140
91419085 if (getLexer().isNot(AsmToken::Identifier)) {
91429086 Error(getLexer().getLoc(), "unexpected token");
91439087 Parser.eatToEndOfStatement();
None @ RUN: not llvm-mc -n -triple armv7-apple-darwin10 %s -filetype=obj -o - 2> %t.err > %t
1 @ RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
0 @ RUN: not llvm-mc -n -triple armv7-apple-darwin10 %s -filetype asm -o /dev/null 2>&1 \
1 @ RUN: | FileCheck --check-prefix CHECK-ERROR %s
2
3 @ RUN: not llvm-mc -n -triple armv7-apple-darwin10 %s -filetype obj -o /dev/null 2>&1 \
4 @ RUN: | FileCheck --check-prefix CHECK-ERROR %s
5
26 @ rdar://16335232
37
48 .eabi_attribute 8, 1
5 @ CHECK-ERROR: error: .eabi_attribute directive not valid for Mach-O
9 @ CHECK-ERROR: error: unknown directive
610
711 .cpu
8 @ CHECK-ERROR: error: .cpu directive not valid for Mach-O
12 @ CHECK-ERROR: error: unknown directive
913
1014 .fpu neon
11 @ CHECK-ERROR: error: .fpu directive not valid for Mach-O
15 @ CHECK-ERROR: error: unknown directive
1216
1317 .arch armv7
14 @ CHECK-ERROR: error: .arch directive not valid for Mach-O
18 @ CHECK-ERROR: error: unknown directive
1519
1620 .fnstart
17 @ CHECK-ERROR: error: .fnstart directive not valid for Mach-O
21 @ CHECK-ERROR: error: unknown directive
1822
1923 .tlsdescseq
20 @ CHECK-ERROR: error: .tlsdescseq directive not valid for Mach-O
24 @ CHECK-ERROR: error: unknown directive
2125
2226 .object_arch armv7
23 @ CHECK-ERROR: error: .object_arch directive not valid for Mach-O
27 @ CHECK-ERROR: error: unknown directive
28