Commits

camlspotter committed 89b10be

comment

  • Participants
  • Parent commits 1a0bc84

Comments (0)

Files changed (2)

 FILES[] =
    ltype_intf
    ltype
+   gep
    lvalue_intf
    lvalue
    lmodule_intf
   val global_stringptr : ?name:string -> string -> i8 pointer v m
 
   val unsafe_gep : ?name:string -> 'a pointer v -> i32 v list -> 'unsafe pointer v m
+    
+  (** Type-safe GEP
+      
+      Do not be fooled by those complex types. They are pretty easy to use:
 
+      [gep v acc1 acc2 ... accn Gep.end_] provides a type safe version of 
+      [unsafe_gep v [<acc1>; <acc2>; .. ; <accn>]].
+
+      Here acci is an accessor, one of the followings:
+       - [Gep.pos_const n] : Accessing n-th pointer/array/vector elements
+       - [Gep.pos n] : Accessing n-th pointer/array/vector elements by llvalue
+       - [Gep.mem<i>] : Accessing n-th element of struct
+
+      You must give appropriate accessors: 
+      for example, you cannot use [pos n] for n-th element of struct.
+
+      Do not forget to put Gep.end_ at the end of the accessor list.
+
+      Examples:
+
+        - Obtain i32* from i32[20]* p, which points to p[0][n]
+            gep pointer (Gep.pos_const 0) (Gep.pos n) Gep.end_ : i32 pointer v m
+        - Obtain i32* from {i1, i16, i32, i64}* p, which points to the i32 element of the struct *p.
+            gep pointer (Gep.pos_const 0) Gep.mem2 Gep.end_ : i32 pointer v m
+
+      Type-safe GEP + load/store
+
+      GEP and load/store are often used in conjunctions, gep_load and gep_store are available for such cases:
+
+        - Load i32 p[0][n] of i32[20]* p
+            gep_load pointer (Gep.pos_const 0) (Gep.pos n) Gep.end_ : i32 v m 
+        - Store the i32 element [v] to the 2nd element of {i1, i16, i32, i64}* p
+            gep_store v ~dst:pointer (Gep.pos_const 0) Gep.mem2 Gep.end_ : i32 v m 
+  *)
   module Gep : sig
     type ('a, 'res) t (** phantom for type safe GEP *)
     val gep_gen : ?name:string -> ('x pointer v -> 'y m) -> 'a pointer v -> (('a pointer, 'x pointer v -> 'y m) t -> 'b) -> 'b