Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "target_registry.h" |
| 18 | |
| 19 | #include "logging.h" |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | // The following arrays contain the real registry data store by Register*() |
| 24 | // methods in TargetRegistry. Should keep sync with enum InstructionSet. |
| 25 | art::greenland::TargetRegistry::TargetCodeGenMachineCtorTy |
| 26 | RegisteredTargetCodeGenMachineCtor[] = { |
| 27 | NULL, /* kNone */ |
| 28 | NULL, /* kArm */ |
| 29 | NULL, /* kThumb2 */ |
| 30 | NULL, /* kX86 */ |
| 31 | NULL, /* kMips */ |
| 32 | }; |
| 33 | |
| 34 | art::greenland::TargetRegistry::CreateInvokeStubFn |
| 35 | RegisteredInvokeStubCompiler[] = { |
| 36 | NULL, /* kNone */ |
| 37 | NULL, /* kArm */ |
| 38 | NULL, /* kThumb2 */ |
| 39 | NULL, /* kX86 */ |
| 40 | NULL, /* kMips */ |
| 41 | }; |
| 42 | |
| 43 | } // anonymous namespace |
| 44 | |
| 45 | namespace art { |
| 46 | namespace greenland { |
| 47 | |
| 48 | void TargetRegistry::RegisterTargetCodeGenMachine(InstructionSet insn_set, |
| 49 | TargetCodeGenMachineCtorTy ctor) { |
| 50 | CHECK(static_cast<unsigned>(insn_set) < |
| 51 | (sizeof(RegisteredTargetCodeGenMachineCtor) / sizeof(RegisteredTargetCodeGenMachineCtor[0]))); |
| 52 | RegisteredTargetCodeGenMachineCtor[static_cast<unsigned>(insn_set)] = ctor; |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | TargetRegistry::TargetCodeGenMachineCtorTy |
| 57 | TargetRegistry::GetTargetCodeGenMachineCtor(InstructionSet insn_set) { |
| 58 | CHECK(static_cast<unsigned>(insn_set) < |
| 59 | (sizeof(RegisteredTargetCodeGenMachineCtor) / sizeof(RegisteredTargetCodeGenMachineCtor[0]))); |
| 60 | return RegisteredTargetCodeGenMachineCtor[static_cast<unsigned>(insn_set)]; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | TargetRegistry::RegisterInvokeStubCompiler(InstructionSet insn_set, |
| 65 | CreateInvokeStubFn compiler_fn) { |
| 66 | CHECK(static_cast<unsigned>(insn_set) < |
| 67 | (sizeof(RegisteredInvokeStubCompiler) / sizeof(RegisteredInvokeStubCompiler[0]))); |
| 68 | RegisteredInvokeStubCompiler[static_cast<unsigned>(insn_set)] = compiler_fn; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | TargetRegistry::CreateInvokeStubFn |
| 73 | TargetRegistry::GetInvokeStubCompiler(InstructionSet insn_set) { |
| 74 | CHECK(static_cast<unsigned>(insn_set) < |
| 75 | (sizeof(RegisteredInvokeStubCompiler) / sizeof(RegisteredInvokeStubCompiler[0]))); |
| 76 | return RegisteredInvokeStubCompiler[static_cast<unsigned>(insn_set)]; |
| 77 | } |
| 78 | |
| 79 | } // namespace greenland |
| 80 | } // namespace art |