Skip to content

Commit 23ffab7

Browse files
committed
test: fix failing tests introduced with previous commit
1 parent c8fd17d commit 23ffab7

File tree

74 files changed

+4924
-2056
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

+4924
-2056
lines changed

compiler/plc_ast/src/pre_processor.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ fn process_global_variables(unit: &mut CompilationUnit, id_provider: &mut IdProv
196196
}
197197

198198
fn process_var_config_variables(unit: &mut CompilationUnit) {
199-
let block = get_internal_global_block(unit);
200199
let variables = unit.var_config.iter().filter_map(|ConfigVariable { data_type, address, .. }| {
201200
let AstStatement::HardwareAccess(hardware) = &address.stmt else {
202201
unreachable!("Must be parsed as hardware access")
@@ -206,10 +205,12 @@ fn process_var_config_variables(unit: &mut CompilationUnit) {
206205
return None;
207206
}
208207

208+
// Check if the mangled variable already exists in any of the global variable blocks
209+
// XXX: Not a fan of this, we should fix the underlying issue with variable block creation here...
209210
let name = hardware.get_mangled_variable_name();
210-
if block.is_some_and(|it| it.variables.iter().any(|v| v.name == name)) {
211-
return None;
212-
};
211+
if find_mangled_variable(unit, &name) {
212+
return None; // Already exists, skip
213+
}
213214

214215
Some(Variable {
215216
name,
@@ -220,7 +221,7 @@ fn process_var_config_variables(unit: &mut CompilationUnit) {
220221
})
221222
});
222223

223-
update_generated_globals(unit, variables.collect())
224+
update_generated_globals(unit, variables.collect());
224225
}
225226

226227
fn update_generated_globals(unit: &mut CompilationUnit, mangled_globals: Vec<Variable>) {
@@ -242,11 +243,8 @@ fn update_generated_globals(unit: &mut CompilationUnit, mangled_globals: Vec<Var
242243
unit.global_vars.push(block);
243244
}
244245

245-
fn get_internal_global_block(unit: &CompilationUnit) -> Option<&VariableBlock> {
246-
unit.global_vars
247-
.iter()
248-
.position(|block| block.kind == VariableBlockType::Global && block.location.is_builtin_internal())
249-
.and_then(|index| unit.global_vars.get(index))
246+
fn find_mangled_variable(unit: &CompilationUnit, name: &str) -> bool {
247+
unit.global_vars.iter().flat_map(|block| &block.variables).any(|var| var.name == name)
250248
}
251249

252250
fn build_enum_initializer(

compiler/plc_driver/src/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn compile<T: Compilable>(codegen_context: &CodegenContext, source: T) -> Ge
6666
pub fn compile_and_run<T, U, S: Compilable>(source: S, params: &mut T) -> U {
6767
let context: CodegenContext = CodegenContext::create();
6868
let module = compile(&context, source);
69-
module.print_to_stderr();
69+
// module.print_to_stderr();
7070
module.run::<T, U>("main", params)
7171
}
7272

@@ -77,6 +77,6 @@ pub fn compile_and_run<T, U, S: Compilable>(source: S, params: &mut T) -> U {
7777
pub fn compile_and_run_no_params<U, S: Compilable>(source: S) -> U {
7878
let context: CodegenContext = CodegenContext::create();
7979
let module = compile(&context, source);
80-
module.print_to_stderr();
80+
// module.print_to_stderr();
8181
module.run_no_param::<U>("main")
8282
}

compiler/plc_driver/src/tests/multi_files.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn forward_declared_constant_is_also_marked_constant() {
159159
let results = compile_with_root(vec![src1, src2], vec![], "root", DebugLevel::Full(5)).unwrap();
160160

161161
// THEN the constant is marked as constant in the generated code
162-
filtered_assert_snapshot!(results.join("\n"), @r###"
162+
filtered_assert_snapshot!(results.join("\n"), @r#"
163163
; ModuleID = 'external_file1.st'
164164
source_filename = "external_file1.st"
165165
target datalayout = "[filtered]"
@@ -194,9 +194,9 @@ fn forward_declared_constant_is_also_marked_constant() {
194194
195195
declare void @__init_foo(%foo*)
196196
197-
declare !dbg !24 void @__user_init_foo(%foo*)
197+
declare void @__user_init_foo(%foo*)
198198
199-
declare !dbg !29 void @mainProg(%mainProg*)
199+
declare !dbg !24 void @mainProg(%mainProg*)
200200
201201
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
202202
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
@@ -234,17 +234,12 @@ fn forward_declared_constant_is_also_marked_constant() {
234234
!21 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !11, file: !11, line: 12, type: !22, scopeLine: 16, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
235235
!22 = !DISubroutineType(flags: DIFlagPublic, types: !23)
236236
!23 = !{null, !10}
237-
!24 = distinct !DISubprogram(name: "__user_init_foo", linkageName: "__user_init_foo", scope: !25, file: !25, type: !26, scopeLine: 1, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
238-
!25 = !DIFile(filename: "__initializers", directory: "")
239-
!26 = !DISubroutineType(flags: DIFlagPublic, types: !27)
240-
!27 = !{null, !28}
241-
!28 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__auto_pointer_to_foo", baseType: !10, size: 64, align: 64, dwarfAddressSpace: 1)
242-
!29 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !11, file: !11, line: 6, type: !30, scopeLine: 10, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
243-
!30 = !DISubroutineType(flags: DIFlagPublic, types: !31)
244-
!31 = !{null, !32, !14}
245-
!32 = !DICompositeType(tag: DW_TAG_structure_type, name: "mainProg", scope: !11, file: !11, line: 6, size: 16, align: 64, flags: DIFlagPublic, elements: !33, identifier: "mainProg")
246-
!33 = !{!34}
247-
!34 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !11, line: 8, baseType: !14, size: 16, align: 16, flags: DIFlagPublic)
237+
!24 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !11, file: !11, line: 6, type: !25, scopeLine: 10, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
238+
!25 = !DISubroutineType(flags: DIFlagPublic, types: !26)
239+
!26 = !{null, !27, !14}
240+
!27 = !DICompositeType(tag: DW_TAG_structure_type, name: "mainProg", scope: !11, file: !11, line: 6, size: 16, align: 64, flags: DIFlagPublic, elements: !28, identifier: "mainProg")
241+
!28 = !{!29}
242+
!29 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !11, line: 8, baseType: !14, size: 16, align: 16, flags: DIFlagPublic)
248243
249244
; ModuleID = 'external_file2.st'
250245
source_filename = "external_file2.st"
@@ -380,5 +375,5 @@ fn forward_declared_constant_is_also_marked_constant() {
380375
declare void @mainProg(%mainProg*)
381376
382377
declare void @__user_init_mainProg(%mainProg*)
383-
"###);
378+
"#);
384379
}

compiler/plc_source/src/source_location.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,18 @@ impl SourceLocation {
413413
}
414414

415415
pub fn is_internal(&self) -> bool {
416-
self.file.is_internal()
416+
matches!(self.file, FileMarker::Internal(_)) | matches!(self.span, CodeSpan::None)
417417
}
418418

419419
pub fn is_builtin_internal(&self) -> bool {
420420
self.file.is_internal() && self.span == CodeSpan::None
421421
}
422422

423+
// TODO: hmm, we definitely need at least one more is_internal function; fix before merge
424+
pub fn is_internal_the_100th(&self) -> bool {
425+
self.span == CodeSpan::None
426+
}
427+
423428
pub fn is_in_unit(&self, unit: impl AsRef<str>) -> bool {
424429
if let Some(filename) = self.get_file_name() {
425430
filename == unit.as_ref()

libs/stdlib/src/bistable_functionblocks.rs

Lines changed: 27 additions & 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,
@@ -12,6 +13,21 @@ impl SetResetParams {
1213
}
1314
}
1415

16+
#[repr(C)]
17+
pub struct VTable {
18+
pub body: extern "C" fn(&mut SetResetParams),
19+
}
20+
21+
#[allow(non_upper_case_globals)]
22+
#[no_mangle]
23+
#[used]
24+
pub static __vtable_SR: VTable = VTable { body: SR };
25+
26+
#[allow(non_upper_case_globals)]
27+
#[no_mangle]
28+
#[used]
29+
pub static __SR__init: SetResetParams =
30+
SetResetParams { __vtable: 0, set: false, reset: false, output: false };
1531
///.
1632
/// Bistable function, set dominant
1733
///
@@ -21,6 +37,17 @@ pub extern "C" fn SR(params: &mut SetResetParams) {
2137
params.set_output(params.set | (!params.reset & params.output));
2238
}
2339

40+
#[allow(non_upper_case_globals)]
41+
#[no_mangle]
42+
#[used]
43+
pub static __vtable_RS: VTable = VTable { body: RS };
44+
45+
#[allow(non_upper_case_globals)]
46+
#[no_mangle]
47+
#[used]
48+
pub static __RS__init: SetResetParams =
49+
SetResetParams { __vtable: 0, set: false, reset: false, output: false };
50+
2451
///.
2552
/// Bistable function, reset dominant
2653
///

0 commit comments

Comments
 (0)