From a7da6066e5c3e10844356c22d09e8dcddf124279 Mon Sep 17 00:00:00 2001 From: Rohan Jacob-Rao Date: Wed, 12 Aug 2015 12:26:59 -0700 Subject: [PATCH] Build maps of metadata variables. --- infer/src/backend/utils.ml | 6 ++++++ infer/src/backend/utils.mli | 3 +++ infer/src/llvm/lAst.ml | 10 +++++----- infer/src/llvm/lParser.mly | 10 +++++++--- infer/src/llvm/lTrans.ml | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/infer/src/backend/utils.ml b/infer/src/backend/utils.ml index 442f421ae..19042fb79 100644 --- a/infer/src/backend/utils.ml +++ b/infer/src/backend/utils.ml @@ -251,6 +251,12 @@ module StringSet = Set.Make(String) let pp_stringset fmt 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 *) module StringMap = Map.Make (struct type t = string diff --git a/infer/src/backend/utils.mli b/infer/src/backend/utils.mli index c3b08287d..efcd06e3d 100644 --- a/infer/src/backend/utils.mli +++ b/infer/src/backend/utils.mli @@ -147,6 +147,9 @@ module StringSet : Set.S with type elt = string (** Pretty print a set of strings *) val pp_stringset : Format.formatter -> StringSet.t -> unit +(** Maps from integers *) +module IntMap : Map.S with type key = int + (** Maps from strings *) module StringMap : Map.S with type key = string diff --git a/infer/src/llvm/lAst.ml b/infer/src/llvm/lAst.ml index 6c331cb30..a0947a823 100644 --- a/infer/src/llvm/lAst.ml +++ b/infer/src/llvm/lAst.ml @@ -9,6 +9,8 @@ (** Representation of LLVM constructs *) +module MetadataMap = Utils.IntMap;; + type variable_id = | Name of string | Number of int @@ -44,10 +46,6 @@ and metadata_component = | TypOperand of typ option * operand | MetadataVal of metadata_value -type metadata_mapping = - | NameMapping of string * int list - | NumberMapping of int * metadata_component list - type instr = | Ret of (typ * operand) option | 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 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 | Global var_id | Local var_id -> diff --git a/infer/src/llvm/lParser.mly b/infer/src/llvm/lParser.mly index 4692b4703..e896ed5ae 100644 --- a/infer/src/llvm/lParser.mly +++ b/infer/src/llvm/lParser.mly @@ -154,7 +154,11 @@ %% 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: | { (None, None) } @@ -170,8 +174,8 @@ target_triple: | TARGET TRIPLE EQUALS str = CONSTANT_STRING { str } metadata_def: - | name = NAMED_METADATA EQUALS metadata_ids = numbered_metadata_node { NameMapping (name, metadata_ids) } - | metadata_id = NUMBERED_METADATA EQUALS components = metadata_node { NumberMapping (metadata_id, components) } + | NAMED_METADATA EQUALS numbered_metadata_node { None } + | metadata_id = NUMBERED_METADATA EQUALS components = metadata_node { Some (metadata_id, components) } numbered_metadata_node: | METADATA_NODE_BEGIN metadata_ids = separated_list(COMMA, NUMBERED_METADATA) RBRACE { metadata_ids } diff --git a/infer/src/llvm/lTrans.ml b/infer/src/llvm/lTrans.ml index e11025165..d064bed05 100644 --- a/infer/src/llvm/lTrans.ml +++ b/infer/src/llvm/lTrans.ml @@ -119,7 +119,7 @@ let trans_func_def (cfg : Cfg.cfg) (cg: Cg.t) : LAst.func_def -> unit = function Cg.add_node cg procname 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 cg = Cg.create () in let tenv = Sil.create_tenv () in