Simplification of API.

This commit is contained in:
2025-01-04 23:12:54 +01:00
parent 7787d1307b
commit d08529a3eb
5 changed files with 52 additions and 5 deletions

View File

@@ -504,6 +504,22 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
} }
} }
codegen :: (result : *Compile_Result) {
if result.had_error {
return;
}
for *file : result.files {
state : Codegen_State;
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);
file.codegen_result_text = copy_string(codegen_result.result_text);
}
}
codegen :: (state : *Codegen_State) -> Codegen_Result { codegen :: (state : *Codegen_State) -> Codegen_Result {
found_function : bool = false; found_function : bool = false;
// found_struct : bool = false; // found_struct : bool = false;

View File

@@ -506,7 +506,7 @@ lex :: (result : *Compile_Result) {
return; return;
} }
for file : result.files { for *file : result.files {
lexer : Lexer; lexer : Lexer;
init_lexer_from_string(*lexer, file.file.source); init_lexer_from_string(*lexer, file.file.source);
token : *Token = scan_next_token(*lexer); token : *Token = scan_next_token(*lexer);
@@ -514,6 +514,8 @@ lex :: (result : *Compile_Result) {
token = scan_next_token(*lexer); token = scan_next_token(*lexer);
} }
array_copy(*file.tokens.tokens, lexer.result.tokens);
// @Incomplete(nb): Temporary until we figure out a good way of passing this stuff around // @Incomplete(nb): Temporary until we figure out a good way of passing this stuff around
copy_messages(lexer.result.messages, *result.messages); copy_messages(lexer.result.messages, *result.messages);
} }

View File

@@ -1061,6 +1061,10 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
} }
parse :: (result : *Compile_Result) { parse :: (result : *Compile_Result) {
if result.had_error {
return;
}
for *file : result.files { for *file : result.files {
parse_state : Parse_State; parse_state : Parse_State;
init_parse_state(*parse_state, file.tokens.tokens, file.file.path); init_parse_state(*parse_state, file.tokens.tokens, file.file.path);

View File

@@ -1651,6 +1651,27 @@ type_check :: (checker : *Semantic_Checker, root : *AST_Node) {
traverse(checker, root); traverse(checker, root);
} }
check :: (result : *Compile_Result) {
if result.had_error {
return;
}
for *file : result.files {
checker : Semantic_Checker;
checker.current_buffer_index = 0;
checker.current_sampler_index = 0;
checker.current_texture_index = 0;
array_reserve(*checker.result.messages, 16);
add_hlsl_builtins(*checker);
type_check(*checker, file.ast_root);
file.semantic_check_result = checker.result;
copy_messages(checker.result.messages, *result.messages);
}
}
check :: (checker : *Semantic_Checker, root : *AST_Node) -> Semantic_Check_Result { check :: (checker : *Semantic_Checker, root : *AST_Node) -> Semantic_Check_Result {
checker.current_buffer_index = 0; checker.current_buffer_index = 0;
checker.current_sampler_index = 0; checker.current_sampler_index = 0;

View File

@@ -146,6 +146,10 @@ Compiled_File :: struct {
tokens : Token_Stream; tokens : Token_Stream;
ast_root : *AST_Node; ast_root : *AST_Node;
ast_nodes : [..]AST_Node; ast_nodes : [..]AST_Node;
codegen_result_text : string;
semantic_check_result : Semantic_Check_Result;
} }
Compile_Result :: struct { Compile_Result :: struct {
@@ -368,9 +372,9 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
} }
lex(*result); lex(*result);
// parse(*result); parse(*result);
// check(*result); check(*result);
// codegen(*result); codegen(*result);
return result; return result;
} }