Skip to content

Commit

Permalink
Explore blocks from end first
Browse files Browse the repository at this point in the history
  • Loading branch information
ScoreUnder committed Dec 6, 2022
1 parent 5a85dcf commit 503555c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src_pksv/lang_decompiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,22 @@ void decompile_all(FILE *input_file, uint32_t start_offset,
// 1. Gets all the blocks that need to be decompiled.
// 2. Associates addresses with decompiled blocks.
while (unvisited_blocks.size != 0) {
uint32_t decompilation_addr = bsearch_key_u32(&unvisited_blocks, 0);
// Taking last is faster on removal
size_t index = unvisited_blocks.size - 1;
uint32_t decompilation_addr = bsearch_key_u32(&unvisited_blocks, index);

if (bsearch_find_u32(&decomp_blocks, decompilation_addr) >= 0) {
// Already queued for decompilation.
bsearch_remove(&unvisited_blocks, 0);
bsearch_remove(&unvisited_blocks, index);
continue;
}

struct queued_decompilation *decompilation_type =
duplicate_queued_decompilation(unvisited_blocks.pairs[0].value);
duplicate_queued_decompilation(unvisited_blocks.pairs[index].value);
bsearch_upsert(&decomp_blocks, CAST_u32_pvoid(decompilation_addr),
decompilation_type);

bsearch_remove(&unvisited_blocks, 0);
bsearch_remove(&unvisited_blocks, index);

decomp_visit_address(&decomp_state, decompilation_type, decompilation_addr,
false);
Expand Down

0 comments on commit 503555c

Please sign in to comment.