Added Args::StringForEncoding(), Args::StringToGenericRegister() and centralized the parsing of the string to encoding and string to generic register.

Added code the initialize the register context in the OperatingSystemPython plug-in with the new PythonData classes, and added a test OperatingSystemPython module in lldb/examples/python/operating_system.py that we can use for testing.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@162530 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Interpreter/Args.cpp b/source/Interpreter/Args.cpp
index 5b3b679..63bcb87 100644
--- a/source/Interpreter/Args.cpp
+++ b/source/Interpreter/Args.cpp
@@ -1007,6 +1007,60 @@
     return error;
 }
 
+lldb::Encoding
+Args::StringToEncoding (const char *s, lldb::Encoding fail_value)
+{
+    if (s && s[0])
+    {
+        if (strcmp(s, "uint") == 0)
+            return eEncodingUint;
+        else if (strcmp(s, "sint") == 0)
+            return eEncodingSint;
+        else if (strcmp(s, "ieee754") == 0)
+            return eEncodingIEEE754;
+        else if (strcmp(s, "vector") == 0)
+            return eEncodingVector;
+    }
+    return fail_value;
+}
+
+uint32_t
+Args::StringToGenericRegister (const char *s)
+{
+    if (s && s[0])
+    {
+        if (strcmp(s, "pc") == 0)
+            return LLDB_REGNUM_GENERIC_PC;
+        else if (strcmp(s, "sp") == 0)
+            return LLDB_REGNUM_GENERIC_SP;
+        else if (strcmp(s, "fp") == 0)
+            return LLDB_REGNUM_GENERIC_FP;
+        else if (strcmp(s, "ra") == 0)
+            return LLDB_REGNUM_GENERIC_RA;
+        else if (strcmp(s, "flags") == 0)
+            return LLDB_REGNUM_GENERIC_FLAGS;
+        else if (strncmp(s, "arg", 3) == 0)
+        {
+            if (s[3] && s[4] == '\0')
+            {
+                switch (s[3])
+                {
+                    case '1': return LLDB_REGNUM_GENERIC_ARG1;
+                    case '2': return LLDB_REGNUM_GENERIC_ARG2;
+                    case '3': return LLDB_REGNUM_GENERIC_ARG3;
+                    case '4': return LLDB_REGNUM_GENERIC_ARG4;
+                    case '5': return LLDB_REGNUM_GENERIC_ARG5;
+                    case '6': return LLDB_REGNUM_GENERIC_ARG6;
+                    case '7': return LLDB_REGNUM_GENERIC_ARG7;
+                    case '8': return LLDB_REGNUM_GENERIC_ARG8;
+                }
+            }
+        }
+    }
+    return LLDB_INVALID_REGNUM;
+}
+
+
 void
 Args::LongestCommonPrefix (std::string &common_prefix)
 {
diff --git a/source/Interpreter/PythonDataObjects.cpp b/source/Interpreter/PythonDataObjects.cpp
index ba3879e..c41772c 100644
--- a/source/Interpreter/PythonDataObjects.cpp
+++ b/source/Interpreter/PythonDataObjects.cpp
@@ -212,7 +212,7 @@
 }
 
 PythonDataObject
-PythonDataDictionary::GetItemForKey (const char *key)
+PythonDataDictionary::GetItemForKey (const char *key) const
 {
     if (key && key[0])
     {
@@ -224,15 +224,40 @@
 
 
 PythonDataObject
-PythonDataDictionary::GetItemForKey (const PythonDataString &key)
+PythonDataDictionary::GetItemForKey (const PythonDataString &key) const
 {
     if (m_object && key)
         return PythonDataObject(PyDict_GetItem(GetPythonObject(), key.GetPythonObject()));
     return PythonDataObject();
 }
 
+
+const char *
+PythonDataDictionary::GetItemForKeyAsString (const PythonDataString &key, const char *fail_value) const
+{
+    if (m_object && key)
+    {
+        PyObject *object = PyDict_GetItem(GetPythonObject(), key.GetPythonObject());
+        if (object && PyString_Check(object))
+            return PyString_AsString(object);
+    }
+    return fail_value;
+}
+
+int64_t
+PythonDataDictionary::GetItemForKeyAsInteger (const PythonDataString &key, int64_t fail_value) const
+{
+    if (m_object && key)
+    {
+        PyObject *object = PyDict_GetItem(GetPythonObject(), key.GetPythonObject());
+        if (object && PyInt_Check(object))
+            return PyInt_AsLong(object);
+    }
+    return fail_value;
+}
+
 PythonDataArray
-PythonDataDictionary::GetKeys ()
+PythonDataDictionary::GetKeys () const
 {
     if (m_object)
         return PythonDataArray(PyDict_Keys(GetPythonObject()));
@@ -240,7 +265,7 @@
 }
 
 PythonDataString
-PythonDataDictionary::GetKeyAtPosition (uint32_t pos)
+PythonDataDictionary::GetKeyAtPosition (uint32_t pos) const
 {
     PyObject *key, *value;
     Py_ssize_t pos_iter = 0;
@@ -257,7 +282,7 @@
 }
 
 PythonDataObject
-PythonDataDictionary::GetValueAtPosition (uint32_t pos)
+PythonDataDictionary::GetValueAtPosition (uint32_t pos) const
 {
     PyObject *key, *value;
     Py_ssize_t pos_iter = 0;