Skip to content

Commit 2202923

Browse files
committed
rusty: Add --online-change CLI flag
1 parent 7807d9d commit 2202923

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

compiler/plc_driver/src/cli.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ pub struct CompileParameters {
193193
#[clap(name = "check", long, help = "Check only, do not generate any output", global = true)]
194194
pub check_only: bool,
195195

196+
#[clap(
197+
long,
198+
help = "Emit a binary with specific compilation information, suitable for online changes when ran under a conforming runtime"
199+
)]
200+
pub online_change: bool,
201+
196202
#[clap(subcommand)]
197203
pub commands: Option<SubCommands>,
198204
}

compiler/plc_driver/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct CompileOptions {
5454
pub error_format: ErrorFormat,
5555
pub debug_level: DebugLevel,
5656
pub single_module: bool,
57+
pub online_change: bool,
5758
}
5859

5960
impl Default for CompileOptions {
@@ -67,6 +68,7 @@ impl Default for CompileOptions {
6768
error_format: ErrorFormat::None,
6869
debug_level: DebugLevel::None,
6970
single_module: false,
71+
online_change: false,
7072
}
7173
}
7274
}
@@ -176,6 +178,7 @@ pub fn get_compilation_context<T: AsRef<str> + AsRef<OsStr> + Debug>(
176178
error_format: compile_parameters.error_format,
177179
debug_level: compile_parameters.debug_level(),
178180
single_module: compile_parameters.single_module,
181+
online_change: compile_parameters.online_change,
179182
};
180183

181184
let libraries =

compiler/plc_driver/src/pipelines.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
284284
literals,
285285
dependencies,
286286
&self.index,
287+
compile_options.online_change,
287288
)?;
288-
code_generator.generate(context, unit, &self.annotations, &self.index, &llvm_index)
289+
code_generator.generate(
290+
context,
291+
unit,
292+
&self.annotations,
293+
&self.index,
294+
&llvm_index,
295+
compile_options.online_change,
296+
)
289297
}
290298

291299
pub fn codegen_single_module<'ctx>(

src/codegen.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'ink> CodeGen<'ink> {
104104
literals: &StringLiterals,
105105
dependencies: &IndexSet<Dependency>,
106106
global_index: &Index,
107+
hot_reload: bool,
107108
) -> Result<LlvmTypedIndex<'ink>, Diagnostic> {
108109
let llvm = Llvm::new(context, context.create_builder());
109110
let mut index = LlvmTypedIndex::default();
@@ -135,6 +136,7 @@ impl<'ink> CodeGen<'ink> {
135136
annotations,
136137
&index,
137138
&mut self.debug,
139+
hot_reload,
138140
)?;
139141
let llvm = Llvm::new(context, context.create_builder());
140142
index.merge(llvm_impl_index);
@@ -194,10 +196,11 @@ impl<'ink> CodeGen<'ink> {
194196
annotations: &AstAnnotations,
195197
global_index: &Index,
196198
llvm_index: &LlvmTypedIndex,
199+
hot_reload: bool,
197200
) -> Result<GeneratedModule<'ink>, Diagnostic> {
198201
//generate all pous
199202
let llvm = Llvm::new(context, context.create_builder());
200-
let pou_generator = PouGenerator::new(llvm, global_index, annotations, llvm_index);
203+
let pou_generator = PouGenerator::new(llvm, global_index, annotations, llvm_index, hot_reload);
201204

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

src/codegen/generators/pou_generator.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct PouGenerator<'ink, 'cg> {
4949
index: &'cg Index,
5050
annotations: &'cg AstAnnotations,
5151
llvm_index: &'cg LlvmTypedIndex<'ink>,
52+
online_change: bool,
5253
}
5354

5455
/// Creates opaque implementations for all callable items in the index
@@ -61,9 +62,10 @@ pub fn generate_implementation_stubs<'ink>(
6162
annotations: &AstAnnotations,
6263
types_index: &LlvmTypedIndex<'ink>,
6364
debug: &mut DebugBuilderEnum<'ink>,
65+
hot_reload: bool,
6466
) -> Result<LlvmTypedIndex<'ink>, Diagnostic> {
6567
let mut llvm_index = LlvmTypedIndex::default();
66-
let pou_generator = PouGenerator::new(llvm, index, annotations, types_index);
68+
let pou_generator = PouGenerator::new(llvm, index, annotations, types_index, hot_reload);
6769
let implementations = dependencies
6870
.into_iter()
6971
.filter_map(|it| {
@@ -149,8 +151,9 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
149151
index: &'cg Index,
150152
annotations: &'cg AstAnnotations,
151153
llvm_index: &'cg LlvmTypedIndex<'ink>,
154+
hot_reload: bool,
152155
) -> PouGenerator<'ink, 'cg> {
153-
PouGenerator { llvm, index, annotations, llvm_index }
156+
PouGenerator { llvm, index, annotations, llvm_index, online_change: hot_reload }
154157
}
155158

156159
fn mangle_function(&self, implementation: &ImplementationIndexEntry) -> String {
@@ -281,8 +284,10 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
281284

282285
let curr_f = module.add_function(implementation.get_call_name(), function_declaration, None);
283286

284-
let section_name = self.mangle_function(implementation);
285-
curr_f.set_section(Some(&section_name));
287+
if self.online_change {
288+
let section_name = self.mangle_function(implementation);
289+
curr_f.set_section(Some(&section_name));
290+
}
286291

287292
let pou_name = implementation.get_call_name();
288293
if let Some(pou) = self.index.find_pou(pou_name) {

src/test_utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ pub mod tests {
166166
);
167167
let annotations = AstAnnotations::new(annotations, id_provider.next_id());
168168
let llvm_index = code_generator
169-
.generate_llvm_index(&context, &annotations, &literals, &dependencies, &index)
169+
.generate_llvm_index(&context, &annotations, &literals, &dependencies, &index, false)
170170
.map_err(|err| {
171171
reporter.handle(&[err]);
172172
reporter.buffer().unwrap()
173173
})?;
174174

175175
code_generator
176-
.generate(&context, &unit, &annotations, &index, &llvm_index)
176+
.generate(&context, &unit, &annotations, &index, &llvm_index, false)
177177
.map(|module| module.persist_to_string())
178178
.map_err(|err| {
179179
reporter.handle(&[err]);
@@ -241,9 +241,10 @@ pub mod tests {
241241
&literals,
242242
&dependencies,
243243
&index,
244+
false,
244245
)?;
245246

246-
code_generator.generate(context, &unit, &annotations, &index, &llvm_index)
247+
code_generator.generate(context, &unit, &annotations, &index, &llvm_index, false)
247248
})
248249
.collect::<Result<Vec<_>, Diagnostic>>()
249250
}

0 commit comments

Comments
 (0)