Skip to content

Commit 4e04e85

Browse files
committed
vtables are part of the function_blocks
1 parent 9615b42 commit 4e04e85

File tree

74 files changed

+1887
-1321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1887
-1321
lines changed

libs/stdlib/src/bistable_functionblocks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[repr(C)]
22
#[derive(Debug, Default)]
33
pub struct SetResetParams {
4+
__vtable: usize,
45
set: bool,
56
reset: bool,
67
output: bool,

libs/stdlib/src/counters.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::utils::Signal;
55
#[repr(C)]
66
#[derive(Debug, Default)]
77
pub struct CTUParams<T> {
8+
__vtable: usize,
89
cu: bool,
910
r: bool,
1011
pv: T,
@@ -103,6 +104,7 @@ pub extern "C" fn CTU_ULINT(params: &mut CTUParams<u64>) {
103104
#[repr(C)]
104105
#[derive(Debug, Default)]
105106
pub struct CTDParams<T> {
107+
__vtable: usize,
106108
cd: bool,
107109
ld: bool,
108110
pv: T,
@@ -201,6 +203,7 @@ pub extern "C" fn CTD_ULINT(params: &mut CTDParams<u64>) {
201203
#[repr(C)]
202204
#[derive(Debug, Default)]
203205
pub struct CTUDParams<T> {
206+
__vtable: usize,
204207
cu: bool,
205208
cd: bool,
206209
r: bool,

libs/stdlib/src/flanks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::utils::Signal;
33
#[derive(Debug, Default)]
44
#[repr(C)]
55
pub struct Trigger {
6+
__vtable: usize,
67
clk: bool,
78
output: bool,
89
internal: Signal,

libs/stdlib/src/timers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub type Time = i64;
1515
#[repr(C)]
1616
#[derive(Debug, Default)]
1717
pub struct TimerParams {
18+
__vtable: usize,
1819
input: bool,
1920
preset_time: Time,
2021
output: bool,

src/codegen/generators/expression_generator.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,17 @@ impl<'ink, 'b> ExpressionCodeGenerator<'ink, 'b> {
723723
}
724724

725725
fn generate_output_assignment(&self, context: &CallParameterAssignment) -> Result<(), Diagnostic> {
726-
let &CallParameterAssignment { assignment: expr, function_name, index, parameter_struct } = context;
726+
let &CallParameterAssignment { assignment: expr, function_name, index, parameter_struct } =
727+
dbg!(context);
727728
let builder = &self.llvm.builder;
728729

729730
// We don't want to generate any code if the right side of an assignment is empty, e.g. `foo(out =>)`
730731
if expr.is_empty_statement() {
731732
return Ok(());
732733
}
733734

734-
let parameter = self.index.get_declared_parameter(function_name, index).expect("must exist");
735+
let parameter =
736+
self.index.get_declared_parameter(dbg!(function_name), dbg!(index)).expect("must exist");
735737

736738
match expr.get_stmt() {
737739
AstStatement::ReferenceExpr(_) if expr.has_direct_access() => {
@@ -2429,7 +2431,10 @@ impl<'ink, 'b> ExpressionCodeGenerator<'ink, 'b> {
24292431
)?;
24302432
(size, 1)
24312433
}
2432-
_ => unreachable!("memcpy is not used for non-aggregate types"),
2434+
(left, right) => {
2435+
dbg!(left, right);
2436+
unreachable!("memcpy is not used for non-aggregate types")
2437+
}
24332438
};
24342439

24352440
self.llvm

src/codegen/tests/code_gen_tests.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,20 +1108,22 @@ fn fb_method_called_locally() {
11081108
; ModuleID = '<internal>'
11091109
source_filename = "<internal>"
11101110
1111-
%foo = type { i32 }
1111+
%foo = type { i32*, i32 }
11121112
1113-
@__foo__init = unnamed_addr constant %foo { i32 42 }
1113+
@__foo__init = unnamed_addr constant %foo { i32* null, i32 42 }
11141114
11151115
define void @foo(%foo* %0) {
11161116
entry:
1117-
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1117+
%__vtable = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1118+
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
11181119
%call = call i32 @foo_addToBar(%foo* %0, i16 42)
11191120
ret void
11201121
}
11211122
11221123
define i32 @foo_addToBar(%foo* %0, i16 %1) {
11231124
entry:
1124-
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1125+
%__vtable = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1126+
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
11251127
%foo.addToBar = alloca i32, align 4
11261128
%in = alloca i16, align 2
11271129
store i16 %1, i16* %in, align 2
@@ -1191,20 +1193,22 @@ fn fb_local_method_var_shadows_parent_var() {
11911193
; ModuleID = '<internal>'
11921194
source_filename = "<internal>"
11931195
1194-
%foo = type { i32 }
1196+
%foo = type { i32*, i32 }
11951197
1196-
@__foo__init = unnamed_addr constant %foo { i32 42 }
1198+
@__foo__init = unnamed_addr constant %foo { i32* null, i32 42 }
11971199
11981200
define void @foo(%foo* %0) {
11991201
entry:
1200-
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1202+
%__vtable = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1203+
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
12011204
%call = call i32 @foo_addToBar(%foo* %0, i16 42)
12021205
ret void
12031206
}
12041207
12051208
define i32 @foo_addToBar(%foo* %0, i16 %1) {
12061209
entry:
1207-
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1210+
%__vtable = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
1211+
%bar = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
12081212
%foo.addToBar = alloca i32, align 4
12091213
%in = alloca i16, align 2
12101214
store i16 %1, i16* %in, align 2
@@ -3953,9 +3957,9 @@ fn variables_in_var_external_block_are_not_generated() {
39533957
; ModuleID = '<internal>'
39543958
source_filename = "<internal>"
39553959
3956-
%bar = type {}
3960+
%bar = type { i32* }
39573961
%baz = type {}
3958-
%qux = type {}
3962+
%qux = type { i32* }
39593963
39603964
@arr = global [101 x i16] zeroinitializer
39613965
@__bar__init = unnamed_addr constant %bar zeroinitializer
@@ -3969,6 +3973,7 @@ fn variables_in_var_external_block_are_not_generated() {
39693973
39703974
define void @bar(%bar* %0) {
39713975
entry:
3976+
%__vtable = getelementptr inbounds %bar, %bar* %0, i32 0, i32 0
39723977
ret void
39733978
}
39743979
@@ -3979,6 +3984,7 @@ fn variables_in_var_external_block_are_not_generated() {
39793984
39803985
define void @qux(%qux* %0) {
39813986
entry:
3987+
%__vtable = getelementptr inbounds %qux, %qux* %0, i32 0, i32 0
39823988
ret void
39833989
}
39843990
"#);

src/codegen/tests/debug_tests.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,22 +354,24 @@ fn dbg_declare_has_valid_metadata_references_for_methods() {
354354
source_filename = "<internal>"
355355
356356
%__vtable_fb = type { i32* }
357-
%fb = type {}
357+
%fb = type { i32* }
358358
359359
@____vtable_fb__init = constant %__vtable_fb zeroinitializer, !dbg !0
360360
@__fb__init = constant %fb zeroinitializer, !dbg !8
361361
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
362362
363-
define void @fb(%fb* %0) !dbg !16 {
363+
define void @fb(%fb* %0) !dbg !17 {
364364
entry:
365-
call void @llvm.dbg.declare(metadata %fb* %0, metadata !19, metadata !DIExpression()), !dbg !20
366-
ret void, !dbg !20
365+
call void @llvm.dbg.declare(metadata %fb* %0, metadata !21, metadata !DIExpression()), !dbg !22
366+
%__vtable = getelementptr inbounds %fb, %fb* %0, i32 0, i32 0
367+
ret void, !dbg !22
367368
}
368369
369-
define void @fb_foo(%fb* %0) !dbg !21 {
370+
define void @fb_foo(%fb* %0) !dbg !23 {
370371
entry:
371-
call void @llvm.dbg.declare(metadata %fb* %0, metadata !22, metadata !DIExpression()), !dbg !23
372-
ret void, !dbg !23
372+
call void @llvm.dbg.declare(metadata %fb* %0, metadata !24, metadata !DIExpression()), !dbg !25
373+
%__vtable = getelementptr inbounds %fb, %fb* %0, i32 0, i32 0
374+
ret void, !dbg !25
373375
}
374376
375377
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
@@ -396,33 +398,35 @@ fn dbg_declare_has_valid_metadata_references_for_methods() {
396398
397399
attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
398400
399-
!llvm.module.flags = !{!12, !13}
400-
!llvm.dbg.cu = !{!14}
401+
!llvm.module.flags = !{!13, !14}
402+
!llvm.dbg.cu = !{!15}
401403
402404
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
403405
!1 = distinct !DIGlobalVariable(name: "____vtable_fb__init", scope: !2, file: !2, type: !3, isLocal: false, isDefinition: true)
404406
!2 = !DIFile(filename: "<internal>", directory: "")
405407
!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "__vtable_fb", scope: !2, file: !2, size: 64, align: 64, flags: DIFlagPublic, elements: !4, identifier: "__vtable_fb")
406408
!4 = !{!5}
407409
!5 = !DIDerivedType(tag: DW_TAG_member, name: "fb.foo", scope: !2, file: !2, baseType: !6, size: 64, align: 64, flags: DIFlagPublic)
408-
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "VOID_POINTER", baseType: !7, size: 64, align: 64, dwarfAddressSpace: 1)
410+
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__VOID_POINTER", baseType: !7, size: 64, align: 64, dwarfAddressSpace: 1)
409411
!7 = !DIBasicType(name: "__VOID", encoding: DW_ATE_unsigned, flags: DIFlagPublic)
410412
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
411413
!9 = distinct !DIGlobalVariable(name: "__fb__init", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true)
412-
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "fb", scope: !2, file: !2, line: 2, align: 64, flags: DIFlagPublic, elements: !11, identifier: "fb")
413-
!11 = !{}
414-
!12 = !{i32 2, !"Dwarf Version", i32 5}
415-
!13 = !{i32 2, !"Debug Info Version", i32 3}
416-
!14 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !15, splitDebugInlining: false)
417-
!15 = !{!8, !0}
418-
!16 = distinct !DISubprogram(name: "fb", linkageName: "fb", scope: !2, file: !2, line: 2, type: !17, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !14, retainedNodes: !11)
419-
!17 = !DISubroutineType(flags: DIFlagPublic, types: !18)
420-
!18 = !{null, !10}
421-
!19 = !DILocalVariable(name: "fb", scope: !16, file: !2, line: 5, type: !10)
422-
!20 = !DILocation(line: 5, column: 8, scope: !16)
423-
!21 = distinct !DISubprogram(name: "fb.foo", linkageName: "fb.foo", scope: !16, file: !2, line: 3, type: !17, scopeLine: 4, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !14, retainedNodes: !11)
424-
!22 = !DILocalVariable(name: "fb", scope: !21, file: !2, line: 4, type: !10)
425-
!23 = !DILocation(line: 4, column: 8, scope: !21)
414+
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "fb", scope: !2, file: !2, line: 2, size: 64, align: 64, flags: DIFlagPublic, elements: !11, identifier: "fb")
415+
!11 = !{!12}
416+
!12 = !DIDerivedType(tag: DW_TAG_member, name: "__vtable", scope: !2, file: !2, baseType: !6, size: 64, align: 64, flags: DIFlagPublic)
417+
!13 = !{i32 2, !"Dwarf Version", i32 5}
418+
!14 = !{i32 2, !"Debug Info Version", i32 3}
419+
!15 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !16, splitDebugInlining: false)
420+
!16 = !{!8, !0}
421+
!17 = distinct !DISubprogram(name: "fb", linkageName: "fb", scope: !2, file: !2, line: 2, type: !18, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !20)
422+
!18 = !DISubroutineType(flags: DIFlagPublic, types: !19)
423+
!19 = !{null, !10}
424+
!20 = !{}
425+
!21 = !DILocalVariable(name: "fb", scope: !17, file: !2, line: 5, type: !10)
426+
!22 = !DILocation(line: 5, column: 8, scope: !17)
427+
!23 = distinct !DISubprogram(name: "fb.foo", linkageName: "fb.foo", scope: !17, file: !2, line: 3, type: !18, scopeLine: 4, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !20)
428+
!24 = !DILocalVariable(name: "fb", scope: !23, file: !2, line: 4, type: !10)
429+
!25 = !DILocation(line: 4, column: 8, scope: !23)
426430
"#);
427431
}
428432

src/codegen/tests/debug_tests/expression_debugging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ fn zero_sized_types_offset_and_size_are_correct() {
358358
END_VAR
359359
END_PROGRAM
360360
361-
FUNCTION_BLOCK zeroSize
361+
PROGRAM zeroSize
362362
VAR
363363
END_VAR
364-
END_FUNCTION_BLOCK
364+
END_PROGRAM
365365
",
366366
);
367367
// We expect the element after the zero sized member to have the offset same offset as the zero sized member
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
22
source: src/codegen/tests/debug_tests/expression_debugging.rs
33
expression: result
4-
snapshot_kind: text
54
---
65
; ModuleID = '<internal>'
76
source_filename = "<internal>"
87

98
%myPrg = type {}
10-
%myFb = type {}
9+
%myFb = type { i32* }
1110

1211
@myPrg_instance = external global %myPrg, !dbg !0
1312
@__myFb__init = external global %myFb, !dbg !5
@@ -18,8 +17,8 @@ declare void @myPrg(%myPrg*)
1817

1918
declare void @myFb(%myFb*)
2019

21-
!llvm.module.flags = !{!8, !9}
22-
!llvm.dbg.cu = !{!10}
20+
!llvm.module.flags = !{!12, !13}
21+
!llvm.dbg.cu = !{!14}
2322

2423
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
2524
!1 = distinct !DIGlobalVariable(name: "myPrg", scope: !2, file: !2, line: 4, type: !3, isLocal: false, isDefinition: true)
@@ -28,9 +27,13 @@ declare void @myFb(%myFb*)
2827
!4 = !{}
2928
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
3029
!6 = distinct !DIGlobalVariable(name: "__myFb__init", scope: !2, file: !2, line: 6, type: !7, isLocal: false, isDefinition: true)
31-
!7 = !DICompositeType(tag: DW_TAG_structure_type, name: "myFb", scope: !2, file: !2, line: 6, align: 64, flags: DIFlagPublic, elements: !4, identifier: "myFb")
32-
!8 = !{i32 2, !"Dwarf Version", i32 5}
33-
!9 = !{i32 2, !"Debug Info Version", i32 3}
34-
!10 = distinct !DICompileUnit(language: DW_LANG_C, file: !11, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !12, splitDebugInlining: false)
35-
!11 = !DIFile(filename: "<internal>", directory: "src")
36-
!12 = !{!0, !5}
30+
!7 = !DICompositeType(tag: DW_TAG_structure_type, name: "myFb", scope: !2, file: !2, line: 6, size: 64, align: 64, flags: DIFlagPublic, elements: !8, identifier: "myFb")
31+
!8 = !{!9}
32+
!9 = !DIDerivedType(tag: DW_TAG_member, name: "__vtable", scope: !2, file: !2, baseType: !10, size: 64, align: 64, flags: DIFlagPublic)
33+
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__VOID_POINTER", baseType: !11, size: 64, align: 64, dwarfAddressSpace: 1)
34+
!11 = !DIBasicType(name: "__VOID", encoding: DW_ATE_unsigned, flags: DIFlagPublic)
35+
!12 = !{i32 2, !"Dwarf Version", i32 5}
36+
!13 = !{i32 2, !"Debug Info Version", i32 3}
37+
!14 = distinct !DICompileUnit(language: DW_LANG_C, file: !15, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !16, splitDebugInlining: false)
38+
!15 = !DIFile(filename: "<internal>", directory: "src")
39+
!16 = !{!0, !5}

0 commit comments

Comments
 (0)