Simplification of API.
This commit is contained in:
16
Codegen.jai
16
Codegen.jai
@@ -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 {
|
||||
found_function : bool = false;
|
||||
// found_struct : bool = false;
|
||||
|
||||
@@ -506,7 +506,7 @@ lex :: (result : *Compile_Result) {
|
||||
return;
|
||||
}
|
||||
|
||||
for file : result.files {
|
||||
for *file : result.files {
|
||||
lexer : Lexer;
|
||||
init_lexer_from_string(*lexer, file.file.source);
|
||||
token : *Token = scan_next_token(*lexer);
|
||||
@@ -514,6 +514,8 @@ lex :: (result : *Compile_Result) {
|
||||
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
|
||||
copy_messages(lexer.result.messages, *result.messages);
|
||||
}
|
||||
|
||||
@@ -1061,6 +1061,10 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
|
||||
}
|
||||
|
||||
parse :: (result : *Compile_Result) {
|
||||
if result.had_error {
|
||||
return;
|
||||
}
|
||||
|
||||
for *file : result.files {
|
||||
parse_state : Parse_State;
|
||||
init_parse_state(*parse_state, file.tokens.tokens, file.file.path);
|
||||
|
||||
@@ -1651,6 +1651,27 @@ type_check :: (checker : *Semantic_Checker, root : *AST_Node) {
|
||||
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 {
|
||||
checker.current_buffer_index = 0;
|
||||
checker.current_sampler_index = 0;
|
||||
|
||||
12
module.jai
12
module.jai
@@ -145,7 +145,11 @@ Compiled_File :: struct {
|
||||
file : Input_File;
|
||||
tokens : Token_Stream;
|
||||
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 {
|
||||
@@ -368,9 +372,9 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
|
||||
}
|
||||
|
||||
lex(*result);
|
||||
// parse(*result);
|
||||
// check(*result);
|
||||
// codegen(*result);
|
||||
parse(*result);
|
||||
check(*result);
|
||||
codegen(*result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user