Commit 6c3d6a0b authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r227085:

------------------------------------------------------------------------
r227085 | joerg | 2015-01-26 03:41:48 -0800 (Mon, 26 Jan 2015) | 13 lines

The canonical CPU variant for ARM according to config.guess uses a
suffix it seems:

    # ./config.guess
    earmv7hfeb-unknown-netbsd7.99.4

Extend the triple parsing to support this. Avoid running the ARM parser
multiple times because StringSwitch is not lazy.

Reviewers: Renato Golin, Tim Northover

Differential Revision: http://reviews.llvm.org/D7166

------------------------------------------------------------------------

llvm-svn: 227394
parent 3f065cca
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -246,12 +246,20 @@ static Triple::ArchType parseARMArch(StringRef ArchName) {

  if (ArchName.startswith("armv")) {
    offset = 3;
    if (ArchName.endswith("eb")) {
      arch = Triple::armeb;
      ArchName = ArchName.substr(0, ArchName.size() - 2);
    } else
      arch = Triple::arm;
  } else if (ArchName.startswith("armebv")) {
    offset = 5;
    arch = Triple::armeb;
  } else if (ArchName.startswith("thumbv")) {
    offset = 5;
    if (ArchName.endswith("eb")) {
      arch = Triple::thumbeb;
      ArchName = ArchName.substr(0, ArchName.size() - 2);
    } else
      arch = Triple::thumb;
  } else if (ArchName.startswith("thumbebv")) {
    offset = 7;
@@ -271,6 +279,8 @@ static Triple::ArchType parseARMArch(StringRef ArchName) {
}

static Triple::ArchType parseArch(StringRef ArchName) {
  Triple::ArchType ARMArch(parseARMArch(ArchName));

  return StringSwitch<Triple::ArchType>(ArchName)
    .Cases("i386", "i486", "i586", "i686", Triple::x86)
    // FIXME: Do we need to support these?
@@ -280,9 +290,10 @@ static Triple::ArchType parseArch(StringRef ArchName) {
    .Cases("powerpc64", "ppu", Triple::ppc64)
    .Case("powerpc64le", Triple::ppc64le)
    .Case("xscale", Triple::arm)
    .StartsWith("arm", parseARMArch(ArchName))
    .StartsWith("thumb", parseARMArch(ArchName))
    .StartsWith("aarch64", parseARMArch(ArchName))
    .Case("xscaleeb", Triple::armeb)
    .StartsWith("arm", ARMArch)
    .StartsWith("thumb", ARMArch)
    .StartsWith("aarch64", ARMArch)
    .Case("msp430", Triple::msp430)
    .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
    .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
@@ -379,6 +390,9 @@ static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
}

static Triple::SubArchType parseSubArch(StringRef SubArchName) {
  if (SubArchName.endswith("eb"))
    SubArchName = SubArchName.substr(0, SubArchName.size() - 2);

  return StringSwitch<Triple::SubArchType>(SubArchName)
    .EndsWith("v8", Triple::ARMSubArch_v8)
    .EndsWith("v8a", Triple::ARMSubArch_v8)
@@ -1022,6 +1036,8 @@ const char *Triple::getARMCPUForArch(StringRef MArch) const {
    offset = 5;
  if (offset != StringRef::npos && MArch.substr(offset, 2) == "eb")
    offset += 2;
  if (MArch.endswith("eb"))
    MArch = MArch.substr(0, MArch.size() - 2);
  if (offset != StringRef::npos)
    result = llvm::StringSwitch<const char *>(MArch.substr(offset))
      .Cases("v2", "v2a", "arm2")
+17 −0
Original line number Diff line number Diff line
@@ -665,3 +665,20 @@ TEST(TripleTest, getARMCPUForArch) {
  }
}
}

TEST(TripleTest, NormalizeARM) {
  EXPECT_EQ("armv6--netbsd-eabi", Triple::normalize("armv6-netbsd-eabi"));
  EXPECT_EQ("armv7--netbsd-eabi", Triple::normalize("armv7-netbsd-eabi"));
  EXPECT_EQ("armv6eb--netbsd-eabi", Triple::normalize("armv6eb-netbsd-eabi"));
  EXPECT_EQ("armv7eb--netbsd-eabi", Triple::normalize("armv7eb-netbsd-eabi"));
  EXPECT_EQ("armv6--netbsd-eabihf", Triple::normalize("armv6-netbsd-eabihf"));
  EXPECT_EQ("armv7--netbsd-eabihf", Triple::normalize("armv7-netbsd-eabihf"));
  EXPECT_EQ("armv6eb--netbsd-eabihf", Triple::normalize("armv6eb-netbsd-eabihf"));
  EXPECT_EQ("armv7eb--netbsd-eabihf", Triple::normalize("armv7eb-netbsd-eabihf"));

  Triple T;
  T = Triple("armv6--netbsd-eabi");
  EXPECT_EQ(Triple::arm, T.getArch());
  T = Triple("armv6eb--netbsd-eabi");
  EXPECT_EQ(Triple::armeb, T.getArch());
}