Skip to content
3 changes: 2 additions & 1 deletion compiler/plc_driver/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<T: SourceContainer> BuildPipeline<T> {
}

pub fn get_default_mut_participants(&self) -> Vec<Box<dyn PipelineParticipantMut>> {
use participant::InitParticipant;
use participant::{ArrayLowerer, InitParticipant};

// XXX: should we use a static array of participants?
let mut_participants: Vec<Box<dyn PipelineParticipantMut>> = vec![
Expand All @@ -312,6 +312,7 @@ impl<T: SourceContainer> BuildPipeline<T> {
self.context.provider(),
self.context.should_generate_external_constructors(),
)),
Box::new(ArrayLowerer::new(self.context.provider())),
];
mut_participants
}
Expand Down
23 changes: 23 additions & 0 deletions compiler/plc_driver/src/pipelines/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use plc::{
};
use plc_diagnostics::diagnostics::Diagnostic;
use plc_lowering::{
array_lowering,
retain::RetainParticipant,
{
control_statement::ControlStatementParticipant, inheritance::InheritanceLowerer,
Expand Down Expand Up @@ -245,6 +246,28 @@ impl PipelineParticipantMut for InitParticipant {
}
}

pub struct ArrayLowerer {
id_provider: IdProvider,
}

impl ArrayLowerer {
pub fn new(id_provider: IdProvider) -> Self {
Self { id_provider }
}
}

impl PipelineParticipantMut for ArrayLowerer {
fn pre_annotate(&mut self, indexed_project: IndexedProject) -> IndexedProject {
let IndexedProject { project: ParsedProject { mut units }, index, .. } = indexed_project;
for unit in &mut units {
array_lowering::lower_literal_arrays(unit, &index, &mut self.id_provider);
}
// Re-index since we modified the AST (new statements, possible new alloca variables)
let project = ParsedProject { units };
project.index(self.id_provider.clone())
}
}

impl PipelineParticipantMut for InheritanceLowerer {
fn pre_index(&mut self, parsed_project: ParsedProject) -> ParsedProject {
let ParsedProject { mut units } = parsed_project;
Expand Down
844 changes: 844 additions & 0 deletions compiler/plc_lowering/src/array_lowering.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions compiler/plc_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use plc::{
};
use plc_ast::{ast::AstNode, provider::IdProvider};

pub mod array_lowering;
pub mod control_statement;
pub mod inheritance;
pub mod initializer;
Expand Down
1 change: 1 addition & 0 deletions compiler/plc_lowering/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod array_lowering_tests;
mod inheritance_tests;
mod initializer_tests;
mod super_tests;
Loading
Loading