| ... | @@ -9884,6 +9884,28 @@ static void gen_h_file_functions(CodeGen* g, GenH* gen_h, Buf* out_buf, Buf* exp | ... | @@ -9884,6 +9884,28 @@ static void gen_h_file_functions(CodeGen* g, GenH* gen_h, Buf* out_buf, Buf* exp |
| 9884 | } | 9884 | } |
| 9885 | } | 9885 | } |
| 9886 | | 9886 | |
| | 9887 | static void gen_h_file_variables(CodeGen* g, GenH* gen_h, Buf* h_buf, Buf* export_macro) { |
| | 9888 | for (size_t exp_var_i = 0; exp_var_i < g->global_vars.length; exp_var_i += 1) { |
| | 9889 | ZigVar* var = g->global_vars.at(exp_var_i)->var; |
| | 9890 | if (var->export_list.length == 0) |
| | 9891 | continue; |
| | 9892 | |
| | 9893 | Buf var_type_c = BUF_INIT; |
| | 9894 | get_c_type(g, gen_h, var->var_type, &var_type_c); |
| | 9895 | |
| | 9896 | if (export_macro != nullptr) { |
| | 9897 | buf_appendf(h_buf, "extern %s %s %s;\n", |
| | 9898 | buf_ptr(export_macro), |
| | 9899 | buf_ptr(&var_type_c), |
| | 9900 | var->name); |
| | 9901 | } else { |
| | 9902 | buf_appendf(h_buf, "extern %s %s;\n", |
| | 9903 | buf_ptr(&var_type_c), |
| | 9904 | var->name); |
| | 9905 | } |
| | 9906 | } |
| | 9907 | } |
| | 9908 | |
| 9887 | static void gen_h_file(CodeGen *g) { | 9909 | static void gen_h_file(CodeGen *g) { |
| 9888 | GenH gen_h_data = {0}; | 9910 | GenH gen_h_data = {0}; |
| 9889 | GenH *gen_h = &gen_h_data; | 9911 | GenH *gen_h = &gen_h_data; |
| ... | @@ -9907,9 +9929,15 @@ static void gen_h_file(CodeGen *g) { | ... | @@ -9907,9 +9929,15 @@ static void gen_h_file(CodeGen *g) { |
| 9907 | buf_resize(&fns_buf, 0); | 9929 | buf_resize(&fns_buf, 0); |
| 9908 | gen_h_file_functions(g, gen_h, &fns_buf, export_macro); | 9930 | gen_h_file_functions(g, gen_h, &fns_buf, export_macro); |
| 9909 | | 9931 | |
| | 9932 | Buf vars_buf = BUF_INIT; |
| | 9933 | buf_resize(&vars_buf, 0); |
| | 9934 | gen_h_file_variables(g, gen_h, &vars_buf, export_macro); |
| | 9935 | |
| | 9936 | // Types will be populated by exported functions and variables so it has to run last. |
| 9910 | Buf types_buf = BUF_INIT; | 9937 | Buf types_buf = BUF_INIT; |
| 9911 | buf_resize(&types_buf, 0); | 9938 | buf_resize(&types_buf, 0); |
| 9912 | gen_h_file_types(g, gen_h, &types_buf); | 9939 | gen_h_file_types(g, gen_h, &types_buf); |
| | 9940 | |
| 9913 | Buf *ifdef_dance_name = preprocessor_mangle(buf_sprintf("%s_H", buf_ptr(g->root_out_name))); | 9941 | Buf *ifdef_dance_name = preprocessor_mangle(buf_sprintf("%s_H", buf_ptr(g->root_out_name))); |
| 9914 | buf_upcase(ifdef_dance_name); | 9942 | buf_upcase(ifdef_dance_name); |
| 9915 | | 9943 | |