Skip to content

Commit

Permalink
move lowering stage after validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhasel committed Oct 24, 2024
1 parent 0c1227d commit ad2286e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
18 changes: 12 additions & 6 deletions compiler/plc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,24 @@ pub fn compile_with_options(compile_options: CompilationContext) -> Result<()> {
// 1. Parse, 2. Index and 3. Resolve / Annotate
let annotated_project = pipelines::ParsedProject::parse(&ctxt, project, &mut diagnostician)?
.index(ctxt.provider())
.annotate(ctxt.provider())
// 4. AST-lowering, re-index and re-resolve
.lower(ctxt.provider());
.annotate(ctxt.provider());

// 4. Validate
annotated_project.validate(&ctxt, &mut diagnostician).map_err(|e| {
if compile_parameters.output_ast {
println!("{:#?}", annotated_project.units);
}
e
})?;

// 5. AST-lowering, re-index and re-resolve
let annotated_project = annotated_project.lower(ctxt.provider());

if compile_parameters.output_ast {
println!("{:#?}", annotated_project.units);
return Ok(());
}

// 5. Validate
annotated_project.validate(&ctxt, &mut diagnostician)?;

if let Some((location, format)) =
compile_parameters.hardware_config.as_ref().zip(compile_parameters.config_format())
{
Expand Down
19 changes: 0 additions & 19 deletions src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,6 @@ impl AstVisitorMut for AstLowerer {
}

fn visit_variable(&mut self, variable: &mut plc_ast::ast::Variable) {
let is_recursive = self
.ctxt
.get_scope()
.as_ref()
.map(|scope| {
self.index.find_pou_type(scope).is_some_and(|it| {
let Ok(pou_type) = self.index.get_effective_type_by_name(it.get_name()) else {
unreachable!("We are in the context of this POU, it must have a type");
};
let var_type = self.index.get_effective_type_or_void_by_name(
variable.data_type_declaration.get_name().unwrap_or_default(),
);
pou_type.get_name() == var_type.get_name()
})
})
.unwrap_or_default();
if is_recursive {
return;
};
self.maybe_add_global_instance_initializer(variable);
self.update_initializer(variable);
variable.walk(self);
Expand Down

0 comments on commit ad2286e

Please sign in to comment.