1
1
// Copyright (c) 2020 Ghaith Hachem and Mathias Rieder
2
2
use inkwell:: types:: { AnyTypeEnum , BasicType , BasicTypeEnum , PointerType } ;
3
- use inkwell:: values:: { BasicValueEnum , FunctionValue , GlobalValue , PointerValue } ;
3
+ use inkwell:: values:: { AnyValue , BasicValueEnum , FunctionValue , GlobalValue , PointerValue } ;
4
4
use inkwell:: AddressSpace ;
5
5
use plc_diagnostics:: diagnostics:: Diagnostic ;
6
6
use plc_source:: source_location:: SourceLocation ;
@@ -111,7 +111,10 @@ impl<'ink> LlvmTypedIndex<'ink> {
111
111
type_name : & str ,
112
112
target_type : AnyTypeEnum < ' ink > ,
113
113
) -> Result < ( ) , Diagnostic > {
114
- self . type_associations . insert ( type_name. to_lowercase ( ) , target_type) ;
114
+ let name = type_name. to_lowercase ( ) ;
115
+
116
+ log:: debug!( "registered `{name}` as type `{}`" , target_type. print_to_string( ) ) ;
117
+ self . type_associations . insert ( name, target_type) ;
115
118
Ok ( ( ) )
116
119
}
117
120
@@ -120,7 +123,10 @@ impl<'ink> LlvmTypedIndex<'ink> {
120
123
type_name : & str ,
121
124
target_type : AnyTypeEnum < ' ink > ,
122
125
) -> Result < ( ) , Diagnostic > {
123
- self . pou_type_associations . insert ( type_name. to_lowercase ( ) , target_type) ;
126
+ let name = type_name. to_lowercase ( ) ;
127
+
128
+ log:: debug!( "registered `{name}` as POU type `{}`" , target_type. print_to_string( ) ) ;
129
+ self . pou_type_associations . insert ( name, target_type) ;
124
130
Ok ( ( ) )
125
131
}
126
132
@@ -129,7 +135,10 @@ impl<'ink> LlvmTypedIndex<'ink> {
129
135
type_name : & str ,
130
136
initial_value : BasicValueEnum < ' ink > ,
131
137
) -> Result < ( ) , Diagnostic > {
132
- self . initial_value_associations . insert ( type_name. to_lowercase ( ) , initial_value) ;
138
+ let name = type_name. to_lowercase ( ) ;
139
+
140
+ log:: debug!( "registered `{name}` as initial value type `{}`" , initial_value. print_to_string( ) ) ;
141
+ self . initial_value_associations . insert ( name, initial_value) ;
133
142
Ok ( ( ) )
134
143
}
135
144
@@ -139,8 +148,62 @@ impl<'ink> LlvmTypedIndex<'ink> {
139
148
variable_name : & str ,
140
149
target_value : PointerValue < ' ink > ,
141
150
) -> Result < ( ) , Diagnostic > {
142
- let qualified_name = qualified_name ( container_name, variable_name) ;
143
- self . loaded_variable_associations . insert ( qualified_name. to_lowercase ( ) , target_value) ;
151
+ let name = qualified_name ( container_name, variable_name) . to_lowercase ( ) ;
152
+
153
+ log:: debug!( "registered `{name}` as loaded local type `{}`" , target_value. print_to_string( ) ) ;
154
+ self . loaded_variable_associations . insert ( name, target_value) ;
155
+ Ok ( ( ) )
156
+ }
157
+
158
+ pub fn associate_global (
159
+ & mut self ,
160
+ variable_name : & str ,
161
+ global_variable : GlobalValue < ' ink > ,
162
+ ) -> Result < ( ) , Diagnostic > {
163
+ let name = variable_name. to_lowercase ( ) ;
164
+
165
+ log:: debug!( "registered `{name}` as global variable type `{}`" , global_variable. print_to_string( ) ) ;
166
+ self . global_values . insert ( name. clone ( ) , global_variable) ;
167
+ self . initial_value_associations . insert ( name, global_variable. as_pointer_value ( ) . into ( ) ) ;
168
+
169
+ // FIXME: Do we want to call .insert_new_got_index() here?
170
+ Ok ( ( ) )
171
+ }
172
+
173
+ pub fn associate_implementation (
174
+ & mut self ,
175
+ callable_name : & str ,
176
+ function_value : FunctionValue < ' ink > ,
177
+ ) -> Result < ( ) , Diagnostic > {
178
+ let name = callable_name. to_lowercase ( ) ;
179
+
180
+ log:: debug!( "registered `{name}` as implementation type `{}`" , function_value. print_to_string( ) ) ;
181
+ self . implementations . insert ( name, function_value) ;
182
+
183
+ Ok ( ( ) )
184
+ }
185
+
186
+ pub fn associate_utf08_literal ( & mut self , literal : & str , literal_variable : GlobalValue < ' ink > ) {
187
+ log:: debug!( "registered literal {literal}" ) ;
188
+ self . utf08_literals . insert ( literal. to_string ( ) , literal_variable) ;
189
+ }
190
+
191
+ pub fn associate_utf16_literal ( & mut self , literal : & str , literal_variable : GlobalValue < ' ink > ) {
192
+ log:: debug!( "registered literal {literal}" ) ;
193
+ self . utf16_literals . insert ( literal. to_string ( ) , literal_variable) ;
194
+ }
195
+
196
+ pub fn associate_got_index ( & mut self , variable_name : & str , index : u64 ) -> Result < ( ) , Diagnostic > {
197
+ let name = variable_name. to_lowercase ( ) ;
198
+ self . got_indices . insert ( name, index) ;
199
+
200
+ Ok ( ( ) )
201
+ }
202
+
203
+ pub fn insert_new_got_index ( & mut self , variable_name : & str ) -> Result < ( ) , Diagnostic > {
204
+ let idx = self . got_indices . values ( ) . max ( ) . copied ( ) . unwrap_or ( 0 ) ;
205
+ self . got_indices . insert ( variable_name. to_lowercase ( ) , idx) ;
206
+
144
207
Ok ( ( ) )
145
208
}
146
209
@@ -192,42 +255,6 @@ impl<'ink> LlvmTypedIndex<'ink> {
192
255
. or_else ( || self . parent_index . and_then ( |it| it. find_associated_initial_value ( type_name) ) )
193
256
}
194
257
195
- pub fn associate_global (
196
- & mut self ,
197
- variable_name : & str ,
198
- global_variable : GlobalValue < ' ink > ,
199
- ) -> Result < ( ) , Diagnostic > {
200
- self . global_values . insert ( variable_name. to_lowercase ( ) , global_variable) ;
201
- self . initial_value_associations
202
- . insert ( variable_name. to_lowercase ( ) , global_variable. as_pointer_value ( ) . into ( ) ) ;
203
-
204
- // FIXME: Do we want to call .insert_new_got_index() here?
205
-
206
- Ok ( ( ) )
207
- }
208
-
209
- pub fn associate_got_index ( & mut self , variable_name : & str , index : u64 ) -> Result < ( ) , Diagnostic > {
210
- self . got_indices . insert ( variable_name. to_lowercase ( ) , index) ;
211
- Ok ( ( ) )
212
- }
213
-
214
- pub fn insert_new_got_index ( & mut self , variable_name : & str ) -> Result < ( ) , Diagnostic > {
215
- let idx = self . got_indices . values ( ) . max ( ) . copied ( ) . unwrap_or ( 0 ) ;
216
-
217
- self . got_indices . insert ( variable_name. to_lowercase ( ) , idx) ;
218
-
219
- Ok ( ( ) )
220
- }
221
-
222
- pub fn associate_implementation (
223
- & mut self ,
224
- callable_name : & str ,
225
- function_value : FunctionValue < ' ink > ,
226
- ) -> Result < ( ) , Diagnostic > {
227
- self . implementations . insert ( callable_name. to_lowercase ( ) , function_value) ;
228
- Ok ( ( ) )
229
- }
230
-
231
258
pub fn find_associated_implementation ( & self , callable_name : & str ) -> Option < FunctionValue < ' ink > > {
232
259
self . implementations
233
260
. get ( & callable_name. to_lowercase ( ) )
@@ -260,20 +287,12 @@ impl<'ink> LlvmTypedIndex<'ink> {
260
287
self . constants . get ( qualified_name) . copied ( )
261
288
}
262
289
263
- pub fn associate_utf08_literal ( & mut self , literal : & str , literal_variable : GlobalValue < ' ink > ) {
264
- self . utf08_literals . insert ( literal. to_string ( ) , literal_variable) ;
265
- }
266
-
267
290
pub fn find_utf08_literal_string ( & self , literal : & str ) -> Option < & GlobalValue < ' ink > > {
268
291
self . utf08_literals
269
292
. get ( literal)
270
293
. or_else ( || self . parent_index . and_then ( |it| it. find_utf08_literal_string ( literal) ) )
271
294
}
272
295
273
- pub fn associate_utf16_literal ( & mut self , literal : & str , literal_variable : GlobalValue < ' ink > ) {
274
- self . utf16_literals . insert ( literal. to_string ( ) , literal_variable) ;
275
- }
276
-
277
296
pub fn find_utf16_literal_string ( & self , literal : & str ) -> Option < & GlobalValue < ' ink > > {
278
297
self . utf16_literals
279
298
. get ( literal)
0 commit comments