From 6c108fa68e6bf7d064f94d554a60fc091a553486 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Wed, 31 Oct 2018 11:16:22 -0700 Subject: [PATCH] [sledge] Make Typ.ptr and Typ.siz inter-castable Reviewed By: mbouaziz Differential Revision: D12854513 fbshipit-source-id: 8af1f9862 --- sledge/TODO.org | 6 ++++++ sledge/src/llair/typ.ml | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sledge/TODO.org b/sledge/TODO.org index a148bd6de..5b2eb355f 100644 --- a/sledge/TODO.org +++ b/sledge/TODO.org @@ -19,6 +19,11 @@ rather than nearest enclosing ** NEXT normalize arithmetic exps to polynomials and sort terms ** when Xor exps have types, simplify e xor e to 0 +** treat Typ.ptr as an integer of some particular size (i.e. ptr = intptr) +- normalizing e.g. p - q to the polynomial p + (-1 * q) forces this interpretation of types +- options are to handle Pointer _ as Integer {bits= 64} everywhere, or +- to remove Pointer and just use Integer +- keeping Pointer makes Typ.equal finer than semantically justified, but may be unproblematic and otherwise worthwhile for reporting/debugging ** ? remove src typ from Convert ** ? distribute addition over multiplication for e.g. ((%12 + 1) * 8) to ((%12 * 8) + 8) @@ -129,6 +134,7 @@ but they are currently the same for all functions: i8* + after entry block (and recursively everything reachable from it) is xlated, map over the function block list looking up from the table to get order of conts to match order of blocks ** ? format #line directives in programs * frontend +** ? translate PtrToInt and IntToPtr as cast when sizes match ** use llvm.lifetime.{start,end} to determine where to (alloc and?) free locals ** hoist alloca's to the beginning of the entry block whenever possible ** clean up translation of intrinsics diff --git a/sledge/src/llair/typ.ml b/sledge/src/llair/typ.ml index 53da05688..e00f71237 100644 --- a/sledge/src/llair/typ.ml +++ b/sledge/src/llair/typ.ml @@ -104,15 +104,19 @@ let struct_ = let bool = integer ~bits:1 let siz = integer ~bits:64 + +(** [ptr] is semantically equivalent to [siz], but has a distinct + representation because the element type is important for [Global]s *) let ptr = pointer ~elt:(integer ~bits:8) (** Queries *) let rec prim_bit_size_of = function | Integer {bits} | Float {bits} -> Some bits + | Pointer _ -> prim_bit_size_of siz | Array {elt; len} -> Option.map (prim_bit_size_of elt) ~f:(fun n -> n * len) - | Function _ | Pointer _ | Tuple _ | Struct _ | Opaque _ -> None + | Function _ | Tuple _ | Struct _ | Opaque _ -> None let castable t0 t1 = match (t0, t1) with