Change hw6 to an unsolved version.

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-01-24 23:10:01 -08:00
parent 0c04936ccf
commit ee01a8f5b2
186 changed files with 9605 additions and 4019 deletions

View file

@ -33,36 +33,8 @@ type fact = SymPtr.t UidM.t
- Other instructions do not define pointers
*)
let insn_flow ((u,i):uid * insn) (d:fact) : fact =
(* define values *)
let unique : SymPtr.t = Unique in
let may_alias : SymPtr.t = MayAlias in
let undef_alias : SymPtr.t = UndefAlias in
match i with
| Alloca _ -> UidM.add u unique d
| Load (ty, _) ->
let is_ty_ptr_namedt = match ty with | Ptr t ->
let r = begin match t with | Ptr t -> true | _ -> false end in r | _ -> false in
if is_ty_ptr_namedt == true then
UidM.add u may_alias d
else d
| Store (_, op, _) ->
(* update ptr arg *)
let is_op_uid = match op with | Const _ -> true | _ -> false in
if is_op_uid == true then d else
let op_uid = match op with | Id i -> i | Gid i -> i | _ -> failwith "Store error should be caught above" in
if UidM.mem op_uid d == false then d else
UidM.update (fun _ -> may_alias) op_uid d
| Call (_, op, _) | Bitcast (_, op, _) | Gep (_, op, _) ->
(* update ptr arg *)
let op_uid = match op with | Id i -> i | Gid i -> i | _ -> failwith "Call is supposed to be a uid" in
if UidM.mem op_uid d == true then
(* update ptr returned *)
let d1 = UidM.update (fun _ -> may_alias) op_uid d in UidM.add u may_alias d1
else UidM.add u may_alias d
| Binop _ | Icmp _ -> d
failwith "Alias.insn_flow unimplemented"
(* The flow function across terminators is trivial: they never change alias info *)
@ -96,33 +68,8 @@ module Fact =
It may be useful to define a helper function that knows how to take the
meet of two SymPtr.t facts.
*)
let lattice (m1:SymPtr.t) (m2:SymPtr.t) : SymPtr.t =
match m1, m2 with
| MayAlias, _ -> MayAlias
| _, MayAlias -> MayAlias
| Unique, Unique -> Unique
| Unique, UndefAlias -> Unique
| UndefAlias, Unique -> Unique
| UndefAlias, UndefAlias -> UndefAlias
let combine (ds : fact list) : fact =
(* used LLM to understand how the UidM.t merge function could be useful through made-up examples, and what the inputs 'a option meant *)
(* PART 2: look at the facts, if we have non-None facts, we can merge them based on the lattice *)
let look_at_facts _ a_opt b_opt =
match a_opt, b_opt with
| Some a, Some b -> Some (lattice a b)
| Some a, None -> Some a
| None, Some b -> Some b
| _, _ -> failwith "look_at_facts: incorrect opts" in
(* PART 1: create combine function that looks at the facts *)
let rec combine_function (fl : fact list) (acc : SymPtr.t UidM.t) : SymPtr.t UidM.t =
match fl with
| [] -> acc
| hd :: tl -> let result = UidM.merge look_at_facts acc hd in combine_function tl result in
combine_function ds UidM.empty
let combine (ds:fact list) : fact =
failwith "Alias.Fact.combine not implemented"
end
(* instantiate the general framework ---------------------------------------- *)