From 14ad67d59a25d99efcf82d2c8129b5010a51bcd8 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Fri, 18 Oct 2024 14:14:44 -0700 Subject: [PATCH] assign correct file path node to source file * disabled debug check for sortness too while I'm here --- src/linker/rdi/rdi_builder.c | 30 +++++++++++++++++++++--------- src/linker/rdi/rdi_builder.h | 2 ++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/linker/rdi/rdi_builder.c b/src/linker/rdi/rdi_builder.c index e545a3d5..79333571 100644 --- a/src/linker/rdi/rdi_builder.c +++ b/src/linker/rdi/rdi_builder.c @@ -1764,13 +1764,23 @@ rdib_idx_from_path_tree(RDIB_PathTree *tree, String8 path) { Temp scratch = scratch_begin(0,0); + // redirect to special nil string + if (path.size == 0) { + path = RDIB_PATH_TREE_NIL_STRING; + } + + // begin traverse from tree root RDIB_PathTreeNode *curr_sub_path = tree->root; - String8List sub_paths = str8_split_by_string_chars(scratch.arena, path, str8_lit("/\\"), 0); + + // split path & resolve dots + String8List sub_paths = str8_split_path(scratch.arena, path); + str8_path_list_resolve_dots_in_place(&sub_paths, path_style_from_str8(path)); + for (String8Node *n = sub_paths.first; n != 0; n = n->next) { // scan children sub-path match RDIB_PathTreeNode *sub_child; for (sub_child = curr_sub_path->first_child; sub_child != 0; sub_child = sub_child->next_sibling) { - if (str8_match(sub_child->sub_path, n->string, StringMatchFlag_CaseInsensitive)) { + if (str8_match(sub_child->sub_path, n->string, 0)) { break; } } @@ -1780,13 +1790,16 @@ rdib_idx_from_path_tree(RDIB_PathTree *tree, String8 path) break; } - // descend + // descend to sub directory curr_sub_path = sub_child; } - U64 idx = max_U64; - if (curr_sub_path != 0) { + // did we find source file? + U64 idx = 0; + if (curr_sub_path != 0 && curr_sub_path->src_file != 0) { idx = curr_sub_path->node_idx; + } else { + Assert(!"unable to find source file path"); } scratch_end(scratch); @@ -2147,7 +2160,7 @@ rdib_string_map_sort_buckets(TP_Context *tp, RDIB_StringMapBucket **buckets, U64 ProfEnd(); // sort correctness check on element index -#if 1 +#if 0 { for (U64 i = 1; i < bucket_count; ++i) { RDIB_StringMapBucket *prev = buckets[i - 1]; @@ -3818,8 +3831,7 @@ rdib_build_path_tree(Arena *arena, Temp scratch = scratch_begin(&arena, 1); RDIB_PathTree *tree = rdib_path_tree_init(arena, worker_count); - - rdib_path_tree_insert(arena, tree, str8_lit(""), null_src_file); + rdib_path_tree_insert(arena, tree, RDIB_PATH_TREE_NIL_STRING, null_src_file); ProfBegin("Units"); for (U64 ichunk = 0; ichunk < unit_chunk_count; ++ichunk) { @@ -3839,7 +3851,7 @@ rdib_build_path_tree(Arena *arena, RDIB_SourceFileChunk *chunk = src_file_chunks[chunk_idx]; for (U64 i = 0; i < chunk->count; ++i) { RDIB_SourceFile *src_file = chunk->v + i; - rdib_path_tree_insert(arena, tree, src_file->normal_full_path, src_file); + rdib_path_tree_insert(arena, tree, src_file->file_path, src_file); } } ProfEnd(); diff --git a/src/linker/rdi/rdi_builder.h b/src/linker/rdi/rdi_builder.h index 8d7cf927..d0b3ef33 100644 --- a/src/linker/rdi/rdi_builder.h +++ b/src/linker/rdi/rdi_builder.h @@ -708,6 +708,8 @@ typedef struct //////////////////////////////// +#define RDIB_PATH_TREE_NIL_STRING str8_lit("") + typedef struct RDIB_PathTreeNode { struct RDIB_PathTreeNode *parent;