Skip to content

Commit 32a648b

Browse files
authored
Relax the restrictions on the encoding of destinations (#1578)
1 parent 7d79f7f commit 32a648b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/bap_disasm/bap_disasm_driver.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,20 @@ let merge_encodings x y =
383383
| Ok coding -> KB.return {x with coding}
384384
| Error mismatch -> KB.fail mismatch
385385

386+
let is_known {coding} = not (Theory.Language.is_unknown coding)
386387

387388
let collect_dests source code =
388389
KB.collect Theory.Semantics.slot code >>= fun insn ->
389390
let init = {
390-
encoding=source;
391+
encoding={source with coding = Theory.Language.unknown};
391392
call = Insn.(is call insn);
392393
barrier = Insn.(is barrier insn);
393394
indirect = false;
394395
resolved = Set.empty (module Addr);
395396
unresolved = Set.empty (module Theory.Label);
396397
} in
397398
KB.Value.get Insn.Slot.dests insn |> function
398-
| None -> KB.return init
399+
| None -> KB.return {init with encoding = source}
399400
| Some dests ->
400401
Set.to_sequence dests |>
401402
KB.Seq.fold ~init ~f:(fun dest label ->
@@ -417,7 +418,9 @@ let collect_dests source code =
417418
indirect=true;
418419
unresolved = Set.add dest.unresolved label;
419420
encoding;
420-
})
421+
}) >>| fun dest ->
422+
if is_known dest.encoding then dest
423+
else {dest with encoding = source}
421424

422425
let pp_addr_opt ppf = function
423426
| None -> Format.fprintf ppf "Unk"
@@ -463,8 +466,6 @@ let switch encoding s =
463466
| Error _ -> s
464467
| Ok dis -> Dis.switch s dis
465468

466-
let is_known {coding} = not (Theory.Language.is_unknown coding)
467-
468469
let disassemble ~code ~data ~funs debt base : Machine.state KB.t =
469470
unit_for_mem base >>= fun unit ->
470471
let rec next_encoding state current mem f =

0 commit comments

Comments
 (0)