Build maps of metadata variables.

master
Rohan Jacob-Rao 9 years ago
parent 7e169b0471
commit a7da6066e5

@ -251,6 +251,12 @@ module StringSet = Set.Make(String)
let pp_stringset fmt ss = let pp_stringset fmt ss =
StringSet.iter (fun s -> F.fprintf fmt "%s " s) ss StringSet.iter (fun s -> F.fprintf fmt "%s " s) ss
(** Maps from integers *)
module IntMap = Map.Make (struct
type t = int
let compare = int_compare
end)
(** Maps from strings *) (** Maps from strings *)
module StringMap = Map.Make (struct module StringMap = Map.Make (struct
type t = string type t = string

@ -147,6 +147,9 @@ module StringSet : Set.S with type elt = string
(** Pretty print a set of strings *) (** Pretty print a set of strings *)
val pp_stringset : Format.formatter -> StringSet.t -> unit val pp_stringset : Format.formatter -> StringSet.t -> unit
(** Maps from integers *)
module IntMap : Map.S with type key = int
(** Maps from strings *) (** Maps from strings *)
module StringMap : Map.S with type key = string module StringMap : Map.S with type key = string

@ -9,6 +9,8 @@
(** Representation of LLVM constructs *) (** Representation of LLVM constructs *)
module MetadataMap = Utils.IntMap;;
type variable_id = type variable_id =
| Name of string | Name of string
| Number of int | Number of int
@ -44,10 +46,6 @@ and metadata_component =
| TypOperand of typ option * operand | TypOperand of typ option * operand
| MetadataVal of metadata_value | MetadataVal of metadata_value
type metadata_mapping =
| NameMapping of string * int list
| NumberMapping of int * metadata_component list
type instr = type instr =
| Ret of (typ * operand) option | Ret of (typ * operand) option
| UncondBranch of variable | UncondBranch of variable
@ -63,7 +61,9 @@ type annotated_instr = instr * annotation option
type func_def = FuncDef of variable * typ option * (typ * string) list * annotated_instr list type func_def = FuncDef of variable * typ option * (typ * string) list * annotated_instr list
type prog = Prog of func_def list type metadata_map = metadata_component list MetadataMap.t
type prog = Prog of func_def list * metadata_map
let string_of_variable : variable -> string = function let string_of_variable : variable -> string = function
| Global var_id | Local var_id -> | Global var_id | Local var_id ->

@ -154,7 +154,11 @@
%% %%
prog: prog:
| targets defs = func_def* mappings = metadata_def* EOF { Prog defs } | targets defs = func_def* opt_mappings = metadata_def* EOF {
let mappings = Utils.list_flatten_options opt_mappings in
let add_mapping map (metadata_id, components) = MetadataMap.add metadata_id components map in
let metadata_map = Utils.list_fold_left add_mapping MetadataMap.empty mappings in
Prog (defs, metadata_map) }
targets: targets:
| { (None, None) } | { (None, None) }
@ -170,8 +174,8 @@ target_triple:
| TARGET TRIPLE EQUALS str = CONSTANT_STRING { str } | TARGET TRIPLE EQUALS str = CONSTANT_STRING { str }
metadata_def: metadata_def:
| name = NAMED_METADATA EQUALS metadata_ids = numbered_metadata_node { NameMapping (name, metadata_ids) } | NAMED_METADATA EQUALS numbered_metadata_node { None }
| metadata_id = NUMBERED_METADATA EQUALS components = metadata_node { NumberMapping (metadata_id, components) } | metadata_id = NUMBERED_METADATA EQUALS components = metadata_node { Some (metadata_id, components) }
numbered_metadata_node: numbered_metadata_node:
| METADATA_NODE_BEGIN metadata_ids = separated_list(COMMA, NUMBERED_METADATA) RBRACE { metadata_ids } | METADATA_NODE_BEGIN metadata_ids = separated_list(COMMA, NUMBERED_METADATA) RBRACE { metadata_ids }

@ -119,7 +119,7 @@ let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) : LAst.func_def -> unit = function
Cg.add_node cg procname Cg.add_node cg procname
let trans_prog : LAst.prog -> Cfg.cfg * Cg.t * Sil.tenv = function let trans_prog : LAst.prog -> Cfg.cfg * Cg.t * Sil.tenv = function
Prog func_defs -> Prog (func_defs, _) ->
let cfg = Cfg.Node.create_cfg () in let cfg = Cfg.Node.create_cfg () in
let cg = Cg.create () in let cg = Cg.create () in
let tenv = Sil.create_tenv () in let tenv = Sil.create_tenv () in

Loading…
Cancel
Save