Move compile result stuff out of specific stages.
This commit is contained in:
164
module.jai
164
module.jai
@@ -140,11 +140,17 @@ Token_Stream :: struct {
|
||||
tokens : [..]Token;
|
||||
}
|
||||
|
||||
Compiled_File :: struct {
|
||||
// Compiled_File :: struct {
|
||||
|
||||
// allocator : Allocator;
|
||||
// arena : Arena;
|
||||
// }
|
||||
|
||||
Compile_Result :: struct {
|
||||
file : Input_File;
|
||||
tokens : Token_Stream;
|
||||
ast_root : *AST_Node;
|
||||
ast_nodes : [..]AST_Node;
|
||||
root : *AST_Node;
|
||||
nodes : [..]AST_Node;
|
||||
|
||||
codegen_result_text : string;
|
||||
|
||||
@@ -172,12 +178,6 @@ Compiled_File :: struct {
|
||||
max_constant_buffers :: 16;
|
||||
cbuffers : Static_Array(Constant_Buffer, max_constant_buffers);
|
||||
|
||||
allocator : Allocator;
|
||||
arena : Arena;
|
||||
}
|
||||
|
||||
Compile_Result :: struct {
|
||||
files : [..]Compiled_File;
|
||||
|
||||
had_error : bool;
|
||||
messages : [..]Compiler_Message;
|
||||
@@ -203,17 +203,18 @@ add_file :: (result : *Compile_Result, path : string) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_file_from_string(result, file_string, path);
|
||||
}
|
||||
|
||||
add_file_from_string :: (result : *Compile_Result, source : string, path : string = "") {
|
||||
input_file : Input_File;
|
||||
|
||||
input_file.source = file_string;
|
||||
input_file.source = source;
|
||||
input_file.path = path;
|
||||
|
||||
compiled_file : Compiled_File;
|
||||
compiled_file.file = input_file;
|
||||
result.file = input_file;
|
||||
|
||||
compiled_file.allocator = make_arena(*compiled_file.arena);
|
||||
|
||||
array_add(*result.files, compiled_file);
|
||||
result.allocator = make_arena(*result.arena);
|
||||
}
|
||||
|
||||
// @Incomplete(nb): Will we ever even use this?
|
||||
@@ -396,95 +397,112 @@ type_variable_to_field :: (type_variables : []Type_Variable, scope_stack : Scope
|
||||
}
|
||||
|
||||
type_variable_to_field :: (checker : *Semantic_Checker, variable : *Type_Variable) -> Field {
|
||||
return type_variable_to_field(checker.result_file.type_variables, checker.result_file.scope_stack, variable);
|
||||
return type_variable_to_field(checker.result.type_variables, checker.result.scope_stack, variable);
|
||||
}
|
||||
|
||||
generate_output_data :: (result : *Compile_Result) {
|
||||
for *file : result.files {
|
||||
if file.vertex_entry_point.node {
|
||||
file.vertex_entry_point.name = file.vertex_entry_point.node.name;
|
||||
if result.had_error {
|
||||
return;
|
||||
}
|
||||
|
||||
if result.vertex_entry_point.node {
|
||||
result.vertex_entry_point.name = result.vertex_entry_point.node.name;
|
||||
|
||||
type_variable := from_handle(file.type_variables, file.vertex_entry_point.node.type_variable);
|
||||
assert(type_variable.type == .Function);
|
||||
type_variable := from_handle(result.type_variables, result.vertex_entry_point.node.type_variable);
|
||||
assert(type_variable.type == .Function);
|
||||
|
||||
node := type_variable.source_node;
|
||||
if node.children.count > 0 {
|
||||
if node.children[0].kind == .FieldList {
|
||||
field_list := node.children[0];
|
||||
for child : field_list.children {
|
||||
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);
|
||||
}
|
||||
node := type_variable.source_node;
|
||||
if node.children.count > 0 {
|
||||
if node.children[0].kind == .FieldList {
|
||||
field_list := node.children[0];
|
||||
for child : field_list.children {
|
||||
tv := from_handle(result.type_variables, child.type_variable);
|
||||
field := type_variable_to_field(result.type_variables, result.scope_stack, tv);
|
||||
array_add(*result.vertex_entry_point.input, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for buffer_variable : file.constant_buffers {
|
||||
variable := from_handle(file.type_variables, buffer_variable);
|
||||
for buffer_variable : result.constant_buffers {
|
||||
variable := from_handle(result.type_variables, buffer_variable);
|
||||
|
||||
cb := array_add(*file.cbuffers);
|
||||
cb := array_add(*result.cbuffers);
|
||||
|
||||
for i : 0..variable.children.count - 1 {
|
||||
child := variable.children[i];
|
||||
field : Property_Field;
|
||||
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;
|
||||
for i : 0..variable.children.count - 1 {
|
||||
child := variable.children[i];
|
||||
field : Property_Field;
|
||||
field.base_field = type_variable_to_field(result.type_variables, result.scope_stack, from_handle(result.type_variables, child));
|
||||
array_add(*cb.fields, field);
|
||||
}
|
||||
|
||||
find_result := find_symbol(*file.scope_stack, file.property_name, xx 1);
|
||||
cb.buffer_index = variable.resource_index;
|
||||
}
|
||||
|
||||
find_result := find_symbol(*result.scope_stack, result.property_name, xx 1);
|
||||
if find_result {
|
||||
property_variable := from_handle(file.type_variables, find_result.type_variable);
|
||||
property_variable := from_handle(result.type_variables, find_result.type_variable);
|
||||
|
||||
for i : 0..property_variable.children.count - 1 {
|
||||
child := property_variable.children[i];
|
||||
field := type_variable_to_field(file.type_variables, file.scope_stack, from_handle(file.type_variables, child));
|
||||
field := type_variable_to_field(result.type_variables, result.scope_stack, from_handle(result.type_variables, child));
|
||||
prop_field : Property_Field;
|
||||
prop_field.base_field = field;
|
||||
array_add(*file.properties.fields, prop_field);
|
||||
array_add(*result.properties.fields, prop_field);
|
||||
}
|
||||
file.properties.buffer_index = property_variable.resource_index;
|
||||
result.properties.buffer_index = property_variable.resource_index;
|
||||
}
|
||||
|
||||
if file.pixel_entry_point.node {
|
||||
file.pixel_entry_point.name = file.pixel_entry_point.node.name;
|
||||
|
||||
type_variable := from_handle(file.type_variables, file.pixel_entry_point.node.type_variable);
|
||||
assert(type_variable.type == .Function);
|
||||
if result.pixel_entry_point.node {
|
||||
result.pixel_entry_point.name = result.pixel_entry_point.node.name;
|
||||
|
||||
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;
|
||||
type_variable := from_handle(result.type_variables, result.pixel_entry_point.node.type_variable);
|
||||
assert(type_variable.type == .Function);
|
||||
|
||||
if hint.ident_value == "position" {
|
||||
// @Incomplete(nb): Should be a lookup table somewhere
|
||||
field_hint.kind = .Position;
|
||||
} else if starts_with(hint.ident_value, "target") {
|
||||
// @Incomplete(nb): Should be a lookup table somewhere
|
||||
index_str : string;
|
||||
index_str.data = *hint.ident_value.data[7];
|
||||
index_str.count = 1;
|
||||
|
||||
result, ok, remainder := string_to_int(index_str);
|
||||
if ok {
|
||||
field_hint.target_index = result;
|
||||
}
|
||||
field_hint.kind = .Target;
|
||||
} else {
|
||||
// @Incomplete(nb): custom hints
|
||||
field := type_variable_to_field(result.type_variables, result.scope_stack, type_variable.return_type_variable);
|
||||
for hint : type_variable.source_node.hint_tokens {
|
||||
field_hint : Field_Hint;
|
||||
|
||||
if hint.ident_value == "position" {
|
||||
// @Incomplete(nb): Should be a lookup table somewhere
|
||||
field_hint.kind = .Position;
|
||||
} else if starts_with(hint.ident_value, "target") {
|
||||
// @Incomplete(nb): Should be a lookup table somewhere
|
||||
index_str : string;
|
||||
index_str.data = *hint.ident_value.data[7];
|
||||
index_str.count = 1;
|
||||
|
||||
result, ok, remainder := string_to_int(index_str);
|
||||
if ok {
|
||||
field_hint.target_index = result;
|
||||
}
|
||||
array_add(*field.hints, field_hint);
|
||||
field_hint.kind = .Target;
|
||||
} else {
|
||||
// @Incomplete(nb): custom hints
|
||||
}
|
||||
|
||||
file.pixel_entry_point.return_value = field;
|
||||
array_add(*field.hints, field_hint);
|
||||
}
|
||||
|
||||
result.pixel_entry_point.return_value = field;
|
||||
}
|
||||
}
|
||||
|
||||
compile_file :: (compiler : *Shader_Compiler, paths : ..string) -> Compile_Result {
|
||||
compile_file :: (compiler : *Shader_Compiler, path : string) -> Compile_Result {
|
||||
result : Compile_Result;
|
||||
|
||||
add_file(*result, path);
|
||||
|
||||
lex(*result);
|
||||
parse(*result);
|
||||
check(*result);
|
||||
codegen(*result);
|
||||
generate_output_data(*result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
compile_files :: (compiler : *Shader_Compiler, paths : ..string) -> Compile_Result {
|
||||
result : Compile_Result;
|
||||
|
||||
for path : paths {
|
||||
|
||||
Reference in New Issue
Block a user