1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[FunC] CMake option -DFUNC_DEBUG for development purposes

Seeing function name in debugger
makes it much easier to delve into FunC sources
This commit is contained in:
Aleksandr Kirsanov 2024-04-20 23:13:10 +03:00
parent a5d2a1003f
commit cbd78964c5
No known key found for this signature in database
GPG key ID: B758BBAA01FFB3D3
4 changed files with 28 additions and 0 deletions

View file

@ -390,6 +390,10 @@ target_link_libraries(func PUBLIC ton_crypto src_parser git ton_block)
if (WINGETOPT_FOUND)
target_link_libraries_system(func wingetopt)
endif()
if (${FUNC_DEBUG}) # -DFUNC_DEBUG=1 in CMake options => #define FUNC_DEBUG (for development purposes)
message(STATUS "FUNC_DEBUG is ON")
target_compile_definitions(func PRIVATE FUNC_DEBUG=1)
endif()
if (USE_EMSCRIPTEN)
add_executable(funcfiftlib funcfiftlib/funcfiftlib.cpp ${FUNC_LIB_SOURCE})

View file

@ -51,6 +51,9 @@ template <typename T>
SymDef* define_builtin_func(std::string name, TypeExpr* func_type, const T& func, bool impure = false) {
SymDef* def = predefine_builtin_func(name, func_type);
def->value = new SymValAsmFunc{func_type, func, impure};
#ifdef FUNC_DEBUG
dynamic_cast<SymValAsmFunc*>(def->value)->name = name;
#endif
return def;
}
@ -59,6 +62,9 @@ SymDef* define_builtin_func(std::string name, TypeExpr* func_type, const T& func
std::initializer_list<int> ret_order = {}, bool impure = false) {
SymDef* def = predefine_builtin_func(name, func_type);
def->value = new SymValAsmFunc{func_type, func, arg_order, ret_order, impure};
#ifdef FUNC_DEBUG
dynamic_cast<SymValAsmFunc*>(def->value)->name = name;
#endif
return def;
}
@ -67,6 +73,9 @@ SymDef* define_builtin_func(std::string name, TypeExpr* func_type, const AsmOp&
bool impure = false) {
SymDef* def = predefine_builtin_func(name, func_type);
def->value = new SymValAsmFunc{func_type, make_simple_compile(macro), arg_order, ret_order, impure};
#ifdef FUNC_DEBUG
dynamic_cast<SymValAsmFunc*>(def->value)->name = name;
#endif
return def;
}

View file

@ -773,6 +773,9 @@ struct SymVal : sym::SymValBase {
struct SymValFunc : SymVal {
std::vector<int> arg_order, ret_order;
#ifdef FUNC_DEBUG
std::string name; // seeing function name in debugger makes it much easier to delve into FunC sources
#endif
~SymValFunc() override = default;
SymValFunc(int val, TypeExpr* _ft, bool _impure = false) : SymVal(_Func, val, _ft, _impure) {
}
@ -809,6 +812,9 @@ struct SymValType : sym::SymValBase {
struct SymValGlobVar : sym::SymValBase {
TypeExpr* sym_type;
int out_idx{0};
#ifdef FUNC_DEBUG
std::string name; // seeing variable name in debugger makes it much easier to delve into FunC sources
#endif
SymValGlobVar(int val, TypeExpr* gvtype, int oidx = 0)
: sym::SymValBase(_GlobVar, val), sym_type(gvtype), out_idx(oidx) {
}

View file

@ -230,6 +230,9 @@ void parse_global_var_decl(Lexer& lex) {
}
} else {
sym_def->value = new SymValGlobVar{glob_var_cnt++, var_type};
#ifdef FUNC_DEBUG
dynamic_cast<SymValGlobVar*>(sym_def->value)->name = lex.cur().str;
#endif
glob_vars.push_back(sym_def);
}
lex.next();
@ -384,6 +387,9 @@ void parse_global_var_decls(Lexer& lex) {
SymValCodeFunc* make_new_glob_func(SymDef* func_sym, TypeExpr* func_type, bool impure = false) {
SymValCodeFunc* res = new SymValCodeFunc{glob_func_cnt, func_type, impure};
#ifdef FUNC_DEBUG
res->name = func_sym->name();
#endif
func_sym->value = res;
glob_func.push_back(func_sym);
glob_func_cnt++;
@ -1530,6 +1536,9 @@ void parse_func_def(Lexer& lex) {
} else {
Lexem asm_lexem = lex.cur();
SymValAsmFunc* asm_func = parse_asm_func_body(lex, func_type, arg_list, ret_type, impure);
#ifdef FUNC_DEBUG
asm_func->name = func_name.str;
#endif
if (func_sym_val) {
if (dynamic_cast<SymValCodeFunc*>(func_sym_val)) {
asm_lexem.error("function `"s + func_name.str + "` was already declared as an ordinary function");