Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ABI.cpp -------------------------------------------------*- C++ -*-===// |
| 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 "lldb/Target/ABI.h" |
| 11 | #include "lldb/Core/PluginManager.h" |
| 12 | |
| 13 | using namespace lldb; |
| 14 | using namespace lldb_private; |
| 15 | |
Greg Clayton | 75906e4 | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 16 | ABISP |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 17 | ABI::FindPlugin (const ArchSpec &arch) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | { |
Greg Clayton | 75906e4 | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 19 | ABISP abi_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | ABICreateInstance create_callback; |
| 21 | |
| 22 | for (uint32_t idx = 0; |
| 23 | (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL; |
| 24 | ++idx) |
| 25 | { |
Greg Clayton | 75906e4 | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 26 | abi_sp = create_callback(arch); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Greg Clayton | 75906e4 | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 28 | if (abi_sp) |
| 29 | return abi_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | } |
Greg Clayton | 75906e4 | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 31 | abi_sp.reset(); |
| 32 | return abi_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | //---------------------------------------------------------------------- |
| 36 | // Constructor |
| 37 | //---------------------------------------------------------------------- |
| 38 | ABI::ABI() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | //---------------------------------------------------------------------- |
| 43 | // Destructor |
| 44 | //---------------------------------------------------------------------- |
| 45 | ABI::~ABI() |
| 46 | { |
| 47 | } |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame^] | 48 | |
| 49 | |
| 50 | bool |
| 51 | ABI::GetRegisterInfoByName (const ConstString &name, RegisterInfo &info) |
| 52 | { |
| 53 | uint32_t count = 0; |
| 54 | const RegisterInfo *register_info_array = GetRegisterInfoArray (count); |
| 55 | if (register_info_array) |
| 56 | { |
| 57 | const char *unique_name_cstr = name.GetCString(); |
| 58 | uint32_t i; |
| 59 | for (i=0; i<count; ++i) |
| 60 | { |
| 61 | if (register_info_array[i].name == unique_name_cstr) |
| 62 | { |
| 63 | info = register_info_array[i]; |
| 64 | return true; |
| 65 | } |
| 66 | } |
| 67 | for (i=0; i<count; ++i) |
| 68 | { |
| 69 | if (register_info_array[i].alt_name == unique_name_cstr) |
| 70 | { |
| 71 | info = register_info_array[i]; |
| 72 | return true; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | bool |
| 80 | ABI::GetRegisterInfoByKind (RegisterKind reg_kind, uint32_t reg_num, RegisterInfo &info) |
| 81 | { |
| 82 | if (reg_kind < eRegisterKindGCC || reg_kind >= kNumRegisterKinds) |
| 83 | return false; |
| 84 | |
| 85 | uint32_t count = 0; |
| 86 | const RegisterInfo *register_info_array = GetRegisterInfoArray (count); |
| 87 | if (register_info_array) |
| 88 | { |
| 89 | for (uint32_t i=0; i<count; ++i) |
| 90 | { |
| 91 | if (register_info_array[i].kinds[reg_kind] == reg_num) |
| 92 | { |
| 93 | info = register_info_array[i]; |
| 94 | return true; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | return false; |
| 99 | } |