llvm.org GIT mirror llvm / 61bc405
[mips] Print warning when using register names not available in N32/64 Summary: The register names t4-t7 are not available in the N32 and N64 ABIs. This patch prints a warning, when those names are used in N32/64, along with a fix-it with the correct register names. Patch by Vasileios Kalintiris Reviewers: dsanders Reviewed By: dsanders Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5272 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218989 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 6 years ago
4 changed file(s) with 58 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
7373
7474 SMLoc getLoc() const;
7575 SMLoc getEndLoc() const;
76 SMRange getLocRange() const;
7677
7778 /// getStringContents - Get the contents of a string token (without quotes).
7879 StringRef getStringContents() const {
2929 SMLoc AsmToken::getEndLoc() const {
3030 return SMLoc::getFromPointer(Str.data() + Str.size());
3131 }
32
33 SMRange AsmToken::getLocRange() const {
34 return SMRange(getLoc(), getEndLoc());
35 }
2626 #include "llvm/Support/Debug.h"
2727 #include "llvm/Support/MathExtras.h"
2828 #include "llvm/Support/TargetRegistry.h"
29 #include "llvm/Support/SourceMgr.h"
2930 #include
3031
3132 using namespace llvm;
99100 // nullptr, which indicates that no function is currently
100101 // selected. This usually happens after an '.end func'
101102 // directive.
103
104 // Print a warning along with its fix-it message at the given range.
105 void printWarningWithFixIt(const Twine &Msg, const Twine &FixMsg,
106 SMRange Range, bool ShowColors = true);
102107
103108 #define GET_ASSEMBLER_HEADER
104109 #include "MipsGenAsmMatcher.inc"
16181623 }
16191624 }
16201625
1626 void
1627 MipsAsmParser::printWarningWithFixIt(const Twine &Msg, const Twine &FixMsg,
1628 SMRange Range, bool ShowColors) {
1629 getSourceManager().PrintMessage(Range.Start, SourceMgr::DK_Warning, Msg,
1630 { Range }, { SMFixIt(Range, FixMsg) },
1631 ShowColors);
1632 }
1633
16211634 int MipsAsmParser::matchCPURegisterName(StringRef Name) {
16221635 int CC;
16231636
16591672
16601673 if (!(isABI_N32() || isABI_N64()))
16611674 return CC;
1675
1676 if (12 <= CC && CC <= 15) {
1677 // Name is one of t4-t7
1678 AsmToken RegTok = getLexer().peekTok();
1679 SMRange RegRange = RegTok.getLocRange();
1680
1681 StringRef FixedName = StringSwitch(Name)
1682 .Case("t4", "t0")
1683 .Case("t5", "t1")
1684 .Case("t6", "t2")
1685 .Case("t7", "t3")
1686 .Default("");
1687 assert(FixedName != "" && "Register name is not one of t4-t7.");
1688
1689 printWarningWithFixIt("register names $t4-$t7 are only available in O32.",
1690 "Did you mean $" + FixedName + "?", RegRange);
1691 }
16621692
16631693 // Although SGI documentation just cuts out t0-t3 for n32/n64,
16641694 // GNU pushes the values of t0-t3 to override the o32/o64 values for t4-t7
None # RUN: llvm-mc %s -triple=mips64-unknown-freebsd -show-encoding | FileCheck %s
0 # RUN: llvm-mc %s -triple=mips64-unknown-freebsd -show-encoding 2>%t0 \
1 # RUN: | FileCheck %s
2 # RUN: FileCheck -check-prefix=WARNING %s < %t0
3 #
14 # RUN: llvm-mc %s -triple=mips64-unknown-freebsd -show-encoding \
2 # RUN: -mattr=-n64,+n32 | FileCheck %s
3
5 # RUN: -mattr=-n64,+n32 2>%t1 | FileCheck %s
6 # RUN: FileCheck -check-prefix=WARNING %s < %t1
7 #
48 # Check that the register names are mapped to their correct numbers for n32/n64
59 # Second byte of addiu with $zero at rt contains the number of the source
610 # register.
2226 daddiu $t1, $zero, 0 # [*] # CHECK: encoding: [0x64,0x0d,0x00,0x00]
2327 daddiu $t2, $zero, 0 # [*] # CHECK: encoding: [0x64,0x0e,0x00,0x00]
2428 daddiu $t3, $zero, 0 # [*] # CHECK: encoding: [0x64,0x0f,0x00,0x00]
29 # WARNING: mips64-register-names-n32-n64.s:[[@LINE+4]]:9: warning: register names $t4-$t7 are only available in O32.
30 # WARNING-NEXT: daddiu $t4, $zero, 0 # {{CHECK}}: encoding: [0x64,0x0c,0x00,0x00]
31 # WARNING-NEXT: ^~
32 # WARNING-NEXT: Did you mean $t0?
2533 daddiu $t4, $zero, 0 # CHECK: encoding: [0x64,0x0c,0x00,0x00]
34 # WARNING: mips64-register-names-n32-n64.s:[[@LINE+4]]:9: warning: register names $t4-$t7 are only available in O32.
35 # WARNING-NEXT: daddiu $t5, $zero, 0 # {{CHECK}}: encoding: [0x64,0x0d,0x00,0x00]
36 # WARNING-NEXT: ^~
37 # WARNING-NEXT: Did you mean $t1?
2638 daddiu $t5, $zero, 0 # CHECK: encoding: [0x64,0x0d,0x00,0x00]
39 # WARNING: mips64-register-names-n32-n64.s:[[@LINE+4]]:9: warning: register names $t4-$t7 are only available in O32.
40 # WARNING-NEXT: daddiu $t6, $zero, 0 # {{CHECK}}: encoding: [0x64,0x0e,0x00,0x00]
41 # WARNING-NEXT: ^~
42 # WARNING-NEXT: Did you mean $t2?
2743 daddiu $t6, $zero, 0 # CHECK: encoding: [0x64,0x0e,0x00,0x00]
44 # WARNING: mips64-register-names-n32-n64.s:[[@LINE+4]]:9: warning: register names $t4-$t7 are only available in O32.
45 # WARNING-NEXT: daddiu $t7, $zero, 0 # {{CHECK}}: encoding: [0x64,0x0f,0x00,0x00]
46 # WARNING-NEXT: ^~
47 # WARNING-NEXT: Did you mean $t3?
2848 daddiu $t7, $zero, 0 # CHECK: encoding: [0x64,0x0f,0x00,0x00]
2949 daddiu $s0, $zero, 0 # CHECK: encoding: [0x64,0x10,0x00,0x00]
3050 daddiu $s1, $zero, 0 # CHECK: encoding: [0x64,0x11,0x00,0x00]