Skip to content

Commit f5ab238

Browse files
authored
Merge pull request #1430 from PLC-lang/debug_fixes
fix: debug for init variables and end_xxx blocks
2 parents da17446 + 20a03b9 commit f5ab238

File tree

70 files changed

+1488
-706
lines changed

Some content is hidden

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

70 files changed

+1488
-706
lines changed

compiler/plc_ast/src/ast.rs

Lines changed: 13 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use serde::{Deserialize, Serialize};
1010

1111
use crate::{
1212
control_statements::{
13-
AstControlStatement, CaseStatement, ConditionalBlock, ForLoopStatement, IfStatement, LoopStatement,
14-
ReturnStatement,
13+
AstControlStatement, CaseStatement, ForLoopStatement, IfStatement, LoopStatement, ReturnStatement,
1514
},
1615
literals::{AstLiteral, StringValue},
1716
pre_processor,
@@ -80,6 +79,7 @@ pub struct PropertyImplementation {
8079
pub location: SourceLocation,
8180
pub variable_blocks: Vec<VariableBlock>,
8281
pub body: Vec<AstNode>,
82+
pub end_location: SourceLocation,
8383
}
8484

8585
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -291,6 +291,7 @@ pub struct Implementation {
291291
pub statements: Vec<AstNode>,
292292
pub location: SourceLocation,
293293
pub name_location: SourceLocation,
294+
pub end_location: SourceLocation,
294295
pub overriding: bool,
295296
pub generic: bool,
296297
pub access: Option<AccessModifier>,
@@ -1465,93 +1466,28 @@ impl AstFactory {
14651466
}
14661467

14671468
/// creates a new if-statement
1468-
pub fn create_if_statement(
1469-
blocks: Vec<ConditionalBlock>,
1470-
else_block: Vec<AstNode>,
1471-
location: SourceLocation,
1472-
id: AstId,
1473-
) -> AstNode {
1474-
AstNode {
1475-
stmt: AstStatement::ControlStatement(AstControlStatement::If(IfStatement { blocks, else_block })),
1476-
location,
1477-
id,
1478-
}
1469+
pub fn create_if_statement(stmt: IfStatement, location: SourceLocation, id: AstId) -> AstNode {
1470+
AstNode { stmt: AstStatement::ControlStatement(AstControlStatement::If(stmt)), location, id }
14791471
}
14801472

14811473
/// creates a new for loop statement
1482-
pub fn create_for_loop(
1483-
counter: AstNode,
1484-
start: AstNode,
1485-
end: AstNode,
1486-
by_step: Option<AstNode>,
1487-
body: Vec<AstNode>,
1488-
location: SourceLocation,
1489-
id: AstId,
1490-
) -> AstNode {
1491-
AstNode {
1492-
stmt: AstStatement::ControlStatement(AstControlStatement::ForLoop(ForLoopStatement {
1493-
counter: Box::new(counter),
1494-
start: Box::new(start),
1495-
end: Box::new(end),
1496-
by_step: by_step.map(Box::new),
1497-
body,
1498-
})),
1499-
location,
1500-
id,
1501-
}
1474+
pub fn create_for_loop(stmt: ForLoopStatement, location: SourceLocation, id: AstId) -> AstNode {
1475+
AstNode { stmt: AstStatement::ControlStatement(AstControlStatement::ForLoop(stmt)), location, id }
15021476
}
15031477

15041478
/// creates a new while statement
1505-
pub fn create_while_statement(
1506-
condition: AstNode,
1507-
body: Vec<AstNode>,
1508-
location: SourceLocation,
1509-
id: AstId,
1510-
) -> AstNode {
1511-
AstNode {
1512-
stmt: AstStatement::ControlStatement(AstControlStatement::WhileLoop(LoopStatement {
1513-
condition: Box::new(condition),
1514-
body,
1515-
})),
1516-
id,
1517-
location,
1518-
}
1479+
pub fn create_while_statement(stmt: LoopStatement, location: SourceLocation, id: AstId) -> AstNode {
1480+
AstNode { stmt: AstStatement::ControlStatement(AstControlStatement::WhileLoop(stmt)), id, location }
15191481
}
15201482

15211483
/// creates a new repeat-statement
1522-
pub fn create_repeat_statement(
1523-
condition: AstNode,
1524-
body: Vec<AstNode>,
1525-
location: SourceLocation,
1526-
id: AstId,
1527-
) -> AstNode {
1528-
AstNode {
1529-
stmt: AstStatement::ControlStatement(AstControlStatement::RepeatLoop(LoopStatement {
1530-
condition: Box::new(condition),
1531-
body,
1532-
})),
1533-
id,
1534-
location,
1535-
}
1484+
pub fn create_repeat_statement(stmt: LoopStatement, location: SourceLocation, id: AstId) -> AstNode {
1485+
AstNode { stmt: AstStatement::ControlStatement(AstControlStatement::RepeatLoop(stmt)), id, location }
15361486
}
15371487

15381488
/// creates a new case-statement
1539-
pub fn create_case_statement(
1540-
selector: AstNode,
1541-
case_blocks: Vec<ConditionalBlock>,
1542-
else_block: Vec<AstNode>,
1543-
location: SourceLocation,
1544-
id: AstId,
1545-
) -> AstNode {
1546-
AstNode {
1547-
stmt: AstStatement::ControlStatement(AstControlStatement::Case(CaseStatement {
1548-
selector: Box::new(selector),
1549-
case_blocks,
1550-
else_block,
1551-
})),
1552-
id,
1553-
location,
1554-
}
1489+
pub fn create_case_statement(stmt: CaseStatement, location: SourceLocation, id: AstId) -> AstNode {
1490+
AstNode { stmt: AstStatement::ControlStatement(AstControlStatement::Case(stmt)), id, location }
15551491
}
15561492

15571493
/// creates an or-expression

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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ source_filename = "app/file1.st"
1111

1212
define i16 @main() !dbg !10 {
1313
entry:
14-
%main = alloca i16, align 2, !dbg !14
15-
call void @llvm.dbg.declare(metadata i16* %main, metadata !15, metadata !DIExpression()), !dbg !17
16-
store i16 0, i16* %main, align 2, !dbg !14
17-
call void @mainProg(%mainProg* @mainProg_instance), !dbg !14
18-
%main_ret = load i16, i16* %main, align 2, !dbg !14
19-
ret i16 %main_ret, !dbg !14
14+
%main = alloca i16, align 2
15+
call void @llvm.dbg.declare(metadata i16* %main, metadata !14, metadata !DIExpression()), !dbg !16
16+
store i16 0, i16* %main, align 2
17+
call void @mainProg(%mainProg* @mainProg_instance), !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
@@ -43,13 +43,14 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4343
!11 = !DIFile(filename: "file1.st", directory: "app")
4444
!12 = !DISubroutineType(flags: DIFlagPublic, types: !13)
4545
!13 = !{null}
46-
!14 = !DILocation(line: 10, column: 4, scope: !10)
47-
!15 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !16, align: 16)
48-
!16 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
49-
!17 = !DILocation(line: 2, column: 13, 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}
46+
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15, align: 16)
47+
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
48+
!16 = !DILocation(line: 2, column: 13, scope: !10)
49+
!17 = !DILocation(line: 10, column: 4, scope: !10)
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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ source_filename = "file1.st"
1111

1212
define i16 @main() !dbg !10 {
1313
entry:
14-
%main = alloca i16, align 2, !dbg !14
15-
call void @llvm.dbg.declare(metadata i16* %main, metadata !15, metadata !DIExpression()), !dbg !17
16-
store i16 0, i16* %main, align 2, !dbg !14
17-
call void @mainProg(%mainProg* @mainProg_instance), !dbg !14
18-
%main_ret = load i16, i16* %main, align 2, !dbg !14
19-
ret i16 %main_ret, !dbg !14
14+
%main = alloca i16, align 2
15+
call void @llvm.dbg.declare(metadata i16* %main, metadata !14, metadata !DIExpression()), !dbg !16
16+
store i16 0, i16* %main, align 2
17+
call void @mainProg(%mainProg* @mainProg_instance), !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
@@ -43,13 +43,14 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4343
!11 = !DIFile(filename: "file1.st", directory: "")
4444
!12 = !DISubroutineType(flags: DIFlagPublic, types: !13)
4545
!13 = !{null}
46-
!14 = !DILocation(line: 10, column: 4, scope: !10)
47-
!15 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !16, align: 16)
48-
!16 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
49-
!17 = !DILocation(line: 2, column: 13, 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}
46+
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15, align: 16)
47+
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
48+
!16 = !DILocation(line: 2, column: 13, scope: !10)
49+
!17 = !DILocation(line: 10, column: 4, scope: !10)
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)