Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/method_returns' into initial_values
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaith committed Jan 24, 2025
2 parents 3f87142 + ec68f54 commit 390be7a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
14 changes: 5 additions & 9 deletions compiler/plc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use anyhow::{anyhow, Result};
use pipelines::{
participant::{CodegenParticipant, InitParticipant},
AnnotatedProject, BuildPipeline, GeneratedProject, Pipeline,
participant::CodegenParticipant, AnnotatedProject, BuildPipeline, GeneratedProject, Pipeline,
};
use std::{
ffi::OsStr,
Expand All @@ -22,8 +21,8 @@ use std::{

use cli::{CompileParameters, ParameterError};
use plc::{
codegen::CodegenContext, linker::LinkerType, lowering::calls::AggregateTypeLowerer, output::FormatOption,
DebugLevel, ErrorFormat, OnlineChange, OptimizationLevel,
codegen::CodegenContext, linker::LinkerType, output::FormatOption, DebugLevel, ErrorFormat, OnlineChange,
OptimizationLevel,
};

use plc_diagnostics::{diagnostician::Diagnostician, diagnostics::Diagnostic};
Expand Down Expand Up @@ -149,6 +148,7 @@ pub fn compile<T: AsRef<str> + AsRef<OsStr> + Debug>(args: &[T]) -> Result<()> {
//Parse the arguments
let mut pipeline = BuildPipeline::new(args)?;
//register participants
pipeline.register_default_participants();
let target = pipeline.compile_parameters.as_ref().and_then(|it| it.target.clone()).unwrap_or_default();
let codegen_participant = CodegenParticipant {
compile_options: pipeline.get_compile_options().unwrap(),
Expand All @@ -163,12 +163,7 @@ pub fn compile<T: AsRef<str> + AsRef<OsStr> + Debug>(args: &[T]) -> Result<()> {
libraries: pipeline.project.get_libraries().to_vec(),
};
pipeline.register_participant(Box::new(codegen_participant));
let init_participant =
InitParticipant::new(&pipeline.project.get_init_symbol_name(), pipeline.context.provider());
pipeline.register_mut_participant(Box::new(init_participant));

let aggregate_return_participant = AggregateTypeLowerer::new(pipeline.context.provider());
pipeline.register_mut_participant(Box::new(aggregate_return_participant));
let format = pipeline.compile_parameters.as_ref().map(|it| it.error_format).unwrap_or_default();

pipeline.run().map_err(|err| {
Expand Down Expand Up @@ -201,6 +196,7 @@ pub fn parse_and_annotate<T: SourceContainer + Clone>(
mutable_participants: Vec::default(),
participants: Vec::default(),
};
pipeline.register_default_participants();
let project = pipeline.parse()?;
let project = pipeline.index(project)?;
let project = pipeline.annotate(project)?;
Expand Down
14 changes: 14 additions & 0 deletions compiler/plc_driver/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ impl<T: SourceContainer> BuildPipeline<T> {
log::info!("{err}")
}
}

/// Register all default participants (excluding codegen/linking)
pub fn register_default_participants(&mut self) {
use participant::InitParticipant;
use plc::lowering::calls::AggregateTypeLowerer;

// XXX: should we use a static array of participants?
let init_participant =
InitParticipant::new(&self.project.get_init_symbol_name(), self.context.provider());
self.register_mut_participant(Box::new(init_participant));

let aggregate_return_participant = AggregateTypeLowerer::new(self.context.provider());
self.register_mut_participant(Box::new(aggregate_return_participant));
}
}

impl<T: SourceContainer> Pipeline for BuildPipeline<T> {
Expand Down
14 changes: 3 additions & 11 deletions compiler/plc_driver/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use crate::{
pipelines::{participant::InitParticipant, BuildPipeline, Pipeline},
pipelines::{BuildPipeline, Pipeline},
CompileOptions,
};

use plc::{
codegen::{CodegenContext, GeneratedModule},
lowering::calls::AggregateTypeLowerer,
};
use plc::codegen::{CodegenContext, GeneratedModule};
use plc_diagnostics::diagnostician::Diagnostician;
use plc_index::GlobalContext;
use project::project::Project;
Expand Down Expand Up @@ -44,12 +41,7 @@ pub fn compile<T: Compilable>(codegen_context: &CodegenContext, source: T) -> Ge
participants: Default::default(),
};

let init_participant =
InitParticipant::new(&pipeline.project.get_init_symbol_name(), pipeline.context.provider());
pipeline.register_mut_participant(Box::new(init_participant));

let aggregate_return_participant = AggregateTypeLowerer::new(pipeline.context.provider());
pipeline.register_mut_participant(Box::new(aggregate_return_participant));
pipeline.register_default_participants();

let project = pipeline.parse().unwrap();
let project = pipeline.index(project).unwrap();
Expand Down
3 changes: 0 additions & 3 deletions src/tests/adr/pou_adr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::test_utils::tests::{annotate_with_ids, codegen, index_with_ids};
/// Programs are POUs with exactly one (static) instance. Programs have a persistent state for VAR, VAR_INPUT,
/// VAR_OUTPUT and VAR_IN_OUT variables. The instance is statically available and behaves as if there is a callable
/// global variable withe the program's name. When calling a program all parameters, except IN_OUT parameters, are optional.
const DEFAULT_PRG: &str = r#"
PROGRAM main_prg
VAR_INPUT i : INT END_VAR
Expand Down Expand Up @@ -378,7 +377,6 @@ fn calling_a_program() {
/// that you can have mulitple instances of a FunctionBlock. Therefore a FunctionBlocks instance variable is not
/// auto-generated as a global variable as it would be for a program. FB-instances can be declared as part of your
/// code. A FunctionBlock acts automatically as a DataType.
const DEFAULT_FB: &str = r#"
FUNCTION_BLOCK main_fb
VAR_INPUT i : INT := 6 END_VAR
Expand Down Expand Up @@ -554,7 +552,6 @@ fn calling_a_function_block() {
///
/// Functions are stateless methods. They dont have an instance-struct or instance variables. Functions
/// take all their parameters passed one by one to the function.
const DEFAULT_FUNC: &str = r#"
FUNCTION main_fun : DINT
VAR_INPUT i : INT; END_VAR
Expand Down

0 comments on commit 390be7a

Please sign in to comment.