📝 change opcode dump format
This commit is contained in:
parent
8759d12eda
commit
00a655a9fc
|
@ -46,7 +46,7 @@ void operand_line_counter::dump_operand_count() const {
|
|||
if (!rate) {
|
||||
break;
|
||||
}
|
||||
std::clog << " " << opname[i.first] << " : ";
|
||||
std::clog << " " << oprand_name_table[i.first] << " : ";
|
||||
std::clog << i.second << " (" << rate << "%)\n";
|
||||
}
|
||||
std::clog << " total : " << total << '\n';
|
||||
|
@ -171,7 +171,7 @@ void dbg::step_info() {
|
|||
<< codestream(bytecode[i], i)
|
||||
<< reset << "\n";
|
||||
}
|
||||
stack_info(10);
|
||||
stack_info(16);
|
||||
}
|
||||
|
||||
void dbg::interact() {
|
||||
|
|
|
@ -24,7 +24,7 @@ void gc::mark() {
|
|||
mark_context_root(bfs);
|
||||
|
||||
// concurrent mark, experimental
|
||||
if (memory.size()>UINT16_MAX && bfs.size()>8192) {
|
||||
if (memory.size()>UINT16_MAX && bfs.size()>32) {
|
||||
flag_concurrent_mark_triggered = true;
|
||||
usize size = bfs.size();
|
||||
std::thread t0(&gc::concurrent_mark, this, std::ref(bfs), 0, size/4);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace nasal {
|
||||
|
||||
const char* opname[] = {
|
||||
const char* oprand_name_table[] = {
|
||||
"exit ", "repl ", "intl ", "loadg ",
|
||||
"loadl ", "loadu ", "pnum ", "pnil ",
|
||||
"pstr ", "newv ", "newh ", "newf ",
|
||||
|
@ -42,67 +42,107 @@ void codestream::dump(std::ostream& out) const {
|
|||
using std::setfill;
|
||||
using std::hex;
|
||||
using std::dec;
|
||||
auto op = code.op;
|
||||
auto num = code.num;
|
||||
|
||||
const auto op = code.op;
|
||||
const auto num = code.num;
|
||||
|
||||
// dump operand index and bytecode(hex format)
|
||||
out << hex << "0x"
|
||||
<< setw(6) << setfill('0') << index << " "
|
||||
<< setw(2) << setfill('0') << static_cast<u32>(op) << " "
|
||||
<< setw(2) << setfill('0') << ((num>>16)&0xff) << " "
|
||||
<< setw(2) << setfill('0') << ((num>>8)&0xff) << " "
|
||||
<< setw(2) << setfill('0') << (num&0xff) << " "
|
||||
<<opname[op]<<" "<<dec;
|
||||
<< setw(2) << setfill('0') << static_cast<u32>(op) << ":" << dec;
|
||||
|
||||
// dump immediate number(hex format)
|
||||
for(i32 i = 64-8; i>=0; i -= 8) {
|
||||
out << hex << setw(2) << setfill('0') << ((num>>i)&0xff) << dec << " ";
|
||||
}
|
||||
|
||||
// dump operand name
|
||||
out << " " << oprand_name_table[op] << " ";
|
||||
|
||||
switch(op) {
|
||||
case op_addeq: case op_subeq:
|
||||
case op_muleq: case op_diveq:
|
||||
case op_lnkeq: case op_meq:
|
||||
case op_btandeq: case op_btoreq:
|
||||
case op_addeq:
|
||||
case op_subeq:
|
||||
case op_muleq:
|
||||
case op_diveq:
|
||||
case op_lnkeq:
|
||||
case op_meq:
|
||||
case op_btandeq:
|
||||
case op_btoreq:
|
||||
case op_btxoreq:
|
||||
out << hex << "0x" << num << dec << " sp-" << num; break;
|
||||
case op_addeqc: case op_subeqc:
|
||||
case op_muleqc:case op_diveqc:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << const_number[num] << ")"; break;
|
||||
out << hex << "0x" << num << dec << " sp-" << num;
|
||||
break;
|
||||
case op_addeqc:
|
||||
case op_subeqc:
|
||||
case op_muleqc:
|
||||
case op_diveqc:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << const_number[num] << ")";
|
||||
break;
|
||||
case op_lnkeqc:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << rawstr(const_string[num], 16) << ")"; break;
|
||||
case op_addecp: case op_subecp:
|
||||
case op_mulecp: case op_divecp:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << const_number[num] << ") sp-1"; break;
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << rawstr(const_string[num], 16) << ")";
|
||||
break;
|
||||
case op_addecp:
|
||||
case op_subecp:
|
||||
case op_mulecp:
|
||||
case op_divecp:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << const_number[num] << ") sp-1";
|
||||
break;
|
||||
case op_lnkecp:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << rawstr(const_string[num], 16) << ") sp-1"; break;
|
||||
case op_addc: case op_subc:
|
||||
case op_mulc: case op_divc:
|
||||
case op_lessc: case op_leqc:
|
||||
case op_grtc: case op_geqc:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << rawstr(const_string[num], 16) << ") sp-1";
|
||||
break;
|
||||
case op_addc:
|
||||
case op_subc:
|
||||
case op_mulc:
|
||||
case op_divc:
|
||||
case op_lessc:
|
||||
case op_leqc:
|
||||
case op_grtc:
|
||||
case op_geqc:
|
||||
case op_pnum:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << const_number[num] << ")"; break;
|
||||
case op_callvi: case op_newv:
|
||||
case op_callfv: case op_repl:
|
||||
case op_intl: case op_findex:
|
||||
case op_feach: case op_newf:
|
||||
case op_jmp: case op_jt:
|
||||
case op_jf: case op_callg:
|
||||
case op_mcallg: case op_loadg:
|
||||
case op_calll: case op_mcalll:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << const_number[num] << ")";
|
||||
break;
|
||||
case op_callvi:
|
||||
case op_newv:
|
||||
case op_callfv:
|
||||
case op_repl:
|
||||
case op_intl:
|
||||
case op_findex:
|
||||
case op_feach:
|
||||
case op_newf:
|
||||
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_callb:
|
||||
out << hex << "0x" << num << " <" << natives[num].name
|
||||
<< "@0x" << reinterpret_cast<u64>(natives[num].func)
|
||||
<< dec << ">"; break;
|
||||
case op_upval: case op_mupval:
|
||||
case op_upval:
|
||||
case op_mupval:
|
||||
case op_loadu:
|
||||
out << hex << "0x" << ((num>>16)&0xffff)
|
||||
<< "[0x" << (num&0xffff) << "]" << dec; break;
|
||||
case op_happ: case op_pstr:
|
||||
case op_lnkc: case op_callh:
|
||||
case op_mcallh: case op_para:
|
||||
case op_deft: case op_dyn:
|
||||
out << hex << "0x" << num << dec
|
||||
<< " (" << rawstr(const_string[num], 16) << ")"; break;
|
||||
case op_happ:
|
||||
case op_pstr:
|
||||
case op_lnkc:
|
||||
case op_callh:
|
||||
case op_mcallh:
|
||||
case op_para:
|
||||
case op_deft:
|
||||
case op_dyn:
|
||||
out << hex << "0x" << num << dec;
|
||||
out << " (" << rawstr(const_string[num], 16) << ")";
|
||||
break;
|
||||
default:
|
||||
if (files) {
|
||||
out << hex << "0x" << num << dec;
|
||||
|
|
|
@ -127,6 +127,6 @@ public:
|
|||
|
||||
std::ostream& operator<<(std::ostream&, const codestream&);
|
||||
|
||||
extern const char* opname[];
|
||||
extern const char* oprand_name_table[];
|
||||
|
||||
}
|
|
@ -384,7 +384,7 @@ nas_map& var::map() {
|
|||
}
|
||||
|
||||
var nas_err(const std::string& error_function_name, const std::string& info) {
|
||||
std::cerr << "[vm] " << error_function_name << ": " << info << "\n";
|
||||
std::cerr << "\n[vm] " << error_function_name << ": " << info << "\n";
|
||||
return var::none();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,8 +78,8 @@ void vm::value_info(var& val) {
|
|||
<< "> " << rawstr(val.str(), 16)
|
||||
<< std::dec; break;
|
||||
case vm_type::vm_func: std::clog << "| func | <0x" << std::hex << p
|
||||
<< "> entry:0x" << val.func().entry
|
||||
<< std::dec; break;
|
||||
<< std::dec << "> " << val.func();
|
||||
break;
|
||||
case vm_type::vm_upval:std::clog << "| upval| <0x" << std::hex << p
|
||||
<< std::dec << "> [" << val.upval().size
|
||||
<< " val]"; break;
|
||||
|
@ -124,7 +124,7 @@ void vm::function_detail_info(const nas_func& func) {
|
|||
}
|
||||
if (func.dynamic_parameter_index>=0) {
|
||||
std::clog << (argument_list.size()? ", ":"");
|
||||
std::clog << const_string[func.dynamic_parameter_index] << "...";
|
||||
std::clog << func.dynamic_parameter_name << "...";
|
||||
}
|
||||
std::clog << ") ";
|
||||
const auto& code = bytecode[func.entry];
|
||||
|
@ -201,12 +201,15 @@ void vm::trace_back() {
|
|||
// the first called place has no same calls
|
||||
}
|
||||
|
||||
void vm::stack_info(const u32 limit = 10) {
|
||||
void vm::stack_info(const u64 limit = 16) {
|
||||
var* top = ctx.top;
|
||||
var* bottom = ctx.stack;
|
||||
std::clog << "\nstack (0x" << std::hex << reinterpret_cast<u64>(bottom);
|
||||
std::clog << std::dec << ", limit " << limit << ", total ";
|
||||
const auto stack_address = reinterpret_cast<u64>(bottom);
|
||||
|
||||
std::clog << "\nvm stack (0x" << std::hex << stack_address << std::dec;
|
||||
std::clog << ", limit " << limit << ", total ";
|
||||
std::clog << (top<bottom? 0:static_cast<i64>(top-bottom+1)) << ")\n";
|
||||
|
||||
for(u32 i = 0; i<limit && top>=bottom; ++i, --top) {
|
||||
std::clog << " 0x" << std::hex
|
||||
<< std::setw(6) << std::setfill('0')
|
||||
|
@ -388,7 +391,7 @@ std::string vm::type_name_string(const var& value) const {
|
|||
}
|
||||
|
||||
void vm::die(const std::string& str) {
|
||||
std::cerr << "[vm] error: " << str << "\n";
|
||||
std::cerr << "\n[vm] error: " << str << "\n";
|
||||
function_call_trace();
|
||||
trace_back();
|
||||
stack_info();
|
||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
|||
void function_detail_info(const nas_func&);
|
||||
void function_call_trace();
|
||||
void trace_back();
|
||||
void stack_info(const u32);
|
||||
void stack_info(const u64);
|
||||
void register_info();
|
||||
void global_state();
|
||||
void local_state();
|
||||
|
|
|
@ -494,14 +494,22 @@ std::string md5(const std::string& src) {
|
|||
|
||||
// u32(abs(sin(i+1))*(2pow32))
|
||||
const u32 k[] = {
|
||||
0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,0xf57c0faf,0x4787c62a,0xa8304613,0xfd469501,
|
||||
0x698098d8,0x8b44f7af,0xffff5bb1,0x895cd7be,0x6b901122,0xfd987193,0xa679438e,0x49b40821,
|
||||
0xf61e2562,0xc040b340,0x265e5a51,0xe9b6c7aa,0xd62f105d,0x02441453,0xd8a1e681,0xe7d3fbc8,
|
||||
0x21e1cde6,0xc33707d6,0xf4d50d87,0x455a14ed,0xa9e3e905,0xfcefa3f8,0x676f02d9,0x8d2a4c8a,
|
||||
0xfffa3942,0x8771f681,0x6d9d6122,0xfde5380c,0xa4beea44,0x4bdecfa9,0xf6bb4b60,0xbebfbc70,
|
||||
0x289b7ec6,0xeaa127fa,0xd4ef3085,0x04881d05,0xd9d4d039,0xe6db99e5,0x1fa27cf8,0xc4ac5665,
|
||||
0xf4292244,0x432aff97,0xab9423a7,0xfc93a039,0x655b59c3,0x8f0ccc92,0xffeff47d,0x85845dd1,
|
||||
0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391
|
||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
||||
};
|
||||
|
||||
// left shift bits
|
||||
|
|
Loading…
Reference in New Issue