authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-13 14:33:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-13 14:34:07-07:00
log3d8eb10897a86b2616c6a1aa843b7ebe4134ac51
treea45f80edca9f20943b1dd809c383eb3283ab0152
parent9ec892539ee19d39ed040ead628f04da2d11577e

fix incorrect debug info path to imports


4 files changed, 28 insertions(+), 24 deletions(-)

src/analyze.hpp+1
...@@ -152,6 +152,7 @@ struct CodeGen {...@@ -152,6 +152,7 @@ struct CodeGen {
152 bool insert_bootstrap_code;152 bool insert_bootstrap_code;
153 CodeGenBuildType build_type;153 CodeGenBuildType build_type;
154 LLVMTargetMachineRef target_machine;154 LLVMTargetMachineRef target_machine;
155 LLVMZigDIFile *dummy_di_file;
155 bool is_native_target;156 bool is_native_target;
156 Buf *root_source_dir;157 Buf *root_source_dir;
157 Buf *root_out_name;158 Buf *root_out_name;
src/codegen.cpp+25-22
...@@ -1316,9 +1316,8 @@ static void define_builtin_types(CodeGen *g) {...@@ -1316,9 +1316,8 @@ static void define_builtin_types(CodeGen *g) {
1316 g->builtin_types.entry_usize->di_type1316 g->builtin_types.entry_usize->di_type
1317 };1317 };
1318 LLVMZigDIScope *compile_unit_scope = LLVMZigCompileUnitToScope(g->compile_unit);1318 LLVMZigDIScope *compile_unit_scope = LLVMZigCompileUnitToScope(g->compile_unit);
1319 LLVMZigDIFile *difile = nullptr; // TODO make sure this ok
1320 entry->di_type = LLVMZigCreateDebugStructType(g->dbuilder, compile_unit_scope,1319 entry->di_type = LLVMZigCreateDebugStructType(g->dbuilder, compile_unit_scope,
1321 "string", difile, 0, entry->size_in_bits, entry->align_in_bits, 0,1320 "string", g->dummy_di_file, 0, entry->size_in_bits, entry->align_in_bits, 0,
1322 nullptr, di_element_types, element_count, 0, nullptr, "");1321 nullptr, di_element_types, element_count, 0, nullptr, "");
13231322
1324 g->type_table.put(&entry->name, entry);1323 g->type_table.put(&entry->name, entry);
...@@ -1386,21 +1385,20 @@ static void init(CodeGen *g, Buf *source_path) {...@@ -1386,21 +1385,20 @@ static void init(CodeGen *g, Buf *source_path) {
1386 buf_ptr(producer), is_optimized, flags, runtime_version,1385 buf_ptr(producer), is_optimized, flags, runtime_version,
1387 "", 0, !g->strip_debug_symbols);1386 "", 0, !g->strip_debug_symbols);
13881387
1388 // This is for debug stuff that doesn't have a real file.
1389 g->dummy_di_file = nullptr; //LLVMZigCreateFile(g->dbuilder, "", "");
1390
1389 define_builtin_types(g);1391 define_builtin_types(g);
13901392
1391}1393}
13921394
1393static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) {1395static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source_code) {
1394 int err;1396 int err;
1395 Buf full_path = BUF_INIT;1397 Buf *full_path = buf_alloc();
1396 os_path_join(g->root_source_dir, source_path, &full_path);1398 os_path_join(src_dirname, src_basename, full_path);
1397
1398 Buf dirname = BUF_INIT;
1399 Buf basename = BUF_INIT;
1400 os_path_split(&full_path, &dirname, &basename);
14011399
1402 if (g->verbose) {1400 if (g->verbose) {
1403 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(source_path));1401 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(full_path));
1404 fprintf(stderr, "----------------\n");1402 fprintf(stderr, "----------------\n");
1405 fprintf(stderr, "%s\n", buf_ptr(source_code));1403 fprintf(stderr, "%s\n", buf_ptr(source_code));
14061404
...@@ -1418,7 +1416,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou...@@ -1418,7 +1416,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
1418 err->line_end = -1;1416 err->line_end = -1;
1419 err->column_end = -1;1417 err->column_end = -1;
1420 err->msg = tokenization.err;1418 err->msg = tokenization.err;
1421 err->path = source_path;1419 err->path = full_path;
1422 err->source = source_code;1420 err->source = source_code;
1423 err->line_offsets = tokenization.line_offsets;1421 err->line_offsets = tokenization.line_offsets;
14241422
...@@ -1436,7 +1434,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou...@@ -1436,7 +1434,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
1436 ImportTableEntry *import_entry = allocate<ImportTableEntry>(1);1434 ImportTableEntry *import_entry = allocate<ImportTableEntry>(1);
1437 import_entry->source_code = source_code;1435 import_entry->source_code = source_code;
1438 import_entry->line_offsets = tokenization.line_offsets;1436 import_entry->line_offsets = tokenization.line_offsets;
1439 import_entry->path = source_path;1437 import_entry->path = full_path;
1440 import_entry->fn_table.init(32);1438 import_entry->fn_table.init(32);
1441 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);1439 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
1442 assert(import_entry->root);1440 assert(import_entry->root);
...@@ -1444,8 +1442,8 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou...@@ -1444,8 +1442,8 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
1444 ast_print(import_entry->root, 0);1442 ast_print(import_entry->root, 0);
1445 }1443 }
14461444
1447 import_entry->di_file = LLVMZigCreateFile(g->dbuilder, buf_ptr(&basename), buf_ptr(&dirname));1445 import_entry->di_file = LLVMZigCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
1448 g->import_table.put(source_path, import_entry);1446 g->import_table.put(full_path, import_entry);
14491447
14501448
1451 assert(import_entry->root->type == NodeTypeRoot);1449 assert(import_entry->root->type == NodeTypeRoot);
...@@ -1473,7 +1471,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou...@@ -1473,7 +1471,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
1473 goto done_looking_at_imports;1471 goto done_looking_at_imports;
1474 }1472 }
1475 }1473 }
1476 codegen_add_code(g, &top_level_decl->data.use.path, import_code);1474 codegen_add_code(g, search_path, &top_level_decl->data.use.path, import_code);
1477 found_it = true;1475 found_it = true;
1478 break;1476 break;
1479 }1477 }
...@@ -1500,20 +1498,25 @@ done_looking_at_imports:...@@ -1500,20 +1498,25 @@ done_looking_at_imports:
1500 return import_entry;1498 return import_entry;
1501}1499}
15021500
1503void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code) {1501void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *source_code) {
1504 init(g, source_path);1502 Buf source_path = BUF_INIT;
1503 os_path_join(src_dir, src_basename, &source_path);
1504 init(g, &source_path);
15051505
1506 g->root_import = codegen_add_code(g, source_path, source_code);1506 g->root_import = codegen_add_code(g, src_dir, src_basename, source_code);
15071507
1508 if (g->insert_bootstrap_code) {1508 if (g->insert_bootstrap_code) {
1509 Buf *path_to_bootstrap_src = buf_sprintf("%s/bootstrap.zig", ZIG_STD_DIR);1509 Buf *bootstrap_dir = buf_create_from_str(ZIG_STD_DIR);
1510 Buf *bootstrap_basename = buf_create_from_str("bootstrap.zig");
1511 Buf path_to_bootstrap_src = BUF_INIT;
1512 os_path_join(bootstrap_dir, bootstrap_basename, &path_to_bootstrap_src);
1510 Buf *import_code = buf_alloc();1513 Buf *import_code = buf_alloc();
1511 int err;1514 int err;
1512 if ((err = os_fetch_file_path(path_to_bootstrap_src, import_code))) {1515 if ((err = os_fetch_file_path(&path_to_bootstrap_src, import_code))) {
1513 zig_panic("unable to open '%s': %s", buf_ptr(path_to_bootstrap_src), err_str(err));1516 zig_panic("unable to open '%s': %s", buf_ptr(&path_to_bootstrap_src), err_str(err));
1514 }1517 }
15151518
1516 codegen_add_code(g, path_to_bootstrap_src, import_code);1519 codegen_add_code(g, bootstrap_dir, bootstrap_basename, import_code);
1517 }1520 }
15181521
1519 if (g->verbose) {1522 if (g->verbose) {
src/codegen.hpp+1-1
...@@ -34,7 +34,7 @@ void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);...@@ -34,7 +34,7 @@ void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
34void codegen_set_out_type(CodeGen *codegen, OutType out_type);34void codegen_set_out_type(CodeGen *codegen, OutType out_type);
35void codegen_set_out_name(CodeGen *codegen, Buf *out_name);35void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
3636
37void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code);37void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code);
3838
39void codegen_link(CodeGen *g, const char *out_file);39void codegen_link(CodeGen *g, const char *out_file);
4040
src/main.cpp+1-1
...@@ -144,7 +144,7 @@ static int build(const char *arg0, int argc, char **argv) {...@@ -144,7 +144,7 @@ static int build(const char *arg0, int argc, char **argv) {
144 codegen_set_out_name(g, buf_create_from_str(b.out_name));144 codegen_set_out_name(g, buf_create_from_str(b.out_name));
145 codegen_set_verbose(g, b.verbose);145 codegen_set_verbose(g, b.verbose);
146 codegen_set_errmsg_color(g, b.color);146 codegen_set_errmsg_color(g, b.color);
147 codegen_add_root_code(g, &root_source_name, &root_source_code);147 codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code);
148 codegen_link(g, b.out_file);148 codegen_link(g, b.out_file);
149149
150 return 0;150 return 0;