Browse Source

Replace `gb_exit(1)` with `exit_with_errors()` where appropriate

gingerBill 1 year ago
parent
commit
433109ff52
6 changed files with 17 additions and 13 deletions
  1. 2 2
      src/checker.cpp
  2. 1 1
      src/docs_writer.cpp
  3. 4 0
      src/error.cpp
  4. 7 7
      src/llvm_backend.cpp
  5. 1 1
      src/main.cpp
  6. 2 2
      src/parser.cpp

+ 2 - 2
src/checker.cpp

@@ -1204,7 +1204,7 @@ gb_internal void init_universal(void) {
 	}
 
 	if (defined_values_double_declaration) {
-		gb_exit(1);
+		exit_with_errors();
 	}
 
 
@@ -4504,7 +4504,7 @@ gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMap<AstPac
 		if (found == nullptr) {
 			Token token = ast_token(decl);
 			error(token, "Unable to find package: %.*s", LIT(path));
-			gb_exit(1);
+			exit_with_errors();
 		}
 		AstPackage *pkg = *found;
 		GB_ASSERT(pkg->scope != nullptr);

+ 1 - 1
src/docs_writer.cpp

@@ -1170,7 +1170,7 @@ gb_internal void odin_doc_write_to_file(OdinDocWriter *w, char const *filename)
 	gbFileError err = gb_file_open_mode(&f, gbFileMode_Write, filename);
 	if (err != gbFileError_None) {
 		gb_printf_err("Failed to write .odin-doc to: %s\n", filename);
-		gb_exit(1);
+		exit_with_errors();
 		return;
 	}
 	defer (gb_file_close(&f));

+ 4 - 0
src/error.cpp

@@ -613,6 +613,10 @@ gb_internal void compiler_error(char const *fmt, ...) {
 }
 
 
+gb_internal void exit_with_errors(void) {
+	print_all_errors();
+	gb_exit(1);
+}
 
 
 

+ 7 - 7
src/llvm_backend.cpp

@@ -1350,7 +1350,7 @@ gb_internal WORKER_TASK_PROC(lb_llvm_emit_worker_proc) {
 
 	if (LLVMTargetMachineEmitToFile(wd->target_machine, wd->m->mod, cast(char *)wd->filepath_obj.text, wd->code_gen_file_type, &llvm_error)) {
 		gb_printf_err("LLVM Error: %s\n", llvm_error);
-		gb_exit(1);
+		exit_with_errors();
 	}
 	debugf("Generated File: %.*s\n", LIT(wd->filepath_obj));
 	return 0;
@@ -1919,7 +1919,7 @@ verify
 				gb_printf_err("LLVM Error: %s\n", llvm_error);
 			}
 		}
-		gb_exit(1);
+		exit_with_errors();
 		return 1;
 	}
 #endif
@@ -2104,11 +2104,11 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_verification_worker_proc) {
 			String filepath_ll = lb_filepath_ll_for_module(m);
 			if (LLVMPrintModuleToFile(m->mod, cast(char const *)filepath_ll.text, &llvm_error)) {
 				gb_printf_err("LLVM Error: %s\n", llvm_error);
-				gb_exit(1);
+				exit_with_errors();
 				return false;
 			}
 		}
-		gb_exit(1);
+		exit_with_errors();
 		return 1;
 	}
 	return 0;
@@ -2193,7 +2193,7 @@ gb_internal bool lb_llvm_object_generation(lbGenerator *gen, bool do_threading)
 
 			if (LLVMTargetMachineEmitToFile(m->target_machine, m->mod, cast(char *)filepath_obj.text, code_gen_file_type, &llvm_error)) {
 				gb_printf_err("LLVM Error: %s\n", llvm_error);
-				gb_exit(1);
+				exit_with_errors();
 				return false;
 			}
 			debugf("Generated File: %.*s\n", LIT(filepath_obj));
@@ -2393,7 +2393,7 @@ gb_internal void lb_generate_procedure(lbModule *m, lbProcedure *p) {
 			gb_printf_err("LLVM Error: %s\n", llvm_error);
 		}
 		LLVMVerifyFunction(p->value, LLVMPrintMessageAction);
-		gb_exit(1);
+		exit_with_errors();
 	}
 }
 
@@ -2962,7 +2962,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
 			String filepath_ll = lb_filepath_ll_for_module(m);
 			if (LLVMPrintModuleToFile(m->mod, cast(char const *)filepath_ll.text, &llvm_error)) {
 				gb_printf_err("LLVM Error: %s\n", llvm_error);
-				gb_exit(1);
+				exit_with_errors();
 				return false;
 			}
 			array_add(&gen->output_temp_paths, filepath_ll);

+ 1 - 1
src/main.cpp

@@ -1404,7 +1404,7 @@ gb_internal void timings_export_all(Timings *t, Checker *c, bool timings_are_fin
 	gbFileError err = gb_file_open_mode(&f, gbFileMode_Write, fileName);
 	if (err != gbFileError_None) {
 		gb_printf_err("Failed to export timings to: %s\n", fileName);
-		gb_exit(1);
+		exit_with_errors();
 		return;
 	} else {
 		gb_printf("\nExporting timings to '%s'... ", fileName);

+ 2 - 2
src/parser.cpp

@@ -1484,7 +1484,7 @@ gb_internal Token expect_token(AstFile *f, TokenKind kind) {
 		String p = token_to_string(prev);
 		syntax_error(f->curr_token, "Expected '%.*s', got '%.*s'", LIT(c), LIT(p));
 		if (prev.kind == Token_EOF) {
-			gb_exit(1);
+			exit_with_errors();
 		}
 	}
 
@@ -6177,7 +6177,7 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe
 		if (err == ParseFile_EmptyFile) {
 			if (fi.fullpath == p->init_fullpath) {
 				syntax_error(pos, "Initial file is empty - %.*s\n", LIT(p->init_fullpath));
-				gb_exit(1);
+				exit_with_errors();
 			}
 		} else {
 			switch (err) {