0 | {--
 1 | Copyright (C) 2025  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.MLIR.IR.Value
18 |
19 | import Compiler.FFI
20 | import Compiler.MLIR.IR.Types
21 |
22 | ffi : String -> String
23 | ffi = libxla "c/mlir/IR/Value.h"
24 |
25 | public export
26 | data Value = MkValue GCAnyPtr (AnyPtr -> Bits64 -> GCAnyPtr -> PrimIO ())
27 |
28 | export
29 | %foreign (ffi "sizeof_Value")
30 | sizeofValue : Bits64
31 |
32 | export
33 | %foreign (ffi "Value_getType")
34 | prim__valueGetType : GCAnyPtr -> PrimIO AnyPtr
35 |
36 | export
37 | getType : HasIO io => Value -> io Type_
38 | getType (MkValue value _) = do
39 |   type <- primIO $ prim__valueGetType value
40 |   type <- onCollectAny' type (primIO . prim__deleteType)
41 |   pure (MkType_ type prim__setArrayType)
42 |
43 | public export
44 | data BlockArgument = MkBlockArgument GCAnyPtr
45 |
46 | export
47 | %foreign (ffi "BlockArgument_delete")
48 | prim__deleteBlockArgument : AnyPtr -> PrimIO ()
49 |
50 | %foreign (ffi "set_array_BlockArgument")
51 | prim__setArrayBlockArgument : AnyPtr -> Bits64 -> GCAnyPtr -> PrimIO ()
52 |
53 | export
54 | Cast BlockArgument Value where
55 |   cast (MkBlockArgument ptr) = MkValue ptr prim__setArrayBlockArgument
56 |
57 | public export
58 | data OpResult = MkOpResult GCAnyPtr
59 |
60 | export
61 | %foreign (ffi "OpResult_delete")
62 | prim__deleteOpResult : AnyPtr -> PrimIO ()
63 |
64 | %foreign (ffi "set_array_OpResult")
65 | prim__setArrayOpResult : AnyPtr -> Bits64 -> GCAnyPtr -> PrimIO ()
66 |
67 | export
68 | Cast OpResult Value where
69 |   cast (MkOpResult ptr) = MkValue ptr prim__setArrayOpResult
70 |