Daniel Dunbar | 0eb6699 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 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 "llvm/Module.h" |
| 11 | #include "llvm/Target/TargetRegistry.h" |
| 12 | using namespace llvm; |
| 13 | |
| 14 | Target TheMipsTarget; |
| 15 | |
| 16 | static unsigned Mips_JITMatchQuality() { |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | static unsigned Mips_TripleMatchQuality(const std::string &TT) { |
| 21 | // We strongly match "mips*-*". |
| 22 | if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-") |
| 23 | return 20; |
| 24 | |
| 25 | if (TT.size() >= 13 && std::string(TT.begin(), |
| 26 | TT.begin()+13) == "mipsallegrex-") |
| 27 | return 20; |
| 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static unsigned Mips_ModuleMatchQuality(const Module &M) { |
| 33 | // Check for a triple match. |
| 34 | if (unsigned Q = Mips_TripleMatchQuality(M.getTargetTriple())) |
| 35 | return Q; |
| 36 | |
| 37 | // Otherwise if the target triple is non-empty, we don't match. |
| 38 | if (!M.getTargetTriple().empty()) return 0; |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | Target TheMipselTarget; |
| 44 | |
| 45 | static unsigned Mipsel_JITMatchQuality() { |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static unsigned Mipsel_TripleMatchQuality(const std::string &TT) { |
| 50 | // We strongly match "mips*el-*". |
| 51 | if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-") |
| 52 | return 20; |
| 53 | |
| 54 | if (TT.size() >= 15 && std::string(TT.begin(), |
| 55 | TT.begin()+15) == "mipsallegrexel-") |
| 56 | return 20; |
| 57 | |
| 58 | if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp") |
| 59 | return 20; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static unsigned Mipsel_ModuleMatchQuality(const Module &M) { |
| 65 | // Check for a triple match. |
| 66 | if (unsigned Q = Mipsel_TripleMatchQuality(M.getTargetTriple())) |
| 67 | return Q; |
| 68 | |
| 69 | // Otherwise if the target triple is non-empty, we don't match. |
| 70 | if (!M.getTargetTriple().empty()) return 0; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | extern "C" void LLVMInitializeMipsTargetInfo() { |
| 76 | TargetRegistry::RegisterTarget(TheMipsTarget, "mips", |
| 77 | "Mips", |
| 78 | &Mips_TripleMatchQuality, |
| 79 | &Mips_ModuleMatchQuality, |
| 80 | &Mips_JITMatchQuality); |
| 81 | |
| 82 | TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel", |
| 83 | "Mipsel", |
| 84 | &Mipsel_TripleMatchQuality, |
| 85 | &Mipsel_ModuleMatchQuality, |
| 86 | &Mipsel_JITMatchQuality); |
| 87 | } |