Skip to content

Commit 450e278

Browse files
authored
Merge branch 'master' into volsa/lit
2 parents e567c98 + 5174c2c commit 450e278

File tree

426 files changed

+1626
-1374
lines changed

Some content is hidden

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

426 files changed

+1626
-1374
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: "results.join(\"\\n\")"
55
; ModuleID = 'main.st'
66
source_filename = "main.st"
77

8-
define i16 @main() section "fn-main:i16" {
8+
define i16 @main() section "fn-$RUSTY$main:i16" {
99
entry:
1010
%main = alloca i16, align 2
1111
store i16 0, i16* %main, align 2
@@ -14,9 +14,9 @@ entry:
1414
ret i16 %main_ret
1515
}
1616

17-
declare i16 @external() section "fn-external:i16"
17+
declare i16 @external() section "fn-$RUSTY$external:i16"
1818

1919
; ModuleID = 'external.st'
2020
source_filename = "external.st"
2121

22-
declare i16 @external() section "fn-external:i16"
22+
declare i16 @external() section "fn-$RUSTY$external:i16"

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ expression: "results.join(\"\\n\")"
55
; ModuleID = 'main.st'
66
source_filename = "main.st"
77

8-
@x = external global i16, section "var-x:i16"
9-
@y = external global i16, section "var-y:i16"
8+
@x = external global i16, section "var-$RUSTY$x:i16"
9+
@y = external global i16, section "var-$RUSTY$y:i16"
1010

11-
define i16 @main() section "fn-main:i16" {
11+
define i16 @main() section "fn-$RUSTY$main:i16" {
1212
entry:
1313
%main = alloca i16, align 2
1414
store i16 0, i16* %main, align 2
@@ -19,12 +19,12 @@ entry:
1919
ret i16 %main_ret
2020
}
2121

22-
declare i16 @external() section "fn-external:i16"
22+
declare i16 @external() section "fn-$RUSTY$external:i16"
2323

2424
; ModuleID = 'external.st'
2525
source_filename = "external.st"
2626

27-
@x = external global i16, section "var-x:i16"
28-
@y = external global i16, section "var-y:i16"
27+
@x = external global i16, section "var-$RUSTY$x:i16"
28+
@y = external global i16, section "var-$RUSTY$y:i16"
2929

30-
declare i16 @external() section "fn-external:i16"
30+
declare i16 @external() section "fn-$RUSTY$external:i16"

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ source_filename = "app/file1.st"
77

88
%mainProg = type {}
99

10-
@mainProg_instance = external global %mainProg, section "var-mainProg_instance:r0", !dbg !0
10+
@mainProg_instance = external global %mainProg, section "var-$RUSTY$mainProg_instance:r0", !dbg !0
1111

12-
define i16 @main() section "fn-main:i16" !dbg !10 {
12+
define i16 @main() section "fn-$RUSTY$main:i16" !dbg !10 {
1313
entry:
1414
%main = alloca i16, align 2, !dbg !14
1515
call void @llvm.dbg.declare(metadata i16* %main, metadata !15, metadata !DIExpression()), !dbg !17
@@ -19,7 +19,7 @@ entry:
1919
ret i16 %main_ret, !dbg !14
2020
}
2121

22-
declare !dbg !18 void @mainProg(%mainProg*) section "fn-mainProg:v"
22+
declare !dbg !18 void @mainProg(%mainProg*) section "fn-$RUSTY$mainProg:v"
2323

2424
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
2525
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
@@ -54,9 +54,9 @@ source_filename = "lib/file2.st"
5454

5555
%mainProg = type {}
5656

57-
@mainProg_instance = global %mainProg zeroinitializer, section "var-mainProg_instance:r0", !dbg !0
57+
@mainProg_instance = global %mainProg zeroinitializer, section "var-$RUSTY$mainProg_instance:r0", !dbg !0
5858

59-
define void @mainProg(%mainProg* %0) section "fn-mainProg:v" !dbg !10 {
59+
define void @mainProg(%mainProg* %0) section "fn-$RUSTY$mainProg:v" !dbg !10 {
6060
entry:
6161
call void @llvm.dbg.declare(metadata %mainProg* %0, metadata !13, metadata !DIExpression()), !dbg !14
6262
ret void, !dbg !14

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ source_filename = "file1.st"
77

88
%mainProg = type {}
99

10-
@mainProg_instance = external global %mainProg, section "var-mainProg_instance:r0", !dbg !0
10+
@mainProg_instance = external global %mainProg, section "var-$RUSTY$mainProg_instance:r0", !dbg !0
1111

12-
define i16 @main() section "fn-main:i16" !dbg !10 {
12+
define i16 @main() section "fn-$RUSTY$main:i16" !dbg !10 {
1313
entry:
1414
%main = alloca i16, align 2, !dbg !14
1515
call void @llvm.dbg.declare(metadata i16* %main, metadata !15, metadata !DIExpression()), !dbg !17
@@ -19,7 +19,7 @@ entry:
1919
ret i16 %main_ret, !dbg !14
2020
}
2121

22-
declare !dbg !18 void @mainProg(%mainProg*) section "fn-mainProg:v"
22+
declare !dbg !18 void @mainProg(%mainProg*) section "fn-$RUSTY$mainProg:v"
2323

2424
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
2525
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
@@ -54,9 +54,9 @@ source_filename = "file2.st"
5454

5555
%mainProg = type {}
5656

57-
@mainProg_instance = global %mainProg zeroinitializer, section "var-mainProg_instance:r0", !dbg !0
57+
@mainProg_instance = global %mainProg zeroinitializer, section "var-$RUSTY$mainProg_instance:r0", !dbg !0
5858

59-
define void @mainProg(%mainProg* %0) section "fn-mainProg:v" !dbg !10 {
59+
define void @mainProg(%mainProg* %0) section "fn-$RUSTY$mainProg:v" !dbg !10 {
6060
entry:
6161
call void @llvm.dbg.declare(metadata %mainProg* %0, metadata !13, metadata !DIExpression()), !dbg !14
6262
ret void, !dbg !14

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ source_filename = "external_file1.st"
77

88
%mainProg = type {}
99

10-
@mainProg_instance = external global %mainProg, section "var-mainProg_instance:r0"
10+
@mainProg_instance = external global %mainProg, section "var-$RUSTY$mainProg_instance:r0"
1111

12-
define i16 @main() section "fn-main:i16" {
12+
define i16 @main() section "fn-$RUSTY$main:i16" {
1313
entry:
1414
%main = alloca i16, align 2
1515
store i16 0, i16* %main, align 2
@@ -18,16 +18,16 @@ entry:
1818
ret i16 %main_ret
1919
}
2020

21-
declare void @mainProg(%mainProg*) section "fn-mainProg:v"
21+
declare void @mainProg(%mainProg*) section "fn-$RUSTY$mainProg:v"
2222

2323
; ModuleID = 'external_file2.st'
2424
source_filename = "external_file2.st"
2525

2626
%mainProg = type {}
2727

28-
@mainProg_instance = global %mainProg zeroinitializer, section "var-mainProg_instance:r0"
28+
@mainProg_instance = global %mainProg zeroinitializer, section "var-$RUSTY$mainProg_instance:r0"
2929

30-
define void @mainProg(%mainProg* %0) section "fn-mainProg:v" {
30+
define void @mainProg(%mainProg* %0) section "fn-$RUSTY$mainProg:v" {
3131
entry:
3232
ret void
3333
}

compiler/section_mangler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.0.1"
44
edition = "2021"
55

66
[dependencies]
7+
nom = "7.1"

compiler/section_mangler/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,25 @@
4444
4545
use std::fmt;
4646

47+
mod parser;
48+
4749
/// The main builder type of this crate. Use it to create mangling contexts, in
4850
/// order to encode and decode binary type information.
4951
// TODO: Add example code for using this builder
52+
#[derive(Debug, PartialEq, Clone)]
5053
pub enum SectionMangler {
5154
Function(FunctionMangler),
5255
Variable(VariableMangler),
5356
}
5457

58+
#[derive(Debug, PartialEq, Clone)]
5559
pub struct FunctionMangler {
5660
name: String,
5761
parameters: Vec<FunctionArgument>,
5862
return_type: Option<Type>,
5963
}
6064

65+
#[derive(Debug, PartialEq, Clone)]
6166
pub struct VariableMangler {
6267
name: String,
6368
ty: Type,
@@ -72,6 +77,13 @@ impl SectionMangler {
7277
SectionMangler::Variable(VariableMangler { name: name.into(), ty })
7378
}
7479

80+
pub fn name(&self) -> &str {
81+
match self {
82+
SectionMangler::Function(FunctionMangler { name, .. })
83+
| SectionMangler::Variable(VariableMangler { name, .. }) => name,
84+
}
85+
}
86+
7587
pub fn with_parameter(self, param: FunctionArgument) -> SectionMangler {
7688
match self {
7789
SectionMangler::Function(f) => {
@@ -113,6 +125,7 @@ impl SectionMangler {
113125
// NOTE: This is called `variable_linkage` in the `MemberInfo` struct.
114126

115127
/// We have to encode this because if it changes, the function needs to be reloaded - this is an ABI breakage
128+
#[derive(Debug, PartialEq, Clone)]
116129
pub enum FunctionArgument {
117130
ByValue(Type),
118131
ByRef(Type),
@@ -129,6 +142,7 @@ impl fmt::Display for FunctionArgument {
129142
}
130143

131144
// TODO: Do we have to encode this? Does that affect ABI? Probably
145+
#[derive(Debug, PartialEq, Clone)]
132146
pub enum StringEncoding {
133147
// TODO: Should we encode this differently? this could cause problems compared to encoding unsigned types
134148
/// Encoded as `8u`
@@ -148,6 +162,7 @@ impl fmt::Display for StringEncoding {
148162

149163
// This maps directly to the [`DataTypeInformation`] enum in RuSTy - we simply remove some fields and add the ability to encode/decode serialize/deserialize
150164
// TODO: Do we have to handle Generic?
165+
#[derive(Debug, PartialEq, Clone)]
151166
pub enum Type {
152167
/// Encoded as `v`
153168
Void,
@@ -235,16 +250,18 @@ impl fmt::Display for Type {
235250
}
236251
}
237252

253+
pub const PREFIX: &str = "$RUSTY$";
254+
238255
// TODO: How to encode variadics?
239256
fn mangle_function(FunctionMangler { name, parameters, return_type }: FunctionMangler) -> String {
240257
let mangled = parameters
241258
.into_iter()
242259
/* FIXME: Is that correct? */
243260
.fold(return_type.unwrap_or(Type::Void).to_string(), |mangled, arg| format!("{mangled}[{arg}]"));
244261

245-
format!("{name}:{mangled}")
262+
format!("{PREFIX}{name}:{mangled}")
246263
}
247264

248265
fn mangle_variable(VariableMangler { name, ty }: VariableMangler) -> String {
249-
format!("{name}:{ty}")
266+
format!("{PREFIX}{name}:{ty}")
250267
}

0 commit comments

Comments
 (0)