Skip to content

Commit c348132

Browse files
volsaghaith
authored andcommitted
fix: Avoid vtable entries being removed
1 parent 189202c commit c348132

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

compiler/plc_driver/src/pipelines/participant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use plc::{
1717
index::{ArgumentType, PouIndexEntry, VariableIndexEntry},
1818
lowering::calls::AggregateTypeLowerer,
1919
output::FormatOption,
20-
typesystem::{DataType, DataTypeInformation, VOID_TYPE},
20+
typesystem::{DataType, DataTypeInformation, VOID_INTERNAL_NAME, VOID_TYPE},
2121
ConfigFormat, OnlineChange, Target,
2222
};
2323
use plc_diagnostics::diagnostics::Diagnostic;
@@ -289,7 +289,6 @@ impl PipelineParticipantMut for AggregateTypeLowerer {
289289
pub struct VTableIndexer;
290290

291291
impl VTableIndexer {
292-
293292
fn get_vtable_name(name: &str) -> String {
294293
format!("__vtable_{name}")
295294
}
@@ -300,7 +299,7 @@ impl VTableIndexer {
300299
let entry = VariableIndexEntry::new(
301300
method.get_name(),
302301
method.get_name(),
303-
VOID_TYPE,
302+
VOID_INTERNAL_NAME,
304303
ArgumentType::ByRef(plc::index::VariableType::Local),
305304
index as u32,
306305
SourceLocation::internal(),
@@ -325,7 +324,7 @@ impl VTableIndexer {
325324
}
326325

327326
impl PipelineParticipantMut for VTableIndexer {
328-
fn post_index(&mut self, indexed_project: IndexedProject) -> IndexedProject {
327+
fn pre_annotate(&mut self, indexed_project: IndexedProject) -> IndexedProject {
329328
//For each class or interface, create a vtable type
330329
//and add it to the index
331330
let IndexedProject { project, index, unresolvables } = indexed_project;
@@ -346,6 +345,7 @@ impl PipelineParticipantMut for VTableIndexer {
346345
for vtable in vtables {
347346
index.register_type(vtable);
348347
}
348+
349349
IndexedProject { project, index, unresolvables }
350350
}
351351
}

src/codegen/generators/data_type_generator.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,33 @@ pub fn generate_data_types<'ink>(
6565
}
6666

6767
for dep in dependencies {
68-
if let Some(pou) = dep.get_pou(index) {
69-
if !pou.is_generic() && !pou.is_action() {
70-
pou_types.push((dep.get_name(), pou.get_instance_struct_type_or_void(index)));
71-
}
72-
} else if let Some(datatype) = dep.get_type(index) {
73-
if !datatype.get_type_information().is_generic(index) {
74-
types.push((dep.get_name(), datatype))
75-
}
68+
if let Some(pou) = dep.get_pou(index) {
69+
if !pou.is_generic() && !pou.is_action() {
70+
pou_types.push((dep.get_name(), pou.get_instance_struct_type_or_void(index)));
7671
}
77-
if let Some(datatype) = dep.get_vtable(index) {
78-
if !datatype.get_type_information().is_generic(index) {
79-
types.push((dep.get_name(), datatype))
80-
}
72+
} else if let Some(datatype) = dep.get_type(index) {
73+
if !datatype.get_type_information().is_generic(index) {
74+
types.push((dep.get_name(), datatype))
75+
}
76+
}
77+
78+
if let Some(datatype) = dbg!(dep.get_vtable(index)) {
79+
if !datatype.get_type_information().is_generic(index) {
80+
types.push((datatype.get_name(), datatype))
8181
}
82+
}
8283
}
8384

8485
let mut generator =
8586
DataTypeGenerator { llvm, debug, index, annotations, types_index: LlvmTypedIndex::default() };
8687

88+
// dbg!(&types);
8789
// first create all STUBs for struct types (empty structs)
8890
// and associate them in the llvm index
8991
for (name, user_type) in &types {
92+
if *name == "__vtable_fb" {
93+
eprintln!("hi")
94+
}
9095
if let DataTypeInformation::Struct { name: struct_name, .. } = user_type.get_type_information() {
9196
generator.types_index.associate_type(name, llvm.create_struct_stub(struct_name).into())?;
9297
}

0 commit comments

Comments
 (0)