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
13 changes: 13 additions & 0 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ let withCprint (f: 'a -> unit) (x: 'a) : unit =
* hold the result of function calls *)
let callTempVars: unit IH.t = IH.create 13

let allTempVars: unit IH.t = IH.create 13

(* Keep a list of functions that were called without a prototype. *)
let noProtoFunctions : bool IH.t = IH.create 13

Expand Down Expand Up @@ -336,9 +338,16 @@ type envdata =
* for this category is "label foo" *)

let env : (string, envdata * location) H.t = H.create 307

(* Just like env, except that it simply collects all the information (i.e. entries
* are never removed and it is also not emptied after every file). *)
let environment : (string, envdata * location) H.t = H.create 307

(* We also keep a global environment. This is always a subset of the env *)
let genv : (string, envdata * location) H.t = H.create 307

let varnameMapping : (string, string) H.t = H.create 307

(* In the scope we keep the original name, so we can remove them from the
* hash table easily *)
type undoScope =
Expand All @@ -357,6 +366,7 @@ let isAtTopLevel () =
let addLocalToEnv (n: string) (d: envdata) =
(* ignore (E.log "%a: adding local %s to env\n" d_loc !currentLoc n); *)
H.add env n (d, !currentLoc);
H.add environment n (d, !currentLoc);
(* If we are in a scope, then it means we are not at top level. Add the
* name to the scope *)
(match !scopes with
Expand All @@ -373,6 +383,7 @@ let addLocalToEnv (n: string) (d: envdata) =
let addGlobalToEnv (k: string) (d: envdata) : unit =
(* ignore (E.log "%a: adding global %s to env\n" d_loc !currentLoc k); *)
H.add env k (d, !currentLoc);
H.add environment k (d, !currentLoc);
(* Also add it to the global environment *)
H.add genv k (d, !currentLoc)

Expand Down Expand Up @@ -428,6 +439,7 @@ let newAlphaName (globalscope: bool) (* The name should have global scope *)
findEnclosingFun !scopes;
let newname, oldloc =
AL.newAlphaName ~alphaTable:alphaTable ~undolist:None ~lookupname:lookupname ~data:!currentLoc in
H.add varnameMapping origname newname;
stripKind kind newname, oldloc


Expand Down Expand Up @@ -4606,6 +4618,7 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
(* Remember that this variable has been created for this
* specific call. We will use this in collapseCallCast. *)
IH.add callTempVars tmp.vid ();
IH.add allTempVars tmp.vid ();
addCall (Some (var tmp)) (Lval(var tmp)) restype''
end
end;
Expand Down
31 changes: 27 additions & 4 deletions src/frontc/cabs2cil.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(*
*
* Copyright (c) 2001-2002,
* Copyright (c) 2001-2002,
* George C. Necula <necula@cs.berkeley.edu>
* Scott McPeak <smcpeak@cs.berkeley.edu>
* Wes Weimer <weimer@cs.berkeley.edu>
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
Expand Down Expand Up @@ -41,7 +41,7 @@ val convFile: Cabs.file -> Cil.file
(** Turn on tranformation that forces correct parameter evaluation order *)
val forceRLArgEval: bool ref

(** Set this integer to the index of the global to be left in CABS form. Use
(** Set this integer to the index of the global to be left in CABS form. Use
* -1 to disable *)
val nocil: int ref

Expand Down Expand Up @@ -74,7 +74,7 @@ val typeForTypeof: (Cil.typ -> Cil.typ) ref
types of cabs2cil-introduced temp variables. *)
val typeForInsertedVar: (Cil.typ -> Cil.typ) ref

(** Like [typeForInsertedVar], but for casts.
(** Like [typeForInsertedVar], but for casts.
* Casts in the source code are exempt from this hook. *)
val typeForInsertedCast: (Cil.typ -> Cil.typ) ref

Expand All @@ -84,3 +84,26 @@ val typeForCombinedArg: ((string, string) Hashtbl.t -> Cil.typ -> Cil.typ) ref
(** A hook into the code that merges arguments in function attributes. *)
val attrsForCombinedArg: ((string, string) Hashtbl.t ->
Cil.attributes -> Cil.attributes) ref

val varnameMapping : (string, string) Hashtbl.t

val allTempVars: unit Inthash.t

type envdata =
EnvVar of Cil.varinfo (* The name refers to a variable
* (which could also be a function) *)
| EnvEnum of Cil.exp * Cil.typ (* The name refers to an enumeration
* tag for which we know the value
* and the host type *)
| EnvTyp of Cil.typ (* The name is of the form "struct
* foo", or "union foo" or "enum foo"
* and refers to a type. Note that
* the name of the actual type might
* be different from foo due to alpha
* conversion *)
| EnvLabel of string (* The name refers to a label. This
* is useful for GCC's locally
* declared labels. The lookup name
* for this category is "label foo" *)
(** A hashtable containing a mapping of variables, enums, types and labels to varinfo, typ, etc. *)
val environment : (string, envdata * Cil.location) Hashtbl.t