🎨 opcode dump can get global variable name
This commit is contained in:
parent
10d2965197
commit
b5f02de883
|
@ -1436,6 +1436,7 @@ void codegen::print(std::ostream& out) {
|
|||
codestream::set(
|
||||
const_number_table.data(),
|
||||
const_string_table.data(),
|
||||
global,
|
||||
native_function.data()
|
||||
);
|
||||
|
||||
|
|
|
@ -161,11 +161,11 @@ private:
|
|||
void ret_gen(return_expr*);
|
||||
|
||||
public:
|
||||
const auto& strs() const {return const_string_table;}
|
||||
const auto& nums() const {return const_number_table;}
|
||||
const auto& natives() const {return native_function;}
|
||||
const auto& codes() const {return code;}
|
||||
const auto& globals() const {return global;}
|
||||
const auto& strs() const { return const_string_table; }
|
||||
const auto& nums() const { return const_number_table; }
|
||||
const auto& natives() const { return native_function; }
|
||||
const auto& codes() const { return code; }
|
||||
const auto& globals() const { return global; }
|
||||
|
||||
public:
|
||||
codegen() = default;
|
||||
|
|
|
@ -163,7 +163,13 @@ void dbg::step_info() {
|
|||
|
||||
begin = (ctx.pc>>3)==0? 0:((ctx.pc>>3)<<3);
|
||||
end = (1+(ctx.pc>>3))<<3;
|
||||
codestream::set(const_number, const_string, native_function.data(), files);
|
||||
codestream::set(
|
||||
const_number,
|
||||
const_string,
|
||||
global_symbol_name,
|
||||
native_function.data(),
|
||||
files
|
||||
);
|
||||
|
||||
std::clog << "\nnext bytecode:\n";
|
||||
for(u64 i = begin; i<end && bytecode[i].op!=op_exit; ++i) {
|
||||
|
|
|
@ -5,12 +5,31 @@ namespace nasal {
|
|||
|
||||
void codestream::set(const f64* number_list,
|
||||
const std::string* string_list,
|
||||
const std::unordered_map<std::string, u64>& globals,
|
||||
const nasal_builtin_table* native_table,
|
||||
const std::string* file_list) {
|
||||
const_number = number_list;
|
||||
const_string = string_list;
|
||||
natives = native_table;
|
||||
files = file_list;
|
||||
|
||||
global_variable.resize(globals.size());
|
||||
for(auto& [name, index]: globals) {
|
||||
global_variable[index] = name;
|
||||
}
|
||||
}
|
||||
|
||||
void codestream::set(const f64* number_list,
|
||||
const std::string* string_list,
|
||||
const std::vector<std::string>& globals,
|
||||
const nasal_builtin_table* native_table,
|
||||
const std::string* file_list) {
|
||||
const_number = number_list;
|
||||
const_string = string_list;
|
||||
natives = native_table;
|
||||
files = file_list;
|
||||
|
||||
global_variable = globals;
|
||||
}
|
||||
|
||||
void codestream::dump(std::ostream& out) const {
|
||||
|
@ -93,13 +112,16 @@ void codestream::dump(std::ostream& out) const {
|
|||
case op_jmp:
|
||||
case op_jt:
|
||||
case op_jf:
|
||||
case op_callg:
|
||||
case op_mcallg:
|
||||
case op_loadg:
|
||||
case op_calll:
|
||||
case op_mcalll:
|
||||
case op_loadl:
|
||||
out << hex << "0x" << num << dec; break;
|
||||
case op_callg:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << util::rawstr(global_variable[num], 32) << ")";
|
||||
break;
|
||||
case op_callb:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " <" << natives[num].name << "@0x";
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
#include "natives/builtin.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace nasal {
|
||||
|
||||
|
@ -207,11 +211,18 @@ private:
|
|||
inline static const std::string* const_string = nullptr;
|
||||
inline static const nasal_builtin_table* natives = nullptr;
|
||||
inline static const std::string* files = nullptr;
|
||||
inline static std::vector<std::string> global_variable;
|
||||
|
||||
public:
|
||||
codestream(const opcode& c, const u64 i): code(c), index(i) {}
|
||||
static void set(const f64*,
|
||||
const std::string*,
|
||||
const std::unordered_map<std::string, u64>&,
|
||||
const nasal_builtin_table*,
|
||||
const std::string* file_list = nullptr);
|
||||
static void set(const f64*,
|
||||
const std::string*,
|
||||
const std::vector<std::string>&,
|
||||
const nasal_builtin_table*,
|
||||
const std::string* file_list = nullptr);
|
||||
void dump(std::ostream&) const;
|
||||
|
|
|
@ -327,7 +327,13 @@ void vm::trace_back() {
|
|||
|
||||
std::clog << "\nback trace ";
|
||||
std::clog << (ngc.cort? "(coroutine)":"(main)") << "\n";
|
||||
codestream::set(const_number, const_string, native_function.data(), files);
|
||||
codestream::set(
|
||||
const_number,
|
||||
const_string,
|
||||
global_symbol_name,
|
||||
native_function.data(),
|
||||
files
|
||||
);
|
||||
|
||||
for(u64 p = 0, same = 0, prev = 0xffffffff; !ret.empty(); prev = p, ret.pop()) {
|
||||
if ((p = ret.top())==prev) {
|
||||
|
|
Loading…
Reference in New Issue