mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add ~strdump and STRDUMP TVM OP (#452)
* Add ~strdump and STRDUMP TVM OP Add ~strdump and STRDUMP TVM OP Add ~strdump and STRDUMP TVM OP * STRDUMP fixes Co-authored-by: Andrey Tvorozhkov <andrey@h-labs.ru>
This commit is contained in:
parent
e2cca03a78
commit
e40d323fce
2 changed files with 42 additions and 1 deletions
|
@ -1063,6 +1063,8 @@ void define_builtins() {
|
||||||
AsmOp::Nop());
|
AsmOp::Nop());
|
||||||
define_builtin_func("~dump", TypeExpr::new_forall({X}, TypeExpr::new_map(X, TypeExpr::new_tensor({X, Unit}))),
|
define_builtin_func("~dump", TypeExpr::new_forall({X}, TypeExpr::new_map(X, TypeExpr::new_tensor({X, Unit}))),
|
||||||
AsmOp::Custom("s0 DUMP", 1, 1), true);
|
AsmOp::Custom("s0 DUMP", 1, 1), true);
|
||||||
|
define_builtin_func("~strdump", TypeExpr::new_forall({X}, TypeExpr::new_map(X, TypeExpr::new_tensor({X, Unit}))),
|
||||||
|
AsmOp::Custom("STRDUMP", 1, 1), true);
|
||||||
define_builtin_func("run_method0", TypeExpr::new_map(Int, Unit),
|
define_builtin_func("run_method0", TypeExpr::new_map(Int, Unit),
|
||||||
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 0, false); }, true);
|
[](auto a, auto b, auto c) { return compile_run_method(a, b, c, 0, false); }, true);
|
||||||
define_builtin_func("run_method1", TypeExpr::new_forall({X}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X}), Unit)),
|
define_builtin_func("run_method1", TypeExpr::new_forall({X}, TypeExpr::new_map(TypeExpr::new_tensor({Int, X}), Unit)),
|
||||||
|
|
|
@ -105,6 +105,43 @@ int exec_dump_value(VmState* st, unsigned arg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int exec_dump_string(VmState* st) {
|
||||||
|
VM_LOG(st) << "execute STRDUMP";
|
||||||
|
if (!vm_debug_enabled) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stack& stack = st->get_stack();
|
||||||
|
|
||||||
|
if (stack.depth() > 0){
|
||||||
|
auto cs = stack[0].as_slice();
|
||||||
|
|
||||||
|
if (cs.not_null()) { // wanted t_slice
|
||||||
|
auto size = cs->size();
|
||||||
|
|
||||||
|
if (size % 8 == 0) {
|
||||||
|
auto cnt = size / 8;
|
||||||
|
|
||||||
|
unsigned char tmp[128];
|
||||||
|
cs.write().fetch_bytes(tmp, cnt);
|
||||||
|
std::string s{tmp, tmp + cnt};
|
||||||
|
|
||||||
|
std::cerr << "#DEBUG#: " << s << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cerr << "#DEBUG#: slice contains not valid bits count" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
std::cerr << "#DEBUG#: is not a slice" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cerr << "#DEBUG#: s0 is absent" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void register_debug_ops(OpcodeTable& cp0) {
|
void register_debug_ops(OpcodeTable& cp0) {
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
if (!vm_debug_enabled) {
|
if (!vm_debug_enabled) {
|
||||||
|
@ -113,7 +150,9 @@ void register_debug_ops(OpcodeTable& cp0) {
|
||||||
} else {
|
} else {
|
||||||
// NB: all non-redefined opcodes in fe00..feff should be redirected to dummy debug definitions
|
// NB: all non-redefined opcodes in fe00..feff should be redirected to dummy debug definitions
|
||||||
cp0.insert(OpcodeInstr::mksimple(0xfe00, 16, "DUMPSTK", exec_dump_stack))
|
cp0.insert(OpcodeInstr::mksimple(0xfe00, 16, "DUMPSTK", exec_dump_stack))
|
||||||
.insert(OpcodeInstr::mkfixedrange(0xfe01, 0xfe20, 16, 8, instr::dump_1c_and(0xff, "DEBUG "), exec_dummy_debug))
|
.insert(OpcodeInstr::mkfixedrange(0xfe01, 0xfe14, 16, 8, instr::dump_1c_and(0xff, "DEBUG "), exec_dummy_debug))
|
||||||
|
.insert(OpcodeInstr::mksimple(0xfe14, 16,"STRDUMP", exec_dump_string))
|
||||||
|
.insert(OpcodeInstr::mkfixedrange(0xfe15, 0xfe20, 16, 8, instr::dump_1c_and(0xff, "DEBUG "), exec_dummy_debug))
|
||||||
.insert(OpcodeInstr::mkfixed(0xfe2, 12, 4, instr::dump_1sr("DUMP"), exec_dump_value))
|
.insert(OpcodeInstr::mkfixed(0xfe2, 12, 4, instr::dump_1sr("DUMP"), exec_dump_value))
|
||||||
.insert(OpcodeInstr::mkfixedrange(0xfe30, 0xfef0, 16, 8, instr::dump_1c_and(0xff, "DEBUG "), exec_dummy_debug))
|
.insert(OpcodeInstr::mkfixedrange(0xfe30, 0xfef0, 16, 8, instr::dump_1c_and(0xff, "DEBUG "), exec_dummy_debug))
|
||||||
.insert(OpcodeInstr::mkext(0xfef, 12, 4, dump_dummy_debug_str, exec_dummy_debug_str, compute_len_debug_str));
|
.insert(OpcodeInstr::mkext(0xfef, 12, 4, dump_dummy_debug_str, exec_dummy_debug_str, compute_len_debug_str));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue