blob: 35cbf8b883615dde9de2533f518f8fd5a0ef6a3b [file] [log] [blame]
Daniel Dunbarc984df82009-07-15 06:35:19 +00001//===-- 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
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000010#include "Mips.h"
Daniel Dunbarc984df82009-07-15 06:35:19 +000011#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000015Target llvm::TheMipsTarget;
Daniel Dunbarc984df82009-07-15 06:35:19 +000016
Daniel Dunbarc984df82009-07-15 06:35:19 +000017static 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
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000040Target llvm::TheMipselTarget;
Daniel Dunbarc984df82009-07-15 06:35:19 +000041
Daniel Dunbarc984df82009-07-15 06:35:19 +000042static 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,
Daniel Dunbard6fd3772009-07-25 10:09:50 +000072 &Mips_ModuleMatchQuality);
Daniel Dunbarc984df82009-07-15 06:35:19 +000073
74 TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
75 "Mipsel",
76 &Mipsel_TripleMatchQuality,
Daniel Dunbard6fd3772009-07-25 10:09:50 +000077 &Mipsel_ModuleMatchQuality);
Daniel Dunbarc984df82009-07-15 06:35:19 +000078}