summaryrefslogtreecommitdiff
path: root/source/Expression/IRInterpreter.cpp
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2013-11-06 16:48:53 +0000
committerEd Maste <emaste@FreeBSD.org>2013-11-06 16:48:53 +0000
commitf21a844f60ae6c74fcf1fddca32461acce3c1ee0 (patch)
tree56d79f94966870db1cecd65a7264510a25fd1cba /source/Expression/IRInterpreter.cpp
parent37d22554be9f5a677dad2a95b7ef22fe59c66a8a (diff)
Notes
Diffstat (limited to 'source/Expression/IRInterpreter.cpp')
-rw-r--r--source/Expression/IRInterpreter.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/source/Expression/IRInterpreter.cpp b/source/Expression/IRInterpreter.cpp
index dcbf584cfb63f..71ef8d6457bc6 100644
--- a/source/Expression/IRInterpreter.cpp
+++ b/source/Expression/IRInterpreter.cpp
@@ -14,6 +14,7 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Expression/IRMemoryMap.h"
#include "lldb/Expression/IRInterpreter.h"
+#include "lldb/Host/Endian.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
@@ -321,13 +322,19 @@ public:
if (!ResolveConstantValue(resolved_value, constant))
return false;
- const uint64_t *raw_data = resolved_value.getRawData();
-
+ lldb_private::StreamString buffer (lldb_private::Stream::eBinary,
+ m_memory_map.GetAddressByteSize(),
+ m_memory_map.GetByteOrder());
+
size_t constant_size = m_target_data.getTypeStoreSize(constant->getType());
+ const uint64_t *raw_data = resolved_value.getRawData();
+
+ buffer.PutRawBytes(raw_data, constant_size, lldb::endian::InlHostByteOrder());
+
lldb_private::Error write_error;
- m_memory_map.WriteMemory(process_address, (uint8_t*)raw_data, constant_size, write_error);
+ m_memory_map.WriteMemory(process_address, (const uint8_t*)buffer.GetData(), constant_size, write_error);
return write_error.Success();
}
@@ -517,6 +524,7 @@ IRInterpreter::CanInterpret (llvm::Module &module,
case Instruction::SRem:
case Instruction::Store:
case Instruction::Sub:
+ case Instruction::Trunc:
case Instruction::UDiv:
case Instruction::URem:
case Instruction::Xor:
@@ -1162,6 +1170,42 @@ IRInterpreter::Interpret (llvm::Module &module,
}
}
break;
+ case Instruction::Trunc:
+ {
+ const TruncInst *trunc_inst = dyn_cast<TruncInst>(inst);
+
+ if (!trunc_inst)
+ {
+ if (log)
+ log->Printf("getOpcode() returns Trunc, but instruction is not a TruncInst");
+ error.SetErrorToGenericError();
+ error.SetErrorString(interpreter_internal_error);
+ return false;
+ }
+
+ Value *src_operand = trunc_inst->getOperand(0);
+
+ lldb_private::Scalar I;
+
+ if (!frame.EvaluateValue(I, src_operand, module))
+ {
+ if (log)
+ log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
+ error.SetErrorToGenericError();
+ error.SetErrorString(bad_value_error);
+ return false;
+ }
+
+ frame.AssignValue(inst, I, module);
+
+ if (log)
+ {
+ log->Printf("Interpreted a Trunc");
+ 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);