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
1818 #include <exceptions.h>
1919 #include <debug.h>
2020 #include <builtin_module.h>
21+#include "tool_dispatch.h"
2122 #include "execution_table.h"
2223
2324 using namespace disvm;
@@ -186,7 +187,7 @@ namespace · 162 unmodified lines
186187 auto buffer = std::array<char, sizeof("�2147483648")>{};
187188
188189 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);
190191 assert(static_cast<std::size_t>(len) <= buffer.size());
191192
192193 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -212,7 +213,7 @@ namespace · 19 unmodified lines
212213 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};
213214
214215 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);
216217 assert(static_cast<std::size_t>(len) <= buffer.size());
217218
218219 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -238,7 +239,7 @@ namespace · 19 unmodified lines
238239 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};
239240
240241 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);
242243 assert(static_cast<std::size_t>(len) <= buffer.size());
243244
244245 auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
@@ -643,6 +644,7 @@ namespace · 398 unmodified lines
643644 break;
644645 }
645646
647+ assert(0 <= static_cast<std::size_t>(target_pc) && static_cast<std::size_t>(target_pc) < r.module_ref->code_section.size());
646648 r.pc = target_pc;
647649 }
648650
@@ -1036,7 +1038,7 @@ namespace · 387 unmodified lines
10361038 vm_registers_t &r,
10371039 const vm_t &vm,
10381040 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)
10401042 {
10411043 auto buffer_len = word_t{ 0 };
10421044 if (r.mid != r.dest)
@@ -1066,7 +1068,7 @@ namespace · 23 unmodified lines
10661068 {
10671069 auto memory_size = vt_ref<word_t>(r.src);
10681070 auto channel_data_type = type_descriptor_t::create(memory_size);
1069−
1071+
10701072 _newc_(r, vm, channel_data_type, _channel_movm);
10711073 }
10721074
@@ -1669,6 +1671,24 @@ namespace · 596 unmodified lines
16691671 r.pc = handler_pc;
16701672 }
16711673
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+
16721692 //
16731693 // Module operations
16741694 //
@@ -1895,4 +1915,5 @@ const vm_exec_t disvm::runtime::vm_exec_table[static_cast<std::size_t>(opcode_t: · 220 unmodified lines
18951915 expl,
18961916 expf,
18971917 notimpl, // self,
1918+ brkpt,
18981919 };