Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -5314,6 +5314,37 @@ fn (g &Gen) checker_bug(s string, pos token.Pos) {
g.error('checker bug; ${s}', pos)
}

// write_debug_calls_typeof_functions inserts calls to all typeof functions for
// interfaces and sum-types in debug mode so that the compiler does not optimize them.
// These functions are needed to be able to get the name of a specific structure/type in the debugger.
fn (mut g Gen) write_debug_calls_typeof_functions() {
if !g.pref.is_debug {
return
}

g.writeln('\t// we call these functions in debug mode so that the C compiler')
g.writeln('\t// does not optimize them and we can access them in the debugger.')
for _, sym in g.table.type_symbols {
if sym.kind == .sum_type {
sum_info := sym.info as ast.SumType
if sum_info.is_generic {
continue
}
g.writeln('\tv_typeof_sumtype_${sym.cname}(0);')
}
if sym.kind == .interface_ {
if sym.info !is ast.Interface {
continue
}
inter_info := sym.info as ast.Interface
if inter_info.is_generic {
continue
}
g.writeln('\tv_typeof_interface_${sym.cname}(0);')
}
}
}

fn (mut g Gen) write_init_function() {
if g.pref.no_builtin || (g.pref.translated && g.pref.is_o) {
return
Expand All @@ -5330,6 +5361,8 @@ fn (mut g Gen) write_init_function() {
// ___argv is declared as voidptr here, because that unifies the windows/unix logic
g.writeln('void _vinit(int ___argc, voidptr ___argv) {')

g.write_debug_calls_typeof_functions()

if g.pref.trace_calls {
g.writeln('\tv__trace_calls__on_call(_SLIT("_vinit"));')
}
Expand Down