diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-03-22 13:38:20 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-03-22 13:39:02 -0400 |
commit | fc115427dd7f37932763dff09b080f3eb972c1ed (patch) | |
tree | 689476e3b14ed123beb7c2388c7eeb795f22c238 | |
parent | 59e78fe9694fc7cd6ce64a3e10bef57a6eb05b11 (diff) | |
download | roux-fc115427dd7f37932763dff09b080f3eb972c1ed.tar.gz |
fix struct size computation
-rw-r--r-- | lisc/tools/abi.ml | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lisc/tools/abi.ml b/lisc/tools/abi.ml index 88a59de..d845c74 100644 --- a/lisc/tools/abi.ml +++ b/lisc/tools/abi.ml @@ -23,6 +23,10 @@ type testb = TB: 'a bty * 'a -> testb type testa = TA: 'a aty * 'a -> testa +let align a x = + let m = x mod a in + if m <> 0 then x + (a-m) else x + let btysize: type a. a bty -> int = function | Char -> 1 | Short -> 2 @@ -37,9 +41,14 @@ let styempty: type a. a sty -> bool = function | Field _ -> false | Empty -> true -let rec stysize: type a. a sty -> int = function - | Field (b, s) -> (btyalign b) + (stysize s) - | Empty -> 0 +let stysize s = + let rec f: type a. int -> a sty -> int = + fun sz -> function + | Field (b, s) -> + let a = btyalign b in + f (align a sz + btysize b) s + | Empty -> sz in + f 0 s let rec styalign: type a. a sty -> int = function | Field (b, s) -> max (btyalign b) (styalign s) @@ -331,10 +340,7 @@ module OutIL = struct let rec f: type a. int -> int -> a sty * a -> unit = fun id off -> function | Field (b, s), (tb, ts) -> - let al = btyalign b in - let off = - let x = off mod al in - if x <> 0 then off + al - x else off in + let off = align (btyalign b) off in let addr = tmp () in fprintf oc "\t%s =l add %d, %s\n" addr off base; g id addr (TB (b, tb)); |