History

Various work for tool support in the VM. Update some type names (i.e. _t) and alter API signatures to be more consistent.

arr committed 10 years ago

Commit e5d3f861 parent bcb413516 files · +514 −45Browse files

Showing the changes to src/vm/execution_table.cpp (1 of 16 files). Show all

Unified · Split

src/vm/execution_table.cpp+26−5
@@ -18,6 +18,7 @@ · 17 unmodified lines
18#include <exceptions.h>18#include <exceptions.h>
19#include <debug.h>19#include <debug.h>
20#include <builtin_module.h>20#include <builtin_module.h>
21#include "tool_dispatch.h"
21#include "execution_table.h"22#include "execution_table.h"
22 23
23using namespace disvm;24using namespace disvm;
@@ -186,7 +187,7 @@ namespace · 162 unmodified lines
186 auto buffer = std::array<char, sizeof("�2147483648")>{};187 auto buffer = std::array<char, sizeof("�2147483648")>{};
187 188
188 const auto w = vt_ref<word_t>(r.src);189 const auto w = vt_ref<word_t>(r.src);
189 const auto len = ::sprintf(buffer.data(), "%d", w);190 const auto len = std::sprintf(buffer.data(), "%d", w);
190 assert(static_cast<std::size_t>(len) <= buffer.size());191 assert(static_cast<std::size_t>(len) <= buffer.size());
191 192
192 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));193 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -212,7 +213,7 @@ namespace · 19 unmodified lines
212 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};213 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};
213 214
214 const auto real = vt_ref<real_t>(r.src);215 const auto real = vt_ref<real_t>(r.src);
215 const auto len = ::sprintf(buffer.data(), "%g", real);216 const auto len = std::sprintf(buffer.data(), "%g", real);
216 assert(static_cast<std::size_t>(len) <= buffer.size());217 assert(static_cast<std::size_t>(len) <= buffer.size());
217 218
218 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));219 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -238,7 +239,7 @@ namespace · 19 unmodified lines
238 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};239 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};
239 240
240 const auto b = vt_ref<big_t>(r.src);241 const auto b = vt_ref<big_t>(r.src);
241 const auto len = ::sprintf(buffer.data(), "%lld", b);242 const auto len = std::sprintf(buffer.data(), "%lld", b);
242 assert(static_cast<std::size_t>(len) <= buffer.size());243 assert(static_cast<std::size_t>(len) <= buffer.size());
243 244
244 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));245 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -643,6 +644,7 @@ namespace · 398 unmodified lines
643 break;644 break;
644 }645 }
645 646
647 assert(0 <= static_cast<std::size_t>(target_pc) && static_cast<std::size_t>(target_pc) < r.module_ref->code_section.size());
646 r.pc = target_pc;648 r.pc = target_pc;
647 }649 }
648 650
@@ -1036,7 +1038,7 @@ namespace · 387 unmodified lines
1036 vm_registers_t &r,1038 vm_registers_t &r,
1037 const vm_t &vm,1039 const vm_t &vm,
1038 std::shared_ptr<const type_descriptor_t> type_desc,1040 std::shared_ptr<const type_descriptor_t> type_desc,
1039 std::function<void(pointer_t, pointer_t, const type_descriptor_t *)> transfer)1041 vm_channel_t::data_transfer_func_t transfer)
1040 {1042 {
1041 auto buffer_len = word_t{ 0 };1043 auto buffer_len = word_t{ 0 };
1042 if (r.mid != r.dest)1044 if (r.mid != r.dest)
@@ -1066,7 +1068,7 @@ namespace · 23 unmodified lines
1066 {1068 {
1067 auto memory_size = vt_ref<word_t>(r.src); 1069 auto memory_size = vt_ref<word_t>(r.src);
1068 auto channel_data_type = type_descriptor_t::create(memory_size); 1070 auto channel_data_type = type_descriptor_t::create(memory_size);
1069 1071
1070 _newc_(r, vm, channel_data_type, _channel_movm);1072 _newc_(r, vm, channel_data_type, _channel_movm);
1071 }1073 }
1072 1074
@@ -1669,6 +1671,24 @@ namespace · 596 unmodified lines
1669 r.pc = handler_pc;1671 r.pc = handler_pc;
1670 }1672 }
1671 1673
1674 // [SPEC] Added to support debugger.
1675 // The actual opcode for execution can be retrieved from the tool dispatch interface.
1676 // The current register state is for the real opcode, the breakpoint opcode has no inputs/outputs.
1677 EXEC_DECL(brkpt)
1678 {
1679 auto tool_dispatch = r.tool_dispatch.load();
1680 if (tool_dispatch == nullptr)
1681 {
1682 assert(false && "Breakpoint set but no tool dispatcher found" );
1683 throw vm_system_exception{ "Breakpoint set but no tool dispatcher found" };
1684 }
1685
1686 const auto original_op = tool_dispatch->on_breakpoint(r, vm);
1687
1688 // Continue execution
1689 vm_exec_table[static_cast<std::size_t>(original_op)](r, vm);
1690 }
1691
1672 //1692 //
1673 // Module operations1693 // Module operations
1674 //1694 //
@@ -1895,4 +1915,5 @@ const vm_exec_t disvm::runtime::vm_exec_table[static_cast<std::size_t>(opcode_t: · 220 unmodified lines
1895 expl,1915 expl,
1896 expf,1916 expf,
1897 notimpl, // self,1917 notimpl, // self,
1918 brkpt,
1898};1919};