0 | {--
 1 | Copyright (C) 2026  Joel Berkeley
 2 |
 3 | This program is free software: you can redistribute it and/or modify
 4 | it under the terms of the GNU Affero General Public License as published
 5 | by the Free Software Foundation, either version 3 of the License, or
 6 | (at your option) any later version.
 7 |
 8 | This program is distributed in the hope that it will be useful,
 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program.  If not, see <https://www.gnu.org/licenses/>.
15 | --}
16 | ||| For internal spidr use only.
17 | module Compiler.DType
18 |
19 | import Compiler.MLIR.IR.MLIRContext
20 | import Compiler.MLIR.IR.Types
21 | import Compiler.MLIR.IR.BuiltinTypes
22 | import DType
23 |
24 | export
25 | numBits : DType -> Bits16
26 | numBits PRED = 1
27 | numBits S32  = 32
28 | numBits S64  = 64
29 | numBits U32  = 32
30 | numBits U64  = 64
31 | numBits F64  = 64
32 |
33 | export
34 | isSigned : DType -> Bool
35 | isSigned PRED = True
36 | isSigned S32  = True
37 | isSigned S64  = True
38 | isSigned U32  = False
39 | isSigned U64  = False
40 | isSigned F64  = True
41 |
42 | export
43 | mlirType : HasIO io => MLIRContext -> DType -> io Type_
44 | mlirType ctx PRED = cast <$> IntegerType.get ctx 1  Signless
45 | mlirType ctx S32  = cast <$> IntegerType.get ctx 32 Signless
46 | mlirType ctx S64  = cast <$> IntegerType.get ctx 64 Signless
47 | mlirType ctx U32  = cast <$> IntegerType.get ctx 32 Unsigned
48 | mlirType ctx U64  = cast <$> IntegerType.get ctx 64 Unsigned
49 | mlirType ctx F64  = cast <$> Float64Type.get ctx
50 |