Skip to content

Commit b85dc9b

Browse files
committed
fix: add the end keyword as a debug statement
Breakpoints can now be placed on end keywords, including end if, end_while and pou_ends. There's still an issue with stopping on the end_if after an else.
1 parent b18418e commit b85dc9b

File tree

66 files changed

+1129
-238
lines changed

Some content is hidden

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

66 files changed

+1129
-238
lines changed

compiler/plc_ast/src/ast.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub struct PropertyImplementation {
7979
pub location: SourceLocation,
8080
pub variable_blocks: Vec<VariableBlock>,
8181
pub body: Vec<AstNode>,
82+
pub end_location: SourceLocation,
8283
}
8384

8485
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -290,6 +291,7 @@ pub struct Implementation {
290291
pub statements: Vec<AstNode>,
291292
pub location: SourceLocation,
292293
pub name_location: SourceLocation,
294+
pub end_location: SourceLocation,
293295
pub overriding: bool,
294296
pub generic: bool,
295297
pub access: Option<AccessModifier>,
@@ -1442,23 +1444,30 @@ impl AstFactory {
14421444
blocks: Vec<ConditionalBlock>,
14431445
else_block: Vec<AstNode>,
14441446
location: SourceLocation,
1447+
end_location: SourceLocation,
14451448
id: AstId,
14461449
) -> AstNode {
14471450
AstNode {
1448-
stmt: AstStatement::ControlStatement(AstControlStatement::If(IfStatement { blocks, else_block })),
1451+
stmt: AstStatement::ControlStatement(AstControlStatement::If(IfStatement {
1452+
blocks,
1453+
else_block,
1454+
end_location,
1455+
})),
14491456
location,
14501457
id,
14511458
}
14521459
}
14531460

14541461
/// creates a new for loop statement
1462+
#[allow(clippy::too_many_arguments)]
14551463
pub fn create_for_loop(
14561464
counter: AstNode,
14571465
start: AstNode,
14581466
end: AstNode,
14591467
by_step: Option<AstNode>,
14601468
body: Vec<AstNode>,
14611469
location: SourceLocation,
1470+
end_location: SourceLocation,
14621471
id: AstId,
14631472
) -> AstNode {
14641473
AstNode {
@@ -1468,6 +1477,7 @@ impl AstFactory {
14681477
end: Box::new(end),
14691478
by_step: by_step.map(Box::new),
14701479
body,
1480+
end_location,
14711481
})),
14721482
location,
14731483
id,
@@ -1479,12 +1489,14 @@ impl AstFactory {
14791489
condition: AstNode,
14801490
body: Vec<AstNode>,
14811491
location: SourceLocation,
1492+
end_location: SourceLocation,
14821493
id: AstId,
14831494
) -> AstNode {
14841495
AstNode {
14851496
stmt: AstStatement::ControlStatement(AstControlStatement::WhileLoop(LoopStatement {
14861497
condition: Box::new(condition),
14871498
body,
1499+
end_location,
14881500
})),
14891501
id,
14901502
location,
@@ -1496,12 +1508,14 @@ impl AstFactory {
14961508
condition: AstNode,
14971509
body: Vec<AstNode>,
14981510
location: SourceLocation,
1511+
end_location: SourceLocation,
14991512
id: AstId,
15001513
) -> AstNode {
15011514
AstNode {
15021515
stmt: AstStatement::ControlStatement(AstControlStatement::RepeatLoop(LoopStatement {
15031516
condition: Box::new(condition),
15041517
body,
1518+
end_location,
15051519
})),
15061520
id,
15071521
location,
@@ -1514,13 +1528,15 @@ impl AstFactory {
15141528
case_blocks: Vec<ConditionalBlock>,
15151529
else_block: Vec<AstNode>,
15161530
location: SourceLocation,
1531+
end_location: SourceLocation,
15171532
id: AstId,
15181533
) -> AstNode {
15191534
AstNode {
15201535
stmt: AstStatement::ControlStatement(AstControlStatement::Case(CaseStatement {
15211536
selector: Box::new(selector),
15221537
case_blocks,
15231538
else_block,
1539+
end_location,
15241540
})),
15251541
id,
15261542
location,

compiler/plc_ast/src/control_statements.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use std::fmt::Debug;
22

3+
use plc_source::source_location::SourceLocation;
4+
35
use crate::ast::AstNode;
46

57
#[derive(Debug, Clone, PartialEq)]
68
pub struct IfStatement {
79
pub blocks: Vec<ConditionalBlock>,
810
pub else_block: Vec<AstNode>,
11+
pub end_location: SourceLocation,
912
}
1013

1114
#[derive(Debug, Clone, PartialEq)]
@@ -15,20 +18,23 @@ pub struct ForLoopStatement {
1518
pub end: Box<AstNode>,
1619
pub by_step: Option<Box<AstNode>>,
1720
pub body: Vec<AstNode>,
21+
pub end_location: SourceLocation,
1822
}
1923

2024
#[derive(Debug, Clone, PartialEq)]
2125
/// used for While and Repeat loops
2226
pub struct LoopStatement {
2327
pub condition: Box<AstNode>,
2428
pub body: Vec<AstNode>,
29+
pub end_location: SourceLocation,
2530
}
2631

2732
#[derive(Debug, Clone, PartialEq)]
2833
pub struct CaseStatement {
2934
pub selector: Box<AstNode>,
3035
pub case_blocks: Vec<ConditionalBlock>,
3136
pub else_block: Vec<AstNode>,
37+
pub end_location: SourceLocation,
3238
}
3339

3440
#[derive(Debug, Clone, PartialEq)]

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__multi_files__multiple_files_in_different_locations_with_debug_info.snap

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ entry:
1515
call void @llvm.dbg.declare(metadata i16* %main, metadata !14, metadata !DIExpression()), !dbg !16
1616
store i16 0, i16* %main, align 2
1717
call void @mainProg(%mainProg* @mainProg_instance), !dbg !17
18-
%main_ret = load i16, i16* %main, align 2, !dbg !17
19-
ret i16 %main_ret, !dbg !17
18+
%main_ret = load i16, i16* %main, align 2, !dbg !18
19+
ret i16 %main_ret, !dbg !18
2020
}
2121

22-
declare !dbg !18 void @mainProg(%mainProg*)
22+
declare !dbg !19 void @mainProg(%mainProg*)
2323

2424
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
2525
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
@@ -47,9 +47,10 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4747
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
4848
!16 = !DILocation(line: 2, column: 13, scope: !10)
4949
!17 = !DILocation(line: 10, column: 4, scope: !10)
50-
!18 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !2, file: !2, line: 2, type: !19, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
51-
!19 = !DISubroutineType(flags: DIFlagPublic, types: !20)
52-
!20 = !{null, !3}
50+
!18 = !DILocation(line: 11, column: 4, scope: !10)
51+
!19 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !2, file: !2, line: 2, type: !20, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
52+
!20 = !DISubroutineType(flags: DIFlagPublic, types: !21)
53+
!21 = !{null, !3}
5354

5455
; ModuleID = 'lib/file2.st'
5556
source_filename = "lib/file2.st"

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__multi_files__multiple_files_with_debug_info.snap

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ entry:
1515
call void @llvm.dbg.declare(metadata i16* %main, metadata !14, metadata !DIExpression()), !dbg !16
1616
store i16 0, i16* %main, align 2
1717
call void @mainProg(%mainProg* @mainProg_instance), !dbg !17
18-
%main_ret = load i16, i16* %main, align 2, !dbg !17
19-
ret i16 %main_ret, !dbg !17
18+
%main_ret = load i16, i16* %main, align 2, !dbg !18
19+
ret i16 %main_ret, !dbg !18
2020
}
2121

22-
declare !dbg !18 void @mainProg(%mainProg*)
22+
declare !dbg !19 void @mainProg(%mainProg*)
2323

2424
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
2525
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
@@ -47,9 +47,10 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4747
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
4848
!16 = !DILocation(line: 2, column: 13, scope: !10)
4949
!17 = !DILocation(line: 10, column: 4, scope: !10)
50-
!18 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !2, file: !2, line: 2, type: !19, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
51-
!19 = !DISubroutineType(flags: DIFlagPublic, types: !20)
52-
!20 = !{null, !3}
50+
!18 = !DILocation(line: 11, column: 4, scope: !10)
51+
!19 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !2, file: !2, line: 2, type: !20, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
52+
!20 = !DISubroutineType(flags: DIFlagPublic, types: !21)
53+
!21 = !{null, !3}
5354

5455
; ModuleID = 'file2.st'
5556
source_filename = "file2.st"

0 commit comments

Comments
 (0)