Compile with odin.exe and no run.bat

This is win32 only and requires CreateProcessA
This commit is contained in:
gingerBill
2016-08-16 12:33:11 +01:00
parent 6f7f82d877
commit 5da6b74567
9 changed files with 320 additions and 57 deletions
+1 -1
View File
@@ -561,7 +561,7 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
ssa_fprintf(f, "\n");
} break;
case ssaInstr_CopyMemory: {
case ssaInstr_MemCopy: {
ssa_fprintf(f, "call void @llvm.memmove.p0i8.p0i8.");
ssa_print_type(f, m->sizes, t_int);
ssa_fprintf(f, "(i8* ");
+5 -5
View File
@@ -70,7 +70,7 @@ struct ssaProcedure {
SSA_INSTR_KIND(Unreachable), \
SSA_INSTR_KIND(BinaryOp), \
SSA_INSTR_KIND(Call), \
SSA_INSTR_KIND(CopyMemory), \
SSA_INSTR_KIND(MemCopy), \
SSA_INSTR_KIND(ExtractElement), \
SSA_INSTR_KIND(InsertElement), \
SSA_INSTR_KIND(ShuffleVector), \
@@ -330,8 +330,8 @@ Type *ssa_instr_type(ssaInstr *instr) {
return pt;
}
return NULL;
}
case ssaInstr_CopyMemory:
} break;
case ssaInstr_MemCopy:
return t_int;
case ssaInstr_ExtractElement: {
@@ -592,7 +592,7 @@ ssaValue *ssa_make_instr_call(ssaProcedure *p, ssaValue *value, ssaValue **args,
}
ssaValue *ssa_make_instr_copy_memory(ssaProcedure *p, ssaValue *dst, ssaValue *src, ssaValue *len, i32 align, b32 is_volatile) {
ssaValue *v = ssa_alloc_instr(p->module->allocator, ssaInstr_CopyMemory);
ssaValue *v = ssa_alloc_instr(p->module->allocator, ssaInstr_MemCopy);
v->instr.copy_memory.dst = dst;
v->instr.copy_memory.src = src;
v->instr.copy_memory.len = len;
@@ -893,7 +893,7 @@ void ssa_end_procedure_body(ssaProcedure *proc) {
case ssaInstr_Br:
case ssaInstr_Ret:
case ssaInstr_Unreachable:
case ssaInstr_CopyMemory:
case ssaInstr_MemCopy:
case ssaInstr_StartupRuntime:
continue;
case ssaInstr_Call:
+1 -1
View File
@@ -1,4 +1,4 @@
#define GB_NO_WINDOWS_H
// #define GB_NO_WINDOWS_H
#define GB_IMPLEMENTATION
#include "gb/gb.h"
-3
View File
@@ -2964,8 +2964,6 @@ extern "C" {
DWORD dwFlags;
} MONITORINFO;
#define INFINITE 0xffffffffl
#define INVALID_HANDLE_VALUE ((void *)(intptr)(-1))
@@ -2985,7 +2983,6 @@ extern "C" {
GB_DLL_IMPORT void WINAPI RaiseException (DWORD, DWORD, DWORD, ULONG_PTR const *);
GB_DLL_IMPORT BOOL WINAPI GetLogicalProcessorInformation(SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buffer, DWORD *return_length);
GB_DLL_IMPORT DWORD_PTR WINAPI SetThreadAffinityMask(HANDLE thread, DWORD_PTR check_mask);
GB_DLL_IMPORT HANDLE WINAPI GetCurrentThread(void);
+66 -22
View File
@@ -6,46 +6,90 @@
#include "checker/checker.cpp"
#include "codegen/codegen.cpp"
void win32_exec_command_line_app(char *fmt, ...) {
STARTUPINFOA start_info = {gb_size_of(STARTUPINFOA)};
PROCESS_INFORMATION pi = {};
start_info.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
start_info.wShowWindow = SW_SHOW;
start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
start_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
char cmd_line[2048] = {};
va_list va;
va_start(va, fmt);
gb_snprintf_va(cmd_line, gb_size_of(cmd_line), fmt, va);
va_end(va);
if (CreateProcessA(NULL, cmd_line,
NULL, NULL, true, 0, NULL, NULL,
&start_info, &pi)) {
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
// NOTE(bill): failed to create process
}
}
int main(int argc, char **argv) {
if (argc < 2) {
gb_printf_err("Please specify a .odin file\n");
return 1;
}
int success = 1;
init_universal_scope();
for (int arg_index = 1; arg_index < argc; arg_index++) {
char *arg = argv[arg_index];
char *init_filename = arg;
Parser parser = {0};
char *init_filename = argv[1];
b32 run_output = false;
if (gb_strncmp(argv[1], "run", 3) == 0) {
run_output = true;
init_filename = argv[2];
}
Parser parser = {0};
if (init_parser(&parser)) {
defer (destroy_parser(&parser));
if (parse_files(&parser, init_filename) == ParseFile_None) {
// print_ast(parser.files[0].declarations, 0);
if (init_parser(&parser)) {
defer (destroy_parser(&parser));
Checker checker = {};
if (parse_files(&parser, init_filename) == ParseFile_None) {
// print_ast(parser.files[0].decls, 0);
init_checker(&checker, &parser);
defer (destroy_checker(&checker));
Checker checker = {};
check_parsed_files(&checker);
ssaGen ssa = {};
if (ssa_gen_init(&ssa, &checker)) {
defer (ssa_gen_destroy(&ssa));
init_checker(&checker, &parser);
defer (destroy_checker(&checker));
ssa_gen_code(&ssa);
check_parsed_files(&checker);
ssaGen ssa = {};
if (ssa_gen_init(&ssa, &checker)) {
defer (ssa_gen_destroy(&ssa));
success = 0;
} else {
gb_printf("Failed to build: %s\n", init_filename);
ssa_gen_code(&ssa);
char const *output_name = ssa.output_file.filename;
isize base_name_len = gb_path_extension(output_name)-1 - output_name;
win32_exec_command_line_app(
"opt -mem2reg %s -o %.*s.bc",
output_name, cast(int)base_name_len, output_name);
win32_exec_command_line_app(
"clang %.*s.bc -o %.*s.exe -Wno-override-module "
"-lkernel32.lib -luser32.lib",
cast(int)base_name_len, output_name,
cast(int)base_name_len, output_name);
if (run_output) {
win32_exec_command_line_app("%.*s.exe", cast(int)base_name_len, output_name);
}
return 0;
}
}
}
return success;
return 1;
}