Skip to content

Commit 40bbc74

Browse files
committed
Global variables only get sections if online change is active
1 parent a376fe7 commit 40bbc74

File tree

357 files changed

+1712
-1691
lines changed

Some content is hidden

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

357 files changed

+1712
-1691
lines changed

compiler/plc_driver/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ pub struct CompileParameters {
121121
default_value = DEFAULT_GOT_LAYOUT_FILE,
122122
parse(try_from_str = validate_config),
123123
// FIXME: For some reason, this does not work at the moment but it really should
124-
// requires = "online_change"
124+
// The binary behaves as expected but the tests fail
125+
// requires = "online-change"
125126
) ]
126127
pub got_layout_file: String,
127128

compiler/plc_driver/src/pipelines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
370370
&unit.file_name,
371371
compile_options.optimization,
372372
compile_options.debug_level,
373-
//(compile_options.got_layout_file.clone(), compile_options.got_layout_format),
373+
//FIXME don't clone here
374374
compile_options.online_change.clone(),
375375
);
376376
//Create a types codegen, this contains all the type declarations

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

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

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

1111
define i16 @main() {
1212
entry:
@@ -24,8 +24,8 @@ declare i16 @external()
2424
; ModuleID = 'external.st'
2525
source_filename = "external.st"
2626

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

3030
declare i16 @external()
3131

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

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

88
%mainProg = type {}
99

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

1212
define i16 @main() !dbg !10 {
1313
entry:
@@ -54,7 +54,7 @@ source_filename = "lib/file2.st"
5454

5555
%mainProg = type {}
5656

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

5959
define void @mainProg(%mainProg* %0) !dbg !10 {
6060
entry:
@@ -91,7 +91,7 @@ source_filename = "__initializers"
9191

9292
%mainProg = type {}
9393

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

9696
define void @__init_mainprog(%mainProg* %0) !dbg !10 {
9797
entry:
@@ -136,7 +136,7 @@ source_filename = "__init___TestProject"
136136

137137
%mainProg = type {}
138138

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

141141
define void @__init___TestProject() !dbg !10 {
142142
entry:

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

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

88
%mainProg = type {}
99

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

1212
define i16 @main() !dbg !10 {
1313
entry:
@@ -54,7 +54,7 @@ source_filename = "file2.st"
5454

5555
%mainProg = type {}
5656

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

5959
define void @mainProg(%mainProg* %0) !dbg !10 {
6060
entry:
@@ -91,7 +91,7 @@ source_filename = "__initializers"
9191

9292
%mainProg = type {}
9393

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

9696
define void @__init_mainprog(%mainProg* %0) !dbg !10 {
9797
entry:
@@ -136,7 +136,7 @@ source_filename = "__init___TestProject"
136136

137137
%mainProg = type {}
138138

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

141141
define void @__init___TestProject() !dbg !10 {
142142
entry:

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

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

88
%mainProg = type {}
99

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

1212
define i16 @main() {
1313
entry:
@@ -25,7 +25,7 @@ source_filename = "external_file2.st"
2525

2626
%mainProg = type {}
2727

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

3030
define void @mainProg(%mainProg* %0) {
3131
entry:
@@ -37,7 +37,7 @@ source_filename = "__initializers"
3737

3838
%mainProg = type {}
3939

40-
@mainProg_instance = external global %mainProg, section "$RUSTY$var-mainprog_instance:r0"
40+
@mainProg_instance = external global %mainProg
4141

4242
define void @__init_mainprog(%mainProg* %0) {
4343
entry:
@@ -53,7 +53,7 @@ source_filename = "__init___TestProject"
5353

5454
%mainProg = type {}
5555

56-
@mainProg_instance = external global %mainProg, section "$RUSTY$var-mainprog_instance:r0"
56+
@mainProg_instance = external global %mainProg
5757

5858
define void @__init___TestProject() {
5959
entry:

src/codegen.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,15 @@ impl<'ink> CodeGen<'ink> {
126126
)?;
127127
index.merge(llvm_type_index);
128128

129-
let mut variable_generator =
130-
VariableGenerator::new(&self.module, &llvm, global_index, annotations, &index, &mut self.debug);
129+
let mut variable_generator = VariableGenerator::new(
130+
&self.module,
131+
&llvm,
132+
global_index,
133+
annotations,
134+
&index,
135+
&mut self.debug,
136+
&self.online_change,
137+
);
131138

132139
//Generate global variables
133140
let llvm_gv_index =
@@ -166,7 +173,7 @@ impl<'ink> CodeGen<'ink> {
166173
acc
167174
});
168175

169-
if let OnlineChange::Enabled((_, _)) = self.online_change {
176+
if self.online_change.is_enabled() {
170177
let got_entries = &mut *got_layout.lock().unwrap();
171178

172179
let mut new_symbols = Vec::new();
@@ -226,7 +233,7 @@ impl<'ink> CodeGen<'ink> {
226233
annotations,
227234
&index,
228235
&mut self.debug,
229-
self.online_change.clone(),
236+
&self.online_change,
230237
)?;
231238
let llvm = Llvm::new(context, context.create_builder());
232239
index.merge(llvm_impl_index);
@@ -290,7 +297,7 @@ impl<'ink> CodeGen<'ink> {
290297
//generate all pous
291298
let llvm = Llvm::new(context, context.create_builder());
292299
let pou_generator =
293-
PouGenerator::new(llvm, global_index, annotations, &llvm_index, self.online_change);
300+
PouGenerator::new(llvm, global_index, annotations, &llvm_index, &self.online_change);
294301

295302
//Generate the POU stubs in the first go to make sure they can be referenced.
296303
for implementation in &unit.implementations {

src/codegen/generators/pou_generator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct PouGenerator<'ink, 'cg> {
5050
index: &'cg Index,
5151
annotations: &'cg AstAnnotations,
5252
llvm_index: &'cg LlvmTypedIndex<'ink>,
53-
online_change: OnlineChange,
53+
online_change: &'cg OnlineChange,
5454
}
5555

5656
/// Creates opaque implementations for all callable items in the index
@@ -65,7 +65,7 @@ pub fn generate_implementation_stubs<'ink>(
6565
annotations: &AstAnnotations,
6666
types_index: &LlvmTypedIndex<'ink>,
6767
debug: &mut DebugBuilderEnum<'ink>,
68-
online_change: OnlineChange,
68+
online_change: &OnlineChange,
6969
) -> Result<LlvmTypedIndex<'ink>, Diagnostic> {
7070
let mut llvm_index = LlvmTypedIndex::default();
7171
let pou_generator = PouGenerator::new(llvm, index, annotations, types_index, online_change);
@@ -159,7 +159,7 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
159159
index: &'cg Index,
160160
annotations: &'cg AstAnnotations,
161161
llvm_index: &'cg LlvmTypedIndex<'ink>,
162-
online_change: OnlineChange,
162+
online_change: &'cg OnlineChange,
163163
) -> PouGenerator<'ink, 'cg> {
164164
PouGenerator { llvm, index, annotations, llvm_index, online_change }
165165
}
@@ -296,7 +296,7 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
296296

297297
let curr_f = module.add_function(implementation.get_call_name(), function_declaration, None);
298298

299-
if let OnlineChange::Enabled(_) = self.online_change {
299+
if self.online_change.is_enabled() {
300300
let section_name = self.mangle_function(implementation)?;
301301
curr_f.set_section(Some(&section_name));
302302
}

src/codegen/generators/variable_generator.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
},
1111
index::{get_initializer_name, Index, PouIndexEntry, VariableIndexEntry},
1212
resolver::{AnnotationMap, AstAnnotations, Dependency},
13+
OnlineChange,
1314
};
1415
use inkwell::{module::Module, values::GlobalValue};
1516
use plc_ast::ast::LinkageType;
@@ -32,6 +33,7 @@ pub struct VariableGenerator<'ctx, 'b> {
3233
annotations: &'b AstAnnotations,
3334
types_index: &'b LlvmTypedIndex<'ctx>,
3435
debug: &'b mut DebugBuilderEnum<'ctx>,
36+
online_change: &'b OnlineChange,
3537
}
3638

3739
impl<'ctx, 'b> VariableGenerator<'ctx, 'b> {
@@ -42,8 +44,9 @@ impl<'ctx, 'b> VariableGenerator<'ctx, 'b> {
4244
annotations: &'b AstAnnotations,
4345
types_index: &'b LlvmTypedIndex<'ctx>,
4446
debug: &'b mut DebugBuilderEnum<'ctx>,
47+
online_change: &'b OnlineChange,
4548
) -> Self {
46-
VariableGenerator { module, llvm, global_index, annotations, types_index, debug }
49+
VariableGenerator { module, llvm, global_index, annotations, types_index, debug, online_change }
4750
}
4851

4952
pub fn generate_global_variables(
@@ -190,16 +193,17 @@ impl<'ctx, 'b> VariableGenerator<'ctx, 'b> {
190193
};
191194
let global_name = global_name.to_lowercase();
192195

193-
let section = SectionMangler::variable(
194-
global_name,
195-
section_names::mangle_type(
196-
self.global_index,
197-
self.global_index.get_effective_type_by_name(global_variable.get_type_name())?,
198-
)?,
199-
)
200-
.mangle();
201-
202-
global_ir_variable.set_section(Some(&section));
196+
if self.online_change.is_enabled() {
197+
let section = SectionMangler::variable(
198+
global_name,
199+
section_names::mangle_type(
200+
self.global_index,
201+
self.global_index.get_effective_type_by_name(global_variable.get_type_name())?,
202+
)?,
203+
)
204+
.mangle();
205+
global_ir_variable.set_section(Some(&section));
206+
}
203207

204208
Ok(global_ir_variable)
205209
}

0 commit comments

Comments
 (0)