| ... | @@ -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_type | 1316 | 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, ""); |
| 1323 | | 1322 | |
| 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); |
| 1388 | | 1387 | |
| | 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); |
| 1390 | | 1392 | |
| 1391 | } | 1393 | } |
| 1392 | | 1394 | |
| 1393 | static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) { | 1395 | static 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); | | |
| 1401 | | 1399 | |
| 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)); |
| 1406 | | 1404 | |
| ... | @@ -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; |
| 1424 | | 1422 | |
| ... | @@ -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 | } |
| 1446 | | 1444 | |
| 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); |
| 1449 | | 1447 | |
| 1450 | | 1448 | |
| 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 | } |
| 1502 | | 1500 | |
| 1503 | void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code) { | 1501 | void 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); |
| 1505 | | 1505 | |
| 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); |
| 1507 | | 1507 | |
| 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 | } |
| 1515 | | 1518 | |
| 1516 | codegen_add_code(g, path_to_bootstrap_src, import_code); | 1519 | codegen_add_code(g, bootstrap_dir, bootstrap_basename, import_code); |
| 1517 | } | 1520 | } |
| 1518 | | 1521 | |
| 1519 | if (g->verbose) { | 1522 | if (g->verbose) { |