wip
This commit is contained in:
parent
5e8a08d5be
commit
fa3a9f5f32
101
src/compiler.cpp
101
src/compiler.cpp
@ -163,22 +163,39 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
|
|
||||||
auto is_compiler = relative_file_path.equal(string_literal("src/compiler.bbb"));
|
auto is_compiler = relative_file_path.equal(string_literal("src/compiler.bbb"));
|
||||||
|
|
||||||
String output_path_dir_parts[] = {
|
make_directory(base_cache_dir);
|
||||||
|
|
||||||
|
String cpu_dir_parts[] = {
|
||||||
string_literal(base_cache_dir),
|
string_literal(base_cache_dir),
|
||||||
is_compiler ? string_literal("/compiler/") : string_literal("/"),
|
string_literal("/"),
|
||||||
|
options.host_cpu_model ? string_literal("native") : string_literal("baseline"),
|
||||||
|
};
|
||||||
|
|
||||||
|
auto cpu_dir = arena_join_string(arena, array_to_slice(cpu_dir_parts));
|
||||||
|
|
||||||
|
make_directory(cstr(cpu_dir));
|
||||||
|
|
||||||
|
auto base_dir = cpu_dir;
|
||||||
|
|
||||||
|
if (is_compiler)
|
||||||
|
{
|
||||||
|
String compiler_dir_parts[] = {
|
||||||
|
base_dir,
|
||||||
|
is_compiler ? string_literal("/compiler/") : string_literal("/"),
|
||||||
|
};
|
||||||
|
base_dir = arena_join_string(arena, array_to_slice(compiler_dir_parts));
|
||||||
|
make_directory(cstr(base_dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
String output_path_dir_parts[] = {
|
||||||
|
base_dir,
|
||||||
|
string_literal("/"),
|
||||||
build_mode_to_string(options.build_mode),
|
build_mode_to_string(options.build_mode),
|
||||||
string_literal("_"),
|
string_literal("_"),
|
||||||
options.has_debug_info ? string_literal("di") : string_literal("nodi"),
|
options.has_debug_info ? string_literal("di") : string_literal("nodi"),
|
||||||
};
|
};
|
||||||
auto output_path_dir = arena_join_string(arena, array_to_slice(output_path_dir_parts));
|
auto output_path_dir = arena_join_string(arena, array_to_slice(output_path_dir_parts));
|
||||||
|
|
||||||
make_directory(base_cache_dir);
|
|
||||||
|
|
||||||
if (is_compiler)
|
|
||||||
{
|
|
||||||
make_directory(base_cache_dir "/compiler");
|
|
||||||
}
|
|
||||||
|
|
||||||
make_directory(cstr(output_path_dir));
|
make_directory(cstr(output_path_dir));
|
||||||
|
|
||||||
String output_path_base_parts[] = {
|
String output_path_base_parts[] = {
|
||||||
@ -341,6 +358,7 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
.target = {
|
.target = {
|
||||||
.cpu = CPUArchitecture::x86_64,
|
.cpu = CPUArchitecture::x86_64,
|
||||||
.os = OperatingSystem::linux_,
|
.os = OperatingSystem::linux_,
|
||||||
|
.host_cpu_model = options.host_cpu_model,
|
||||||
},
|
},
|
||||||
.build_mode = options.build_mode,
|
.build_mode = options.build_mode,
|
||||||
.has_debug_info = options.has_debug_info,
|
.has_debug_info = options.has_debug_info,
|
||||||
@ -583,43 +601,48 @@ void entry_point(Slice<char* const> arguments, Slice<char* const> envp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool has_debug_info_array[] = {true, false};
|
bool has_debug_info_array[] = {true, false};
|
||||||
|
bool is_host_cpu_model_array[] = {true, false};
|
||||||
|
|
||||||
for (auto name: names)
|
for (auto name: names)
|
||||||
{
|
{
|
||||||
for (BuildMode build_mode = BuildMode::debug_none; build_mode < BuildMode::count; build_mode = (BuildMode)((backing_type(BuildMode))build_mode + 1))
|
for (auto is_host_cpu_model : is_host_cpu_model_array)
|
||||||
{
|
{
|
||||||
for (bool has_debug_info : has_debug_info_array)
|
for (BuildMode build_mode = BuildMode::debug_none; build_mode < BuildMode::count; build_mode = (BuildMode)((backing_type(BuildMode))build_mode + 1))
|
||||||
{
|
{
|
||||||
auto position = arena->position;
|
for (bool has_debug_info : has_debug_info_array)
|
||||||
|
|
||||||
String relative_file_path_parts[] = { string_literal("tests/"), name, string_literal(".bbb") };
|
|
||||||
auto relative_file_path = arena_join_string(arena, array_to_slice(relative_file_path_parts));
|
|
||||||
|
|
||||||
auto executable_path = compile_file(arena, {
|
|
||||||
.relative_file_path = relative_file_path,
|
|
||||||
.build_mode = build_mode,
|
|
||||||
.has_debug_info = has_debug_info,
|
|
||||||
.silent = true,
|
|
||||||
});
|
|
||||||
|
|
||||||
char* const arguments[] =
|
|
||||||
{
|
{
|
||||||
(char*)executable_path.pointer,
|
auto position = arena->position;
|
||||||
0,
|
|
||||||
};
|
String relative_file_path_parts[] = { string_literal("tests/"), name, string_literal(".bbb") };
|
||||||
Slice<char* const> arg_slice = array_to_slice(arguments);
|
auto relative_file_path = arena_join_string(arena, array_to_slice(relative_file_path_parts));
|
||||||
arg_slice.length -= 1;
|
|
||||||
auto execution = os_execute(arena, arg_slice, environment, {});
|
auto executable_path = compile_file(arena, {
|
||||||
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
.relative_file_path = relative_file_path,
|
||||||
if (!success)
|
.build_mode = build_mode,
|
||||||
{
|
.has_debug_info = has_debug_info,
|
||||||
print(string_literal("Test failed: "));
|
.host_cpu_model = is_host_cpu_model,
|
||||||
print(executable_path);
|
.silent = true,
|
||||||
print(string_literal("\n"));
|
});
|
||||||
bb_fail();
|
|
||||||
|
char* const arguments[] =
|
||||||
|
{
|
||||||
|
(char*)executable_path.pointer,
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
Slice<char* const> arg_slice = array_to_slice(arguments);
|
||||||
|
arg_slice.length -= 1;
|
||||||
|
auto execution = os_execute(arena, arg_slice, environment, {});
|
||||||
|
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
print(string_literal("Test failed: "));
|
||||||
|
print(executable_path);
|
||||||
|
print(string_literal("\n"));
|
||||||
|
bb_fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
arena_restore(arena, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
arena_restore(arena, position);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,6 +247,7 @@ struct Target
|
|||||||
{
|
{
|
||||||
CPUArchitecture cpu;
|
CPUArchitecture cpu;
|
||||||
OperatingSystem os;
|
OperatingSystem os;
|
||||||
|
bool host_cpu_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn Target target_get_native()
|
fn Target target_get_native()
|
||||||
@ -270,6 +271,7 @@ struct Compile
|
|||||||
String relative_file_path;
|
String relative_file_path;
|
||||||
BuildMode build_mode;
|
BuildMode build_mode;
|
||||||
bool has_debug_info;
|
bool has_debug_info;
|
||||||
|
bool host_cpu_model;
|
||||||
bool silent;
|
bool silent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -416,15 +416,23 @@ fn void llvm_initialize(Module* module)
|
|||||||
module->scope.llvm = di_compile_unit;
|
module->scope.llvm = di_compile_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* target_triple = {};
|
const char* target_triple = {};
|
||||||
char* cpu_model = {};
|
const char* cpu_model = {};
|
||||||
char* cpu_features = {};
|
const char* cpu_features = {};
|
||||||
|
|
||||||
if (target_compare(module->target, target_get_native()))
|
if (target_compare(module->target, target_get_native()))
|
||||||
{
|
{
|
||||||
target_triple = llvm_global.host_triple;
|
target_triple = llvm_global.host_triple;
|
||||||
cpu_model = llvm_global.host_cpu_model;
|
if (module->target.host_cpu_model)
|
||||||
cpu_features = llvm_global.host_cpu_features;
|
{
|
||||||
|
cpu_model = llvm_global.host_cpu_model;
|
||||||
|
cpu_features = llvm_global.host_cpu_features;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cpu_model = "baseline";
|
||||||
|
cpu_features = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user