authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-28 19:57:59+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-28 19:57:59+03:00
logaf73462da46611ea9293f283ce8a6920ad73b10f
treeceee8d805da4fc252cbe406c6b0630891d9e763a
parent9ba400673d798ea6f0842e4c207039c9faffb27e

Started work on function definition TypeInfo generation.


2 files changed, 52 insertions(+), 2 deletions(-)

src/codegen.cpp+17-1
...@@ -6494,7 +6494,19 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6494,7 +6494,19 @@ static void define_builtin_compile_vars(CodeGen *g) {
6494 " const Data = union(enum) {\n"6494 " const Data = union(enum) {\n"
6495 " Type: type,\n"6495 " Type: type,\n"
6496 " Var: type,\n"6496 " Var: type,\n"
6497 " Fn: void,\n"6497 " Fn: FnDef,\n"
6498 "\n"
6499 " const FnDef = struct {\n"
6500 " fn_type: type,\n"
6501 " inline_type: Inline,\n"
6502 " calling_convention: CallingConvention,\n"
6503 "\n"
6504 " const Inline = enum {\n"
6505 " Auto,\n"
6506 " Always,\n"
6507 " Never,\n"
6508 " };\n"
6509 " };\n"
6498 " };\n"6510 " };\n"
6499 " };\n"6511 " };\n"
6500 "};\n\n");6512 "};\n\n");
...@@ -6508,6 +6520,10 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6508,6 +6520,10 @@ static void define_builtin_compile_vars(CodeGen *g) {
6508 assert(CallingConventionNaked == 3);6520 assert(CallingConventionNaked == 3);
6509 assert(CallingConventionStdcall == 4);6521 assert(CallingConventionStdcall == 4);
6510 assert(CallingConventionAsync == 5);6522 assert(CallingConventionAsync == 5);
6523
6524 assert(FnInlineAuto == 0);
6525 assert(FnInlineAlways == 1);
6526 assert(FnInlineNever == 2);
6511 }6527 }
6512 {6528 {
6513 buf_appendf(contents,6529 buf_appendf(contents,
src/ir.cpp+35-1
...@@ -15797,6 +15797,12 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15797,6 +15797,12 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15797 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);15797 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
15798 ensure_complete_type(ira->codegen, type_info_definition_data_type);15798 ensure_complete_type(ira->codegen, type_info_definition_data_type);
1579915799
15800 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
15801 ensure_complete_type(ira->codegen, type_info_fn_def_type);
15802
15803 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
15804 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);
15805
15800 // Loop through our definitions once to figure out how many definitions we will generate info for.15806 // Loop through our definitions once to figure out how many definitions we will generate info for.
15801 auto decl_it = decls_scope->decl_table.entry_iterator();15807 auto decl_it = decls_scope->decl_table.entry_iterator();
15802 decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;15808 decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;
...@@ -15905,7 +15911,35 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15905,7 +15911,35 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15905 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;15911 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
15906 assert(!fn_entry->is_test);15912 assert(!fn_entry->is_test);
1590715913
15908 inner_fields[2].data.x_union.payload = nullptr;15914 AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
15915
15916 ConstExprValue *fn_def_val = create_const_vals(1);
15917 fn_def_val->special = ConstValSpecialStatic;
15918 fn_def_val->type = type_info_fn_def_type;
15919 fn_def_val->data.x_struct.parent.id = ConstParentIdUnion;
15920 fn_def_val->data.x_struct.parent.data.p_union.union_val = &inner_fields[2];
15921
15922 // @TODO Add fields
15923 ConstExprValue *fn_def_fields = create_const_vals(3);
15924 fn_def_val->data.x_struct.fields = fn_def_fields;
15925
15926 // fn_type: type
15927 ensure_field_index(fn_def_val->type, "fn_type", 0);
15928 fn_def_fields[0].special = ConstValSpecialStatic;
15929 fn_def_fields[0].type = ira->codegen->builtin_types.entry_type;
15930 fn_def_fields[0].data.x_type = fn_entry->type_entry;
15931 // inline_type: Data.FnDef.Inline
15932 ensure_field_index(fn_def_val->type, "inline_type", 1);
15933 fn_def_fields[1].special = ConstValSpecialStatic;
15934 fn_def_fields[1].type = type_info_fn_def_inline_type;
15935 bigint_init_unsigned(&fn_def_fields[1].data.x_enum_tag, fn_entry->fn_inline);
15936 // calling_convention: TypeInfo.CallingConvention
15937 ensure_field_index(fn_def_val->type, "calling_convention", 2);
15938 fn_def_fields[2].special = ConstValSpecialStatic;
15939 fn_def_fields[2].type = ir_type_info_get_type(ira, "CallingConvention");
15940 bigint_init_unsigned(&fn_def_fields[2].data.x_enum_tag, fn_node->cc);
15941
15942 inner_fields[2].data.x_union.payload = fn_def_val;
15909 break;15943 break;
15910 }15944 }
15911 case TldIdContainer:15945 case TldIdContainer: