Properly output compiled file instead of intermediate results in semcheck
This commit is contained in:
296
Test.jai
296
Test.jai
@@ -119,65 +119,6 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
|
||||
return final_path;
|
||||
}
|
||||
|
||||
// run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
|
||||
// ok := read_input_from_file(lexer, file_path);
|
||||
|
||||
// result_data : Result;
|
||||
// result_data.path = file_path;
|
||||
// result_data.stage = .Lexer;
|
||||
|
||||
// if !ok {
|
||||
// result_data.type = .File_Read_Failed;
|
||||
// result_data.info_text = tprint("Unable to read file: %\n", file_path);
|
||||
|
||||
// return result_data;
|
||||
// } else {
|
||||
// result_text : string;
|
||||
// result := lex(lexer, *temp);
|
||||
|
||||
// if result.had_error {
|
||||
// result_data.type = .Failed;
|
||||
// result_text = report_messages(result.messages);
|
||||
// } else {
|
||||
// result_text = pretty_print_tokens(result.tokens, *temp);
|
||||
// }
|
||||
|
||||
// if output_type & .StdOut {
|
||||
// result_data.info_text = result_text;
|
||||
// result_data.type = .StdOut;
|
||||
// return result_data;
|
||||
// }
|
||||
|
||||
// golden_path := get_golden_path(file_path, .Lexer);
|
||||
// do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
// return result_data;
|
||||
// }
|
||||
// }
|
||||
|
||||
run_parser_test :: (file_path : string, output_type : Output_Type = 0) -> Result, *AST_Node {
|
||||
lexer : Lexer;
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
|
||||
ok := read_input_from_file(*lexer, file_path);
|
||||
if !ok {
|
||||
log_error("Unable to read file: %\n", file_path);
|
||||
result_data.type = .File_Read_Failed;
|
||||
result_data.stage = .Lexer;
|
||||
return result_data, null;
|
||||
}
|
||||
|
||||
result := lex(*lexer, *temp);
|
||||
if result.had_error {
|
||||
result_data.type = .Passed; //@Incomplete: Huh?
|
||||
return result_data, null;
|
||||
}
|
||||
|
||||
result_data =, root := run_parser_test(*lexer, output_type);
|
||||
|
||||
return result_data, root;
|
||||
}
|
||||
|
||||
do_golden_comparison :: (golden_path : string, comparison_text : string, result_data : *Result, output_type : Output_Type) {
|
||||
if output_type & .Golden {
|
||||
// Output the comparison file
|
||||
@@ -212,200 +153,49 @@ do_golden_comparison :: (golden_path : string, comparison_text : string, result_
|
||||
}
|
||||
}
|
||||
|
||||
run_parser_test :: (lexer : *Lexer, output_type : Output_Type = 0) -> Result, *AST_Node {
|
||||
parse_state : Parse_State;
|
||||
result_data : Result;
|
||||
result_data.path = lexer.path;
|
||||
result_data.stage = .Parser;
|
||||
init_parse_state(*parse_state, lexer.result.tokens, lexer.path);
|
||||
run_codegen_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
add_file(result, file_path);
|
||||
|
||||
result := parse(*parse_state);
|
||||
result_node : *AST_Node;
|
||||
result_text : string;
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages,, temp);
|
||||
} else {
|
||||
result_text = pretty_print_ast(parse_state.result.root, *temp);
|
||||
result_node = parse_state.result.root;
|
||||
}
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data, result_node;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(parse_state.path, .Parser);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data, result_node;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, output_type : Output_Type = 0) -> Result, Semantic_Check_Result {
|
||||
lexer : Lexer;
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
|
||||
ok := read_input_from_file(*lexer, file_path);
|
||||
if !ok {
|
||||
log_error("Unable to read file: %\n", file_path);
|
||||
result_data.type = .File_Read_Failed;
|
||||
result_data.stage = .Lexer;
|
||||
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
lex_result := lex(*lexer, *temp);
|
||||
if lex_result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.stage = .Lexer;
|
||||
result_data.info_text = report_messages(lex_result.messages);
|
||||
lex(result);
|
||||
parse(result);
|
||||
check(result);
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.type = .StdOut;
|
||||
return result_data, .{};
|
||||
}
|
||||
golden_path := get_golden_path(file_path, .Semantic_Analysis);
|
||||
do_golden_comparison(golden_path, result_data.info_text, *result_data, output_type);
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
parse_state : Parse_State;
|
||||
result_data.stage = .Parser;
|
||||
init_parse_state(*parse_state, lex_result.tokens, lexer.path);
|
||||
|
||||
parse_result := parse(*parse_state);
|
||||
if parse_result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.info_text = report_messages(parse_result.messages);
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.type = .StdOut;
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(file_path, .Semantic_Analysis);
|
||||
do_golden_comparison(golden_path, result_data.info_text, *result_data, output_type);
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
result, check_result := run_semantic_analysis_test(file_path, parse_state.result.root, output_type);
|
||||
return result, check_result;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, root : *AST_Node, output_type : Output_Type = 0) -> Result, Semantic_Check_Result {
|
||||
result_data : Result;
|
||||
|
||||
result_data.path = file_path;
|
||||
result_data.stage = .Semantic_Analysis;
|
||||
checker : Semantic_Checker;
|
||||
init_semantic_checker(*checker, root, file_path);
|
||||
result_text : string;
|
||||
|
||||
result := check(*checker);
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(checker.result.messages);
|
||||
} else {
|
||||
result_text = pretty_print_symbol_table(*checker, temp);
|
||||
return result_data;
|
||||
}
|
||||
result_data = run_codegen_test(result, output_type);
|
||||
|
||||
return result_data;
|
||||
}
|
||||
|
||||
run_codegen_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
result_data.path = result.files[0].file.path;
|
||||
result_text : string;
|
||||
|
||||
codegen(result);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages);
|
||||
return result_data;
|
||||
}
|
||||
|
||||
result_text = result.files[0].codegen_result_text;
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data, .{};
|
||||
return result_data;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(checker.path, .Semantic_Analysis);
|
||||
golden_path := get_golden_path(result.files[0].file.path, .Codegen);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data, result;
|
||||
}
|
||||
|
||||
run_codegen_test :: (path : string, root : *AST_Node, check_result : Semantic_Check_Result, output_type : Output_Type = 0) -> Result, Codegen_Result {
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = path;
|
||||
result_data.stage = .Codegen;
|
||||
|
||||
state : Codegen_State;
|
||||
init_codegen_state(*state, root, check_result, .HLSL);
|
||||
|
||||
result_text : string;
|
||||
|
||||
result := codegen(*state);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.info_text = report_messages(result.messages);
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
result_text = result.result_text;
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data, result;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(path, .Codegen);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data, result;
|
||||
}
|
||||
|
||||
run_codegen_test :: (path : string, root : *AST_Node, output_type : Output_Type = 0) -> Result, Codegen_Result {
|
||||
checker : Semantic_Checker;
|
||||
init_semantic_checker(*checker, root, path);
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = path;
|
||||
result_data.stage = .Semantic_Analysis;
|
||||
|
||||
check_result := check(*checker);
|
||||
if check_result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.info_text = report_messages(check_result.messages);
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
result, codegen_result := run_codegen_test(path, root, check_result, output_type);
|
||||
return result, codegen_result;
|
||||
}
|
||||
|
||||
run_codegen_test :: (path : string, output_type : Output_Type = 0) -> Result, Codegen_Result {
|
||||
lexer : Lexer;
|
||||
result_data : Result;
|
||||
result_data.path = path;
|
||||
|
||||
ok := read_input_from_file(*lexer, path);
|
||||
if !ok {
|
||||
log_error("Unable to read file: %\n", path);
|
||||
result_data.type = .File_Read_Failed;
|
||||
result_data.stage = .Lexer;
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
lex_result := lex(*lexer, *temp);
|
||||
if lex_result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.stage = .Lexer;
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
parse_state : Parse_State;
|
||||
result_data.stage = .Parser;
|
||||
init_parse_state(*parse_state, lex_result.tokens, lexer.path);
|
||||
|
||||
parse_result := parse(*parse_state);
|
||||
if parse_result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_data.info_text = pretty_print_ast(parse_result.root, *temp);
|
||||
return result_data, .{};
|
||||
}
|
||||
|
||||
result, codegen_result := run_codegen_test(path, parse_result.root, output_type);
|
||||
return result, codegen_result;
|
||||
return result_data;
|
||||
}
|
||||
|
||||
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compile_Result {
|
||||
@@ -524,7 +314,7 @@ run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, out
|
||||
lex(result);
|
||||
parse(result);
|
||||
if result.had_error {
|
||||
result_data.type = .Passed;
|
||||
result_data.type = .Failed;
|
||||
return result_data;
|
||||
}
|
||||
|
||||
@@ -554,34 +344,32 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R
|
||||
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
|
||||
result = run_parser_test(*compile_result, output_type);
|
||||
} else {
|
||||
result = run_parser_test(file_path, output_type);
|
||||
result = run_parser_test(file_path, *compile_result, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
if stage_flags & .Semantic_Analysis {
|
||||
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
result = run_semantic_analysis_test(file_path, *compile_result, output_type);
|
||||
result = run_semantic_analysis_test(*compile_result, output_type);
|
||||
} else {
|
||||
result = run_semantic_analysis_test(file_path, *compile_result, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
// if stage_flags & .Codegen {
|
||||
// if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
// result = run_codegen_test(file_path, *compile_result, output_type);
|
||||
// } else if compile_result.ast_root {
|
||||
// result = run_codegen_test(file_path, *compile_result, output_type);
|
||||
// } else {
|
||||
// result = run_codegen_test(file_path, *compile_result, output_type);
|
||||
// }
|
||||
// record_result(results, result);
|
||||
// }
|
||||
if stage_flags & .Codegen {
|
||||
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
result = run_codegen_test(*compile_result, output_type);
|
||||
} else {
|
||||
result = run_codegen_test(file_path, *compile_result, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
// if stage_flags & .Compile {
|
||||
// result = run_compile_test(file_path, output_type);
|
||||
// }
|
||||
if stage_flags & .Compile {
|
||||
result = run_compile_test(file_path, output_type);
|
||||
}
|
||||
}
|
||||
|
||||
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) {
|
||||
|
||||
Reference in New Issue
Block a user