MipsTargetInfo.cpp revision d6fd377f3333922c4e928019cdfa124ff7f4dd2e
1//===-- MipsTargetInfo.cpp - Mips Target Implementation -------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Mips.h"
11#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
15Target llvm::TheMipsTarget;
16
17static unsigned Mips_TripleMatchQuality(const std::string &TT) {
18  // We strongly match "mips*-*".
19  if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
20    return 20;
21
22  if (TT.size() >= 13 && std::string(TT.begin(),
23      TT.begin()+13) == "mipsallegrex-")
24    return 20;
25
26  return 0;
27}
28
29static unsigned Mips_ModuleMatchQuality(const Module &M) {
30  // Check for a triple match.
31  if (unsigned Q = Mips_TripleMatchQuality(M.getTargetTriple()))
32    return Q;
33
34  // Otherwise if the target triple is non-empty, we don't match.
35  if (!M.getTargetTriple().empty()) return 0;
36
37  return 0;
38}
39
40Target llvm::TheMipselTarget;
41
42static unsigned Mipsel_TripleMatchQuality(const std::string &TT) {
43  // We strongly match "mips*el-*".
44  if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-")
45    return 20;
46
47  if (TT.size() >= 15 && std::string(TT.begin(),
48      TT.begin()+15) == "mipsallegrexel-")
49    return 20;
50
51  if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp")
52    return 20;
53
54  return 0;
55}
56
57static unsigned Mipsel_ModuleMatchQuality(const Module &M) {
58  // Check for a triple match.
59  if (unsigned Q = Mipsel_TripleMatchQuality(M.getTargetTriple()))
60    return Q;
61
62  // Otherwise if the target triple is non-empty, we don't match.
63  if (!M.getTargetTriple().empty()) return 0;
64
65  return 0;
66}
67
68extern "C" void LLVMInitializeMipsTargetInfo() {
69  TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
70                                  "Mips",
71                                  &Mips_TripleMatchQuality,
72                                  &Mips_ModuleMatchQuality);
73
74  TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
75                                  "Mipsel",
76                                  &Mipsel_TripleMatchQuality,
77                                  &Mipsel_ModuleMatchQuality);
78}
79