Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions lib/bap_core_theory/bap_core_theory.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ module Theory : sig

(** [read ?package name] is a synonym for [get ?package name].

Introduces for the consistency with the [Enum.S] interface.
Introduced for the consistency with the [Enum.S] interface.
*)
val read : ?package:string -> string -> t

Expand All @@ -1480,10 +1480,30 @@ module Theory : sig
(** [name target] is the unique name of the target. *)
val name : t -> KB.Name.t

(** [matches target name] is true if [name] matches either
the unqualified name of the target itsef or one of its
ancestors; or if the name matches one of the target
nicknames. E.g., [matches target "mips"].

(** [matching t name] the target that matches [name].

[matching t name] is [Some r] where [r] is [t] or the closest
ancestor of [t] such that [r]'s name is equal to [name] or one
of name is [r]'s nicknames.

@since 2.5.0
*)
val matching : t -> string -> t option


(** [matches t name] when {!matching t name} is not [None].

[matching t name] is true when [name] matches either the
unqualified name of the target itsef or one of its ancestors;
or if the name matches one of the target nicknames or the
target parents nicknames.

E.g., [matches target "mips"].

@before 2.5.0 the nicknames of the ancestors weren't taken
into account
@after 2.5.0 uses the ancestors nicknames for matching
*)
val matches : t -> string -> bool

Expand Down Expand Up @@ -1515,7 +1535,7 @@ module Theory : sig
*)
val parents : t -> t list

(** [family p] returns an ordered list of targets that {!belongs} [p].
(** [family p] an ordered list of targets s.t. each {!belongs} to [p].

The family members are ordered according to their hierarchy
with [p] comming first.
Expand Down Expand Up @@ -2342,6 +2362,12 @@ module Theory : sig
?options:string list ->
string -> compiler


(** [name compiler] returns the compiler name.

@since 2.5.0 *)
val name : compiler -> string

(** [version] the compiler version.

The least specific (aka major) version comes first in the
Expand Down
1 change: 1 addition & 0 deletions lib/bap_core_theory/bap_core_theory_program.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module Compiler : sig
?version:string list ->
?options:string list ->
string -> compiler
val name : compiler -> string
val version : compiler -> string list
val options : compiler -> string list
val specs : compiler -> string Map.M(String).t
Expand Down
22 changes: 14 additions & 8 deletions lib/bap_core_theory/bap_core_theory_target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,6 @@ let is_known c = not@@is_unknown c
let rec belongs p c =
Self.equal p c || is_known c && belongs p (parent c)

let rec matches_name t name =
String.Caseless.equal (Name.unqualified (Self.name t)) name ||
is_known t && matches_name (parent t) name

let rec matches t name =
let nicks = (info t).names in
Set.mem nicks name || matches_name t name

let order t1 t2 : KB.Order.partial =
if Self.equal t1 t2 then EQ
else if belongs t1 t2 then LT
Expand Down Expand Up @@ -597,6 +589,20 @@ let partition xs =

let families () = partition@@declared ()

let matches_name t name =
String.Caseless.equal (Name.unqualified (Self.name t)) name

let rec matching t name =
if matches_name t name || Set.mem (info t).names name
then Some t
else if is_known t then matching (parent t) name
else None


let matches t name =
Option.is_some (matching t name)

let nicknames t = (info t).names

type alias = Alias.t

Expand Down
1 change: 1 addition & 0 deletions lib/bap_core_theory/bap_core_theory_target.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ val unknown : t
val is_unknown : t -> bool
val name : t -> KB.Name.t
val matches : t -> string -> bool
val matching : t -> string -> t option
val order : t -> t -> KB.Order.partial
val belongs : t -> t -> bool
val parent : t -> t
Expand Down