diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 15bafadf80c354..7f44932550cd2a 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -600,9 +600,6 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO if g.out_results.len > 0 { b.write_string2('\n// V result_xxx definitions:\n', g.out_results.str()) } - if g.json_forward_decls.len > 0 { - b.write_string2('\n// V json forward decls:\n', g.json_forward_decls.str()) - } b.write_string2('\n// V definitions:\n', g.definitions.str()) if g.sort_fn_definitions.len > 0 { b.write_string2('\n// V sort fn definitions:\n', g.sort_fn_definitions.str()) @@ -621,18 +618,9 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO if interface_table.len > 0 { b.write_string2('\n// V interface table:\n', interface_table) } - if g.waiter_fn_definitions.len > 0 { - b.write_string2('\n// V gowrappers waiter fns:\n', g.waiter_fn_definitions.str()) - } - if g.gowrappers.len > 0 { - b.write_string2('\n// V gowrappers:\n', g.gowrappers.str()) - } if g.hotcode_definitions.len > 0 { b.write_string2('\n// V hotcode definitions:\n', g.hotcode_definitions.str()) } - if g.embedded_data.len > 0 { - b.write_string2('\n// V embedded data:\n', g.embedded_data.str()) - } if g.shared_functions.len > 0 { b.writeln('\n// V shared type functions:\n') b.write_string2(g.shared_functions.str(), c_concurrency_helpers) @@ -659,10 +647,13 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO header = '#ifndef V_HEADER_FILE\n#define V_HEADER_FILE' + header header += '\n#endif\n' - mut helpers := strings.new_builder(200_000) + mut helpers := strings.new_builder(300_000) // Code added here (after the header) goes to out_0.c in parallel cc mode // Previously it went to the header which resulted in duplicated code and more code // to compile for the C compiler + if g.embedded_data.len > 0 { + helpers.write_string2('\n// V embedded data:\n', g.embedded_data.str()) + } if g.anon_fn_definitions.len > 0 { if g.nr_closures > 0 { helpers.writeln2('\n// V closure helpers', c_closure_fn_helpers(g.pref)) @@ -693,6 +684,12 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO } } } + if g.waiter_fn_definitions.len > 0 { + if g.pref.parallel_cc { + g.extern_out.write_string2('\n// V gowrappers waiter fns:\n', g.waiter_fn_definitions.bytestr()) + } + helpers.write_string2('\n// V gowrappers waiter fns:\n', g.waiter_fn_definitions.str()) + } if g.auto_str_funcs.len > 0 { helpers.write_string2('\n// V auto str functions:\n', g.auto_str_funcs.str()) } @@ -702,6 +699,15 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO helpers.writeln(fn_def) } } + if g.json_forward_decls.len > 0 { + helpers.write_string2('\n// V json forward decls:\n', g.json_forward_decls.bytestr()) + if g.pref.parallel_cc { + g.extern_out.write_string2('\n// V json forward decls:\n', g.json_forward_decls.str()) + } + } + if g.gowrappers.len > 0 { + helpers.write_string2('\n// V gowrappers:\n', g.gowrappers.str()) + } if g.dump_funcs.len > 0 { helpers.write_string2('\n// V dump functions:\n', g.dump_funcs.str()) } @@ -1152,6 +1158,9 @@ pub fn (mut g Gen) write_typeof_functions() { } g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}') g.writeln2('', 'int v_typeof_interface_idx_${sym.cname}(int sidx) {') + if g.pref.parallel_cc { + g.extern_out.writeln('extern int v_typeof_interface_idx_${sym.cname}(int sidx);') + } for t in inter_info.types { sub_sym := g.table.sym(ast.mktyp(t)) if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() { diff --git a/vlib/v/gen/c/embed.v b/vlib/v/gen/c/embed.v index 890018d56f6866..db931f54c6fd07 100644 --- a/vlib/v/gen/c/embed.v +++ b/vlib/v/gen/c/embed.v @@ -85,6 +85,9 @@ fn (mut g Gen) gen_embed_file_init(mut node ast.ComptimeCall) { // into a single generated function _v_embed_file_metadata, that accepts a hash of the absolute path of the embedded // files. fn (mut g Gen) gen_embedded_metadata() { + if g.pref.parallel_cc { + g.extern_out.writeln('extern v__embed_file__EmbedFileData _v_embed_file_metadata(u64 ef_hash);') + } g.embedded_data.writeln('v__embed_file__EmbedFileData _v_embed_file_metadata(u64 ef_hash) {') g.embedded_data.writeln('\tv__embed_file__EmbedFileData res;') g.embedded_data.writeln('\tmemset(&res, 0, sizeof(res));') diff --git a/vlib/v/gen/c/json.v b/vlib/v/gen/c/json.v index b9db96dd620876..ba3b36a237009f 100644 --- a/vlib/v/gen/c/json.v +++ b/vlib/v/gen/c/json.v @@ -119,12 +119,13 @@ ${dec_fn_dec} { } } ') - g.json_forward_decls.writeln('${dec_fn_dec};') + extern_str := if g.pref.parallel_cc { 'extern ' } else { '' } + g.json_forward_decls.writeln('${extern_str}${dec_fn_dec};') // Codegen encoder // encode_TYPE funcs receive an object to encode enc_fn_name := js_enc_name(styp) enc_fn_dec := 'cJSON* ${enc_fn_name}(${styp} val)' - g.json_forward_decls.writeln('${enc_fn_dec};\n') + g.json_forward_decls.writeln('${extern_str}${enc_fn_dec};\n') enc.writeln(' ${enc_fn_dec} { \tcJSON *o;') diff --git a/vlib/v/gen/c/spawn_and_go.v b/vlib/v/gen/c/spawn_and_go.v index d37f93d6373db0..7011475d0d4395 100644 --- a/vlib/v/gen/c/spawn_and_go.v +++ b/vlib/v/gen/c/spawn_and_go.v @@ -305,7 +305,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) { } g.type_definitions.writeln('} ${wrapper_struct_name};') thread_ret_type := if g.pref.os == .windows { 'u32' } else { 'void*' } - g.type_definitions.writeln('${g.static_modifier} ${thread_ret_type} ${wrapper_fn_name}(${wrapper_struct_name} *arg);') + g.waiter_fn_definitions.writeln('${g.static_non_parallel}${thread_ret_type} ${wrapper_fn_name}(${wrapper_struct_name} *arg);') g.gowrappers.writeln('${thread_ret_type} ${wrapper_fn_name}(${wrapper_struct_name} *arg) {') if call_ret_type != ast.void_type { if g.pref.os == .windows {