Added support for PtrToInt to the IR
authorSean Callanan <scallanan@apple.com>
Sat, 1 Dec 2012 00:09:34 +0000 (00:09 +0000)
committerSean Callanan <scallanan@apple.com>
Sat, 1 Dec 2012 00:09:34 +0000 (00:09 +0000)
interpreter.

<rdar://problem/12657742>

llvm-svn: 169063

lldb/source/Expression/IRInterpreter.cpp

index b30b066..64d5dc6 100644 (file)
@@ -558,6 +558,7 @@ public:
                 default:
                     return false;
                 case Instruction::IntToPtr:
+                case Instruction::PtrToInt:
                 case Instruction::BitCast:
                     return ResolveConstantValue(value, constant_expr->getOperand(0));
                 case Instruction::GetElementPtr:
@@ -991,6 +992,7 @@ IRInterpreter::supportsFunction (Function &llvm_function,
                 }
                 break;
             case Instruction::IntToPtr:
+            case Instruction::PtrToInt:
             case Instruction::Load:
             case Instruction::Mul:
             case Instruction::Ret:
@@ -1506,6 +1508,42 @@ IRInterpreter::runOnFunction (lldb::ClangExpressionVariableSP &result,
                 }
             }
             break;
+        case Instruction::PtrToInt:
+            {
+                const PtrToIntInst *ptr_to_int_inst = dyn_cast<PtrToIntInst>(inst);
+                
+                if (!ptr_to_int_inst)
+                {
+                    if (log)
+                        log->Printf("getOpcode() returns PtrToInt, but instruction is not an PtrToIntInst");
+                    err.SetErrorToGenericError();
+                    err.SetErrorString(interpreter_internal_error);
+                    return false;
+                }
+                
+                Value *src_operand = ptr_to_int_inst->getOperand(0);
+                
+                lldb_private::Scalar I;
+                
+                if (!frame.EvaluateValue(I, src_operand, llvm_module))
+                {
+                    if (log)
+                        log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
+                    err.SetErrorToGenericError();
+                    err.SetErrorString(bad_value_error);
+                    return false;
+                }
+                
+                frame.AssignValue(inst, I, llvm_module);
+                
+                if (log)
+                {
+                    log->Printf("Interpreted a PtrToInt");
+                    log->Printf("  Src : %s", frame.SummarizeValue(src_operand).c_str());
+                    log->Printf("  =   : %s", frame.SummarizeValue(inst).c_str());
+                }
+            }
+            break;
         case Instruction::Load:
             {
                 const LoadInst *load_inst = dyn_cast<LoadInst>(inst);