1 (* Copyright (C) 2014 Matthew Fluet.
2 * Copyright (C) 2004-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
9 functor CType (S: C_TYPE_STRUCTS): C_TYPE =
29 Int8, Int16, Int32, Int64,
32 Word8, Word16, Word32, Word64]
34 val cpointer = CPointer
38 val equals: t * t -> bool = op =
40 fun memo (f: t -> 'a): t -> 'a =
42 val cpointer = f CPointer
55 fn CPointer => cpointer
70 fn CPointer => "CPointer"
75 | Objptr => "Objptr" (* CHECK *)
83 val layout = Layout.str o toString
85 fun size (t: t): Bytes.t =
87 CPointer => Bits.toBytes (Control.Target.Size.cpointer ())
88 | Int8 => Bytes.fromInt 1
89 | Int16 => Bytes.fromInt 2
90 | Int32 => Bytes.fromInt 4
91 | Int64 => Bytes.fromInt 8
92 | Objptr => Bits.toBytes (Control.Target.Size.objptr ())
93 | Real32 => Bytes.fromInt 4
94 | Real64 => Bytes.fromInt 8
95 | Word8 => Bytes.fromInt 1
96 | Word16 => Bytes.fromInt 2
97 | Word32 => Bytes.fromInt 4
98 | Word64 => Bytes.fromInt 8
102 CPointer => "Q" (* CHECK *)
107 | Objptr => "P" (* CHECK *)
115 fun align (t: t, b: Bytes.t): Bytes.t =
116 Bytes.align (b, {alignment = size t})
118 fun real (s: RealSize.t): t =
119 case Bits.toInt (RealSize.bits s) of
122 | _ => Error.bug "CType.real"
124 fun word' (b: Bits.t, {signed: bool}): t =
125 case (signed, Bits.toInt b) of
128 | (false, 16) => Word16
129 | (true, 16) => Int16
130 | (false, 32) => Word32
131 | (true, 32) => Int32
132 | (false, 64) => Word64
133 | (true, 64) => Int64
134 | _ => Error.bug "CType.word'"
136 fun word (s: WordSize.t, {signed: bool}): t =
137 word' (WordSize.bits s, {signed = signed})
141 (fn () => word' (Control.Target.Size.cint (),
145 (fn () => word' (Control.Target.Size.csize (),
150 (fn () => word' (Control.Target.Size.seqIndex (),
155 (fn () => word' (Control.Target.Size.header (),
158 val bool = word (WordSize.bool, {signed = true})
159 val compareRes = word (WordSize.compareRes, {signed = true})
160 val shiftArg = word (WordSize.shiftArg, {signed = false})