More work towards the new API
This commit is contained in:
23
Codegen.jai
23
Codegen.jai
@@ -38,9 +38,13 @@ Codegen_Result :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_codegen_state :: (state : *Codegen_State, root : *AST_Node, checker_result : Semantic_Check_Result, output_language : Output_Language) {
|
init_codegen_state :: (state : *Codegen_State, root : *AST_Node, checker_result : Semantic_Check_Result, output_language : Output_Language) {
|
||||||
|
init_codegen_state(state, root, checker_result.scope_stack, checker_result.type_variables, output_language);
|
||||||
|
}
|
||||||
|
|
||||||
|
init_codegen_state :: (state : *Codegen_State, root : *AST_Node, scope_stack : Scope_Stack, type_vars : [..]Type_Variable, output_language : Output_Language) {
|
||||||
state.root = root;
|
state.root = root;
|
||||||
state.scope_stack = checker_result.scope_stack;
|
state.scope_stack = scope_stack;
|
||||||
state.type_variables = checker_result.type_variables;
|
state.type_variables = type_vars;
|
||||||
state.current_scope = cast(Scope_Handle)1;
|
state.current_scope = cast(Scope_Handle)1;
|
||||||
state.output_language = output_language;
|
state.output_language = output_language;
|
||||||
init_string_builder(*state.builder);
|
init_string_builder(*state.builder);
|
||||||
@@ -504,6 +508,21 @@ emit_declaration :: (state : *Codegen_State, node : *AST_Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
codegen :: (result : *Compile_Result) {
|
||||||
|
for *file : result.files {
|
||||||
|
state : Codegen_State;
|
||||||
|
init_codegen_state(*state, file.ast_root, file.scope_stack, file.type_variables, .HLSL);
|
||||||
|
|
||||||
|
codegen(*state);
|
||||||
|
|
||||||
|
file.output_text = state.result.result_text; // need to copy at some point. This whole thing is messy...
|
||||||
|
|
||||||
|
copy_messages(state.result.messages, *result.messages);
|
||||||
|
|
||||||
|
print("OUTPUT: \n\n%\n\n", file.output_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;
|
||||||
|
|||||||
@@ -499,14 +499,12 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
|
|||||||
// return error_token(lexer, tprint("Invalid token: %", s));
|
// return error_token(lexer, tprint("Invalid token: %", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lex :: (result : *Compile_Result) {
|
lex :: (result : *Compile_Result) {
|
||||||
if result.had_error {
|
if result.had_error {
|
||||||
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 +512,7 @@ lex :: (result : *Compile_Result) {
|
|||||||
token = scan_next_token(*lexer);
|
token = scan_next_token(*lexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1651,6 +1651,37 @@ type_check :: (checker : *Semantic_Checker, root : *AST_Node) {
|
|||||||
traverse(checker, root);
|
traverse(checker, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check :: (result : *Compile_Result) {
|
||||||
|
for *file : result.files {
|
||||||
|
checker : Semantic_Checker;
|
||||||
|
init_semantic_checker(*checker, file.ast_root, file.file.path);
|
||||||
|
check(*checker);
|
||||||
|
|
||||||
|
//@Incomplete: Copy over the result from the checker result
|
||||||
|
|
||||||
|
//@Note: Meh copy string...
|
||||||
|
file.vertex_entry_point = checker.result.vertex_entry_point;
|
||||||
|
file.pixel_entry_point = checker.result.pixel_entry_point;
|
||||||
|
|
||||||
|
file.constant_buffers.array = checker.result.constant_buffers.array;
|
||||||
|
file.constant_buffers.count = checker.result.constant_buffers.count;
|
||||||
|
file.scope_stack.allocator = checker.result.scope_stack.allocator;
|
||||||
|
file.scope_stack.arena = checker.result.scope_stack.arena;
|
||||||
|
|
||||||
|
file.scope_stack.stack.data = checker.result.scope_stack.stack.data;
|
||||||
|
file.scope_stack.stack.count = checker.result.scope_stack.stack.count;
|
||||||
|
|
||||||
|
file.type_var_arena = checker.result.type_var_arena;
|
||||||
|
file.type_var_allocator = checker.result.type_var_allocator;
|
||||||
|
file.type_variables.data = checker.result.type_variables.data;
|
||||||
|
file.type_variables.count = checker.result.type_variables.count;
|
||||||
|
|
||||||
|
file.property_name = copy_string(checker.result.property_name);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|||||||
6
Test.jai
6
Test.jai
@@ -407,10 +407,10 @@ run_codegen_test :: (path : string, output_type : Output_Type = 0) -> Result, Co
|
|||||||
return result, codegen_result;
|
return result, codegen_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compilation_Result {
|
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compile_Result {
|
||||||
compiler : Shader_Compiler;
|
compiler : Shader_Compiler;
|
||||||
result : Result;
|
result : Result;
|
||||||
compilation_result := compile_file(*compiler, path);
|
compilation_result := compile_file(*compiler, .[path]);
|
||||||
print("\n");
|
print("\n");
|
||||||
|
|
||||||
if compilation_result.had_error {
|
if compilation_result.had_error {
|
||||||
@@ -470,7 +470,7 @@ run_test :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
if stage_flags & .Compile {
|
if stage_flags & .Compile {
|
||||||
result = run_compile_test(file_path, output_type);
|
result, compilation_result := run_compile_test(file_path, output_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
module.jai
22
module.jai
@@ -145,7 +145,21 @@ Compiled_File :: struct {
|
|||||||
file : Input_File;
|
file : Input_File;
|
||||||
tokens : Token_Stream;
|
tokens : Token_Stream;
|
||||||
ast_root : *AST_Node;
|
ast_root : *AST_Node;
|
||||||
ast_nodes : [..]AST_Node;
|
ast_nodes : [..]AST_Node;
|
||||||
|
|
||||||
|
vertex_entry_point : *AST_Node;
|
||||||
|
pixel_entry_point : *AST_Node;
|
||||||
|
|
||||||
|
constant_buffers : Static_Array(Type_Variable_Handle, 16);
|
||||||
|
|
||||||
|
scope_stack : Scope_Stack;
|
||||||
|
type_variables : [..]Type_Variable;
|
||||||
|
type_var_arena : Arena;
|
||||||
|
type_var_allocator : Allocator;
|
||||||
|
|
||||||
|
property_name : string;
|
||||||
|
|
||||||
|
output_text : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
Compile_Result :: struct {
|
Compile_Result :: struct {
|
||||||
@@ -368,9 +382,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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user