@@ -3,13 +3,13 @@ use delegate::delegate;
3
3
use hugr:: {
4
4
ops:: { FuncDecl , FuncDefn , NamedOp as _, OpType } ,
5
5
types:: PolyFuncType ,
6
- HugrView , Node , NodeIndex ,
6
+ HugrView , Node ,
7
7
} ;
8
8
use inkwell:: {
9
9
context:: Context ,
10
10
module:: { Linkage , Module } ,
11
11
types:: { AnyType , BasicType , BasicTypeEnum , FunctionType } ,
12
- values:: { BasicValueEnum , FunctionValue , GlobalValue } ,
12
+ values:: { FunctionValue , GlobalValue } ,
13
13
} ;
14
14
use std:: { collections:: HashSet , hash:: Hash , rc:: Rc } ;
15
15
@@ -21,72 +21,15 @@ use crate::{
21
21
types:: { LLVMSumType , TypeConverter } ,
22
22
} ;
23
23
24
- use self :: func:: { EmitFuncContext , RowPromise } ;
24
+ pub use self :: func:: { EmitFuncContext , RowPromise } ;
25
25
26
+ pub mod args;
26
27
pub mod func;
28
+ pub mod namer;
27
29
mod ops;
28
30
29
- /// A type used whenever emission is delegated to a function
30
- pub struct EmitOpArgs < ' c , OT , H > {
31
- /// This [HugrView] and [Node] we are emitting
32
- pub node : FatNode < ' c , OT , H > ,
33
- /// The values that should be used for all Value input ports of the node
34
- pub inputs : Vec < BasicValueEnum < ' c > > ,
35
- /// The results of the node should be put here
36
- pub outputs : RowPromise < ' c > ,
37
- }
38
-
39
- impl < ' c , OT , H > EmitOpArgs < ' c , OT , H > {
40
- /// Get the internal [FatNode]
41
- pub fn node ( & self ) -> FatNode < ' c , OT , H > {
42
- self . node . clone ( )
43
- }
44
- }
45
-
46
- impl < ' c , H : HugrView > EmitOpArgs < ' c , OpType , H > {
47
- /// Attempt to specialise the internal [FatNode].
48
- pub fn try_into_ot < OT : ' c > ( self ) -> Result < EmitOpArgs < ' c , OT , H > , Self >
49
- where
50
- & ' c OpType : TryInto < & ' c OT > ,
51
- {
52
- let EmitOpArgs {
53
- node,
54
- inputs,
55
- outputs,
56
- } = self ;
57
- match node. try_into_ot ( ) {
58
- Some ( new_node) => Ok ( EmitOpArgs {
59
- node : new_node,
60
- inputs,
61
- outputs,
62
- } ) ,
63
- None => Err ( EmitOpArgs {
64
- node,
65
- inputs,
66
- outputs,
67
- } ) ,
68
- }
69
- }
70
-
71
- /// Specialise the internal [FatNode].
72
- ///
73
- /// Panics if `OT` is not the `get_optype` of the internal [Node].
74
- pub fn into_ot < ' b , OTInto : PartialEq + ' c > ( self , ot : & ' b OTInto ) -> EmitOpArgs < ' c , OTInto , H >
75
- where
76
- for < ' a > & ' a OpType : TryInto < & ' a OTInto > ,
77
- {
78
- let EmitOpArgs {
79
- node,
80
- inputs,
81
- outputs,
82
- } = self ;
83
- EmitOpArgs {
84
- node : node. into_ot ( ot) ,
85
- inputs,
86
- outputs,
87
- }
88
- }
89
- }
31
+ pub use args:: EmitOpArgs ;
32
+ pub use namer:: Namer ;
90
33
91
34
/// A trait used to abstract over emission.
92
35
///
@@ -111,39 +54,9 @@ impl<OT, H: HugrView> EmitOp<'_, OT, H> for NullEmitLlvm {
111
54
}
112
55
}
113
56
114
- /// A type with features for mangling the naming of symbols.
115
- ///
116
- /// TODO This is mostly a placeholder
117
- #[ derive( Clone ) ]
118
- pub struct Namer {
119
- prefix : String ,
120
- }
121
-
122
- impl Namer {
123
- /// Create a new `Namer` that for each symbol:
124
- /// * prefix `prefix`
125
- /// * postfixes ".{node.index()}"
126
- pub fn new ( prefix : impl Into < String > ) -> Self {
127
- Self {
128
- prefix : prefix. into ( ) ,
129
- }
130
- }
131
-
132
- /// Mangle the the name of a [FuncDefn] or [FuncDecl].
133
- pub fn name_func ( & self , name : impl AsRef < str > , node : Node ) -> String {
134
- format ! ( "{}{}.{}" , & self . prefix, name. as_ref( ) , node. index( ) )
135
- }
136
- }
137
-
138
- impl Default for Namer {
139
- fn default ( ) -> Self {
140
- Self :: new ( "_hl." )
141
- }
142
- }
143
-
144
57
pub struct EmitModuleContext < ' c , H : HugrView > {
145
58
module : Module < ' c > ,
146
- extension_context : Rc < CodegenExtsMap < ' c , H > > ,
59
+ extensions : Rc < CodegenExtsMap < ' c , H > > ,
147
60
typer : Rc < TypeConverter < ' c > > ,
148
61
namer : Rc < Namer > ,
149
62
}
@@ -174,13 +87,13 @@ impl<'c, H: HugrView> EmitModuleContext<'c, H> {
174
87
pub fn new (
175
88
module : Module < ' c > ,
176
89
namer : Rc < Namer > ,
177
- extension_context : Rc < CodegenExtsMap < ' c , H > > ,
90
+ extensions : Rc < CodegenExtsMap < ' c , H > > ,
178
91
typer : Rc < TypeConverter < ' c > > ,
179
92
) -> Self {
180
93
Self {
181
94
module,
182
95
namer,
183
- extension_context ,
96
+ extensions ,
184
97
typer,
185
98
}
186
99
}
@@ -194,7 +107,7 @@ impl<'c, H: HugrView> EmitModuleContext<'c, H> {
194
107
195
108
/// Returns a reference to the inner [CodegenExtsMap].
196
109
pub fn extensions ( & self ) -> Rc < CodegenExtsMap < ' c , H > > {
197
- self . extension_context . clone ( )
110
+ self . extensions . clone ( )
198
111
}
199
112
200
113
/// Returns a [TypingSession] constructed from it's members.
@@ -375,8 +288,6 @@ impl<'c, H> Clone for Emission<'c, H> {
375
288
376
289
/// Emits [HugrView]s into an LLVM [Module].
377
290
pub struct EmitHugr < ' c , H : HugrView > {
378
- // funcs: HashMap<Node, FunctionValue<'c>>,
379
- // globals: HashMap<Node, GlobalValue<'c>>,
380
291
emitted : EmissionSet < ' c , H > ,
381
292
module_context : EmitModuleContext < ' c , H > ,
382
293
}
@@ -395,19 +306,19 @@ impl<'c, H: HugrView> EmitHugr<'c, H> {
395
306
396
307
/// Creates a new `EmitHugr`. We take ownership of the [Module], and return it in [Self::finish].
397
308
pub fn new (
398
- iw_context : & ' c Context ,
309
+ context : & ' c Context ,
399
310
module : Module < ' c > ,
400
- exts : Rc < CodegenExtsMap < ' c , H > > ,
311
+ namer : Rc < Namer > ,
312
+ extensions : Rc < CodegenExtsMap < ' c , H > > ,
401
313
) -> Self {
402
- assert_eq ! ( iw_context , & module. get_context( ) ) ;
314
+ assert_eq ! ( context , & module. get_context( ) ) ;
403
315
Self {
404
- // todos: Default::default(),
405
316
emitted : Default :: default ( ) ,
406
317
module_context : EmitModuleContext :: new (
407
318
module,
408
- Default :: default ( ) ,
409
- exts ,
410
- TypeConverter :: new ( iw_context ) ,
319
+ namer ,
320
+ extensions ,
321
+ TypeConverter :: new ( context ) ,
411
322
) ,
412
323
}
413
324
}
0 commit comments