Unify argument builder API
All checks were successful
All checks were successful
This commit is contained in:
parent
9138454892
commit
d327813595
@ -183,6 +183,9 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
|
|
||||||
if (is_compiler)
|
if (is_compiler)
|
||||||
{
|
{
|
||||||
|
// ArgBuilder builder = {};
|
||||||
|
// auto arguments = builder.flush();
|
||||||
|
// os_execute(arena, arguments, environment, {});
|
||||||
}
|
}
|
||||||
else if (base_name.equal(string_literal("c_abi")))
|
else if (base_name.equal(string_literal("c_abi")))
|
||||||
{
|
{
|
||||||
@ -327,7 +330,7 @@ global_variable String names[] =
|
|||||||
string_literal("basic_struct_passing"),
|
string_literal("basic_struct_passing"),
|
||||||
};
|
};
|
||||||
|
|
||||||
void entry_point(Slice<const char*> arguments, Slice<char* const> envp)
|
void entry_point(Slice<char* const> arguments, Slice<char* const> envp)
|
||||||
{
|
{
|
||||||
environment = envp;
|
environment = envp;
|
||||||
Arena* arena = arena_initialize_default(16 * mb);
|
Arena* arena = arena_initialize_default(16 * mb);
|
||||||
@ -457,7 +460,7 @@ void entry_point(Slice<const char*> arguments, Slice<char* const> envp)
|
|||||||
(char*)executable_path.pointer,
|
(char*)executable_path.pointer,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
Slice<const char* const> arg_slice = array_to_slice(arguments);
|
Slice<char* const> arg_slice = array_to_slice(arguments);
|
||||||
arg_slice.length -= 1;
|
arg_slice.length -= 1;
|
||||||
auto execution = os_execute(arena, arg_slice, environment, {});
|
auto execution = os_execute(arena, arg_slice, environment, {});
|
||||||
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
||||||
@ -491,16 +494,16 @@ void entry_point(Slice<const char*> arguments, Slice<char* const> envp)
|
|||||||
bool has_debug_info = true;
|
bool has_debug_info = true;
|
||||||
String relative_file_path_parts[] = { string_literal("tests/"), name, string_literal(".bbb") };
|
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 relative_file_path = arena_join_string(arena, array_to_slice(relative_file_path_parts));
|
||||||
const char* const arguments[] =
|
char* const arguments[] =
|
||||||
{
|
{
|
||||||
(char*)compiler.pointer,
|
(char*)compiler.pointer,
|
||||||
"compile",
|
(char*)"compile",
|
||||||
(char*)relative_file_path.pointer,
|
(char*)relative_file_path.pointer,
|
||||||
(char*)build_mode_to_string(build_mode).pointer,
|
(char*)build_mode_to_string(build_mode).pointer,
|
||||||
has_debug_info ? "true" : "false",
|
(char*)(has_debug_info ? "true" : "false"),
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
Slice<const char* const> arg_slice = array_to_slice(arguments);
|
Slice<char* const> arg_slice = array_to_slice(arguments);
|
||||||
arg_slice.length -= 1;
|
arg_slice.length -= 1;
|
||||||
auto execution = os_execute(arena, arg_slice, environment, {});
|
auto execution = os_execute(arena, arg_slice, environment, {});
|
||||||
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
auto success = execution.termination_kind == TerminationKind::exit && execution.termination_code == 0;
|
||||||
|
@ -1840,6 +1840,25 @@ fn Type* get_enum_array_type(Module* module, Type* enum_type, Type* element_type
|
|||||||
return enum_array_type;
|
return enum_array_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ArgBuilder
|
||||||
|
{
|
||||||
|
char* args[128];
|
||||||
|
u32 argument_count = 0;
|
||||||
|
|
||||||
|
void add(const char* arg)
|
||||||
|
{
|
||||||
|
assert(argument_count < array_length(args));
|
||||||
|
args[argument_count] = (char*)arg;
|
||||||
|
argument_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Slice<char* const> flush()
|
||||||
|
{
|
||||||
|
assert(argument_count < array_length(args));
|
||||||
|
args[argument_count] = 0;
|
||||||
|
return { args, argument_count };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void parse(Module* module);
|
void parse(Module* module);
|
||||||
void emit(Module* module);
|
void emit(Module* module);
|
||||||
|
@ -8316,27 +8316,7 @@ fn BBLLVMCodeGenerationPipelineResult generate_object(LLVMModuleRef module, LLVM
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ArgBuilder
|
fn void link(Module* module)
|
||||||
{
|
|
||||||
const char* args[128];
|
|
||||||
u32 argument_count = 0;
|
|
||||||
|
|
||||||
void add(const char* arg)
|
|
||||||
{
|
|
||||||
assert(argument_count < array_length(args));
|
|
||||||
args[argument_count] = arg;
|
|
||||||
argument_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Slice<const char*> flush()
|
|
||||||
{
|
|
||||||
assert(argument_count < array_length(args));
|
|
||||||
args[argument_count] = 0;
|
|
||||||
return { args, argument_count };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void link(Module* module)
|
|
||||||
{
|
{
|
||||||
Arena* arena = module->arena;
|
Arena* arena = module->arena;
|
||||||
ArgBuilder builder;
|
ArgBuilder builder;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <lib.hpp>
|
#include <lib.hpp>
|
||||||
void entry_point(Slice<const char*> arguments, Slice<char* const> environment);
|
void entry_point(Slice<char* const> arguments, Slice<char* const> environment);
|
||||||
int main(int argc, const char* argv[], char* const envp[])
|
int main(int argc, const char* argv[], char* const envp[])
|
||||||
{
|
{
|
||||||
auto* envp_end = envp;
|
auto* envp_end = envp;
|
||||||
@ -8,6 +8,6 @@ int main(int argc, const char* argv[], char* const envp[])
|
|||||||
envp_end += 1;
|
envp_end += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_point({argv, (u64)argc}, {envp, (u64)(envp_end - envp)});
|
entry_point(Slice<char* const>{(char* const*)argv, (u64)argc}, {envp, (u64)(envp_end - envp)});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ fn bool IFSIGNALED(u32 s)
|
|||||||
{
|
{
|
||||||
return (s & 0xffff) - 1 < 0xff;
|
return (s & 0xffff) - 1 < 0xff;
|
||||||
}
|
}
|
||||||
Execution os_execute(Arena* arena, Slice<const char* const> arguments, Slice<char* const> environment, ExecuteOptions options)
|
Execution os_execute(Arena* arena, Slice<char* const> arguments, Slice<char* const> environment, ExecuteOptions options)
|
||||||
{
|
{
|
||||||
unused(arena);
|
unused(arena);
|
||||||
assert(arguments.pointer[arguments.length] == 0);
|
assert(arguments.pointer[arguments.length] == 0);
|
||||||
|
@ -715,4 +715,4 @@ struct Execution
|
|||||||
u32 termination_code;
|
u32 termination_code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Execution os_execute(Arena* arena, Slice<const char* const> arguments, Slice<char* const> environment, ExecuteOptions options);
|
Execution os_execute(Arena* arena, Slice<char* const> arguments, Slice<char* const> environment, ExecuteOptions options);
|
||||||
|
@ -640,6 +640,6 @@ extern "C" void llvm_module_set_target(LLVMModuleRef m, LLVMTargetMachineRef tm)
|
|||||||
extern "C" void llvm_module_run_optimization_pipeline(LLVMModuleRef module, LLVMTargetMachineRef target_machine, BBLLVMOptimizationPipelineOptions options);
|
extern "C" void llvm_module_run_optimization_pipeline(LLVMModuleRef module, LLVMTargetMachineRef target_machine, BBLLVMOptimizationPipelineOptions options);
|
||||||
extern "C" BBLLVMCodeGenerationPipelineResult llvm_module_run_code_generation_pipeline(LLVMModuleRef m, LLVMTargetMachineRef tm, const BBLLVMCodeGenerationPipelineOptions* options);
|
extern "C" BBLLVMCodeGenerationPipelineResult llvm_module_run_code_generation_pipeline(LLVMModuleRef m, LLVMTargetMachineRef tm, const BBLLVMCodeGenerationPipelineOptions* options);
|
||||||
|
|
||||||
#define lld_api_args() const char** argument_pointer, u64 argument_count, bool exit_early, bool disable_output
|
#define lld_api_args() char* const* argument_pointer, u64 argument_count, bool exit_early, bool disable_output
|
||||||
#define lld_api_function_decl(link_name) LLDResult lld_ ## link_name ## _link(lld_api_args())
|
#define lld_api_function_decl(link_name) LLDResult lld_ ## link_name ## _link(lld_api_args())
|
||||||
extern "C" lld_api_function_decl(elf);
|
extern "C" lld_api_function_decl(elf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user