blob: fc55ccac6fc78eca4a8a08f363ffb7f31bc3c9f4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
13using namespace lldb;
14using namespace lldb_private;
15
Greg Clayton75906e42011-05-11 18:39:18 +000016ABISP
Greg Clayton395fc332011-02-15 21:59:32 +000017ABI::FindPlugin (const ArchSpec &arch)
Chris Lattner24943d22010-06-08 16:52:24 +000018{
Greg Clayton75906e42011-05-11 18:39:18 +000019 ABISP abi_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000020 ABICreateInstance create_callback;
21
22 for (uint32_t idx = 0;
23 (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL;
24 ++idx)
25 {
Greg Clayton75906e42011-05-11 18:39:18 +000026 abi_sp = create_callback(arch);
Chris Lattner24943d22010-06-08 16:52:24 +000027
Greg Clayton75906e42011-05-11 18:39:18 +000028 if (abi_sp)
29 return abi_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000030 }
Greg Clayton75906e42011-05-11 18:39:18 +000031 abi_sp.reset();
32 return abi_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000033}
34
35//----------------------------------------------------------------------
36// Constructor
37//----------------------------------------------------------------------
38ABI::ABI()
39{
40}
41
42//----------------------------------------------------------------------
43// Destructor
44//----------------------------------------------------------------------
45ABI::~ABI()
46{
47}
Greg Clayton37f962e2011-08-22 02:49:39 +000048
49
50bool
51ABI::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
79bool
80ABI::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}