diff --git a/Codegen.jai b/Codegen.jai index e380144..883903b 100644 --- a/Codegen.jai +++ b/Codegen.jai @@ -617,7 +617,7 @@ codegen :: (result : *Compile_Result) { for *file : result.files { state : Codegen_State; - init_codegen_state(*state, file.ast_root, file.semantic_check_result, .HLSL); + // init_codegen_state(*state, file.ast_root, file.semantic_check_result, .HLSL); //@Incomplete(nb): just call the codegen function for now with old result struct codegen_result := codegen(*state); diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index cccd61c..884c585 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -1774,7 +1774,24 @@ check :: (result : *Compile_Result) { type_check(*checker, file.ast_root); - file.semantic_check_result = checker.result; + file.constant_buffers = array_copy(*checker.result.constant_buffers); + + //@Incomplete: should just be a copy? + file.scope_stack.stack.allocator = file.allocator; + array_reserve(*file.scope_stack.stack, checker.result.scope_stack.stack.count); + for scope : checker.result.scope_stack.stack { + array_add(*file.scope_stack.stack, scope); + } + + file.type_variables.allocator = file.allocator; + array_reserve(*file.type_variables, checker.result.type_variables.count); + for tv : checker.result.type_variables { + array_add(*file.type_variables, tv); + } + + file.vertex_entry_point.node = checker.result.vertex_entry_point; + file.pixel_entry_point.node = checker.result.pixel_entry_point; + result.had_error |= checker.result.had_error; copy_messages(checker.result.messages, *result.messages); } @@ -2084,8 +2101,7 @@ pretty_print_symbol_table :: (result : *Compile_Result, allocator : Allocator) - for *file : result.files { current_scope := cast(Scope_Handle)1; - check_result := file.semantic_check_result; - pretty_print_scope(current_scope, check_result.scope_stack, check_result.type_variables, *check_result.scope_stack.stack[0], *builder); + pretty_print_scope(current_scope, file.scope_stack, file.type_variables, *file.scope_stack.stack[0], *builder); } diff --git a/module.jai b/module.jai index d1117d2..62ce9dd 100644 --- a/module.jai +++ b/module.jai @@ -149,17 +149,22 @@ Compiled_File :: struct { codegen_result_text : string; - semantic_check_result : Semantic_Check_Result; + constant_buffers : Static_Array(Type_Variable_Handle, 16); + + scope_stack : Scope_Stack; + type_variables : [..]Type_Variable; + + property_name : string; vertex_entry_point : struct { + node : *AST_Node; name : string; - input : [..]Field; } pixel_entry_point : struct { + node : *AST_Node; name : string; - return_value : Field; } @@ -167,6 +172,9 @@ Compiled_File :: struct { max_constant_buffers :: 16; cbuffers : Static_Array(Constant_Buffer, max_constant_buffers); + + allocator : Allocator; + arena : Arena; } Compile_Result :: struct { @@ -196,6 +204,8 @@ add_file :: (result : *Compile_Result, path : string) { compiled_file : Compiled_File; compiled_file.file = input_file; + compiled_file.allocator = make_arena(*compiled_file.arena); + array_add(*result.files, compiled_file); } @@ -407,11 +417,10 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul } for *file : result.files { - check_result := file.semantic_check_result; - if check_result.vertex_entry_point { - file.vertex_entry_point.name = check_result.vertex_entry_point.name; + if file.vertex_entry_point.node { + file.vertex_entry_point.name = file.vertex_entry_point.node.name; - type_variable := from_handle(check_result.type_variables, check_result.vertex_entry_point.type_variable); + type_variable := from_handle(file.type_variables, file.vertex_entry_point.node.type_variable); assert(type_variable.type == .Function); node := type_variable.source_node; @@ -419,36 +428,36 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul if node.children[0].kind == .FieldList { field_list := node.children[0]; for child : field_list.children { - tv := from_handle(check_result.type_variables, child.type_variable); - field := type_variable_to_field(check_result.type_variables, check_result.scope_stack, tv); + tv := from_handle(file.type_variables, child.type_variable); + field := type_variable_to_field(file.type_variables, file.scope_stack, tv); array_add(*file.vertex_entry_point.input, field); } } } } - for buffer_variable : to_array(*check_result.constant_buffers) { - variable := from_handle(check_result.type_variables, buffer_variable); + for buffer_variable : file.constant_buffers { + variable := from_handle(file.type_variables, buffer_variable); cb := array_add(*file.cbuffers); for i : 0..variable.children.count - 1 { child := variable.children[i]; field : Property_Field; - field.base_field = type_variable_to_field(check_result.type_variables, check_result.scope_stack, from_handle(check_result.type_variables, child)); + field.base_field = type_variable_to_field(file.type_variables, file.scope_stack, from_handle(file.type_variables, child)); array_add(*cb.fields, field); } cb.buffer_index = variable.resource_index; } - find_result := find_symbol(*check_result.scope_stack, check_result.property_name, xx 1); + find_result := find_symbol(*file.scope_stack, file.property_name, xx 1); if find_result { - property_variable := from_handle(check_result.type_variables, find_result.type_variable); + property_variable := from_handle(file.type_variables, find_result.type_variable); for i : 0..property_variable.children.count - 1 { child := property_variable.children[i]; - field := type_variable_to_field(check_result.type_variables, check_result.scope_stack, from_handle(check_result.type_variables, child)); + field := type_variable_to_field(file.type_variables, file.scope_stack, from_handle(file.type_variables, child)); prop_field : Property_Field; prop_field.base_field = field; array_add(*file.properties.fields, prop_field); @@ -456,13 +465,13 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul file.properties.buffer_index = property_variable.resource_index; } - if check_result.pixel_entry_point { - file.pixel_entry_point.name = check_result.pixel_entry_point.name; + if file.pixel_entry_point.node { + file.pixel_entry_point.name = file.pixel_entry_point.node.name; - type_variable := from_handle(check_result.type_variables, check_result.pixel_entry_point.type_variable); + type_variable := from_handle(file.type_variables, file.pixel_entry_point.node.type_variable); assert(type_variable.type == .Function); - field := type_variable_to_field(check_result.type_variables, check_result.scope_stack, type_variable.return_type_variable); + field := type_variable_to_field(file.type_variables, file.scope_stack, type_variable.return_type_variable); for hint : type_variable.source_node.hint_tokens { field_hint : Field_Hint;