@@ -4,6 +4,7 @@ use super::{
4
4
data_type_generator:: get_default_for,
5
5
expression_generator:: ExpressionCodeGenerator ,
6
6
llvm:: { GlobalValueExt , Llvm } ,
7
+ section_names,
7
8
statement_generator:: { FunctionContext , StatementCodeGenerator } ,
8
9
ADDRESS_SPACE_GENERIC ,
9
10
} ;
@@ -14,7 +15,7 @@ use crate::{
14
15
} ,
15
16
index:: { self , ImplementationType } ,
16
17
resolver:: { AstAnnotations , Dependency } ,
17
- typesystem:: { self , DataType , DataTypeInformation , StringEncoding , TypeSize , VarArgs } ,
18
+ typesystem:: { self , DataType , VarArgs } ,
18
19
} ;
19
20
use std:: collections:: HashMap ;
20
21
@@ -40,7 +41,7 @@ use inkwell::{
40
41
use plc_ast:: ast:: { AstNode , Implementation , PouType } ;
41
42
use plc_diagnostics:: diagnostics:: { Diagnostic , INTERNAL_LLVM_ERROR } ;
42
43
use plc_source:: source_location:: SourceLocation ;
43
- use section_mangler:: { FunctionArgument , SectionMangler , StringEncoding as SectionStringEncoding , Type } ;
44
+ use section_mangler:: { FunctionArgument , SectionMangler } ;
44
45
45
46
pub struct PouGenerator < ' ink , ' cg > {
46
47
llvm : Llvm < ' ink > ,
@@ -158,7 +159,10 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
158
159
159
160
let ctx = params. into_iter ( ) . fold ( ctx, |ctx, param| {
160
161
// FIXME: Can we unwrap here?
161
- let ty = self . mangle_type ( self . index . get_effective_type_by_name ( & param. data_type_name ) . unwrap ( ) ) ;
162
+ let ty = section_names:: mangle_type (
163
+ self . index ,
164
+ self . index . get_effective_type_by_name ( & param. data_type_name ) . unwrap ( ) ,
165
+ ) ;
162
166
let parameter = match param. argument_type {
163
167
// TODO: We need to handle the `VariableType` enum as well - this describes the mode of
164
168
// argument passing, e.g. inout
@@ -169,44 +173,14 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
169
173
ctx. with_parameter ( parameter)
170
174
} ) ;
171
175
172
- let return_ty =
173
- self . index . find_return_type ( implementation. get_type_name ( ) ) . map ( |ty| self . mangle_type ( ty) ) ;
176
+ let return_ty = self
177
+ . index
178
+ . find_return_type ( implementation. get_type_name ( ) )
179
+ . map ( |ty| section_names:: mangle_type ( self . index , ty) ) ;
174
180
175
181
ctx. with_return_type ( return_ty) . mangle ( )
176
182
}
177
183
178
- fn mangle_type ( & self , ty : & typesystem:: DataType ) -> Type {
179
- // TODO: This is a bit ugly because we keep dereferencing references to Copy types like
180
- // bool, u32, etc, because `DataTypeInformation::Pointer` keeps a `String` which is not
181
- // Copy. the alternative is for section_mangle::Type to keep references everywhere, and
182
- // have a lifetime generic parameter, e.g. `section_mangler::Type<'a>` - which is also
183
- // annoying.
184
- match ty. get_type_information ( ) {
185
- DataTypeInformation :: Void => Type :: Void ,
186
- DataTypeInformation :: Integer { signed, size, semantic_size, .. } => {
187
- Type :: Integer { signed : * signed, size : * size, semantic_size : * semantic_size }
188
- }
189
- DataTypeInformation :: Float { size, .. } => Type :: Float { size : * size } ,
190
- DataTypeInformation :: String { size : TypeSize :: LiteralInteger ( size) , encoding } => {
191
- let encoding = match encoding {
192
- StringEncoding :: Utf8 => SectionStringEncoding :: Utf8 ,
193
- StringEncoding :: Utf16 => SectionStringEncoding :: Utf16 ,
194
- } ;
195
-
196
- Type :: String { size : * size as usize , encoding }
197
- }
198
- DataTypeInformation :: Pointer { inner_type_name, .. } => Type :: Pointer {
199
- inner : Box :: new (
200
- self . mangle_type ( self . index . get_effective_type_by_name ( inner_type_name) . unwrap ( ) ) ,
201
- ) ,
202
- } ,
203
- // FIXME: For now, encode all unknown types as "void" since this is not required for
204
- // execution. Not doing so (and doing an `unreachable!()` for example) obviously causes
205
- // failures, because complex types are already implemented in the compiler.
206
- _ => Type :: Void ,
207
- }
208
- }
209
-
210
184
/// generates an empty llvm function for the given implementation, including all parameters and the return type
211
185
pub fn generate_implementation_stub (
212
186
& self ,
0 commit comments