@@ -153,33 +153,37 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
153
153
PouGenerator { llvm, index, annotations, llvm_index }
154
154
}
155
155
156
- fn mangle_function ( & self , implementation : & ImplementationIndexEntry ) -> String {
156
+ fn mangle_function ( & self , implementation : & ImplementationIndexEntry ) -> Result < String , Diagnostic > {
157
157
let ctx = SectionMangler :: function ( implementation. get_call_name ( ) ) ;
158
158
159
159
let params = self . index . get_declared_parameters ( implementation. get_call_name ( ) ) ;
160
160
161
- let ctx = params. into_iter ( ) . fold ( ctx, |ctx, param| {
162
- // FIXME: Can we unwrap here?
161
+ let ctx = params. into_iter ( ) . try_fold ( ctx, |ctx, param| -> Result < SectionMangler , Diagnostic > {
163
162
let ty = section_names:: mangle_type (
164
163
self . index ,
165
- self . index . get_effective_type_by_name ( & param. data_type_name ) . unwrap ( ) ,
166
- ) ;
164
+ self . index . get_effective_type_by_name ( & param. data_type_name ) ? ,
165
+ ) ? ;
167
166
let parameter = match param. argument_type {
168
167
// TODO: We need to handle the `VariableType` enum as well - this describes the mode of
169
168
// argument passing, e.g. inout
170
169
index:: ArgumentType :: ByVal ( _) => FunctionArgument :: ByValue ( ty) ,
171
170
index:: ArgumentType :: ByRef ( _) => FunctionArgument :: ByRef ( ty) ,
172
171
} ;
173
172
174
- ctx. with_parameter ( parameter)
175
- } ) ;
173
+ Ok ( ctx. with_parameter ( parameter) )
174
+ } ) ? ;
176
175
177
176
let return_ty = self
178
177
. index
179
178
. find_return_type ( implementation. get_type_name ( ) )
180
179
. map ( |ty| section_names:: mangle_type ( self . index , ty) ) ;
181
180
182
- ctx. with_return_type ( return_ty) . mangle ( )
181
+ let ctx = match return_ty {
182
+ Some ( rty) => ctx. with_return_type ( rty?) ,
183
+ None => ctx,
184
+ } ;
185
+
186
+ Ok ( ctx. mangle ( ) )
183
187
}
184
188
185
189
/// generates an empty llvm function for the given implementation, including all parameters and the return type
@@ -281,7 +285,7 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
281
285
282
286
let curr_f = module. add_function ( implementation. get_call_name ( ) , function_declaration, None ) ;
283
287
284
- let section_name = self . mangle_function ( implementation) ;
288
+ let section_name = self . mangle_function ( implementation) ? ;
285
289
curr_f. set_section ( Some ( & section_name) ) ;
286
290
287
291
let pou_name = implementation. get_call_name ( ) ;
0 commit comments