aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-02-25 11:49:44 +0000
committergingerBill <bill@gingerbill.org>2018-02-25 11:49:44 +0000
commite14e2c3b4d460887056c68f3926f2b96f276777a (patch)
tree3a17aeb7cef0b569e7d7f7d0d5b45394a4a841f0 /src/ir.cpp
parentf96a8978212dabaf4f6a5267b8f098d356d1ffe2 (diff)
`-out` and generate executable in the current working directory
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 9613f7192..8622659e6 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -1655,7 +1655,7 @@ irValue *ir_find_or_generate_context_ptr(irProcedure *proc) {
proc->curr_block = proc->blocks[0];
defer (proc->curr_block = tmp_block);
-
+
irValue *c = ir_add_local_generated(proc, t_context);
array_add(&proc->context_stack, c);
ir_emit_store(proc, c, ir_emit_load(proc, proc->module->global_default_context));
@@ -7772,12 +7772,23 @@ bool ir_gen_init(irGen *s, Checker *c) {
// s->module.generate_debug_info = false;
String init_fullpath = c->parser->init_fullpath;
- // TODO(bill): generate appropriate output name
- int pos = cast(int)string_extension_position(init_fullpath);
- int dir_pos = cast(int)string_extension_position(init_fullpath);
- s->output_name = filename_from_path(init_fullpath);
- s->output_base = make_string(init_fullpath.text, pos);
- gbFileError err = gb_file_create(&s->output_file, gb_bprintf("%.*s.ll", LIT(s->output_base)));
+
+ if (build_context.out_filepath.len == 0) {
+ s->output_name = filename_from_path(init_fullpath);
+ s->output_base = s->output_name;
+ } else {
+ s->output_name = build_context.out_filepath;
+ isize pos = string_extension_position(s->output_name);
+ if (pos < 0) {
+ s->output_base = s->output_name;
+ } else {
+ s->output_base = substring(s->output_name, 0, pos);
+ }
+ }
+
+ gbString output_file_path = gb_string_make_length(heap_allocator(), s->output_base.text, s->output_base.len);
+ output_file_path = gb_string_appendc(output_file_path, ".ll");
+ gbFileError err = gb_file_create(&s->output_file, output_file_path);
if (err != gbFileError_None) {
return false;
}