Skip to content

Conversation

@Kaholaz
Copy link

@Kaholaz Kaholaz commented Oct 10, 2025

My implementation is for the most part derived from Annotation::getDerivativeAnnotation(), but I got it that this is not the preferred way of implementing such a feature. Could you point me in the right direction?

I also made some changes to the CMakeLists.txt this was done to make my LSP happy :D

This fixes some issues where my IDE does not recognize the header files.
@Kaholaz Kaholaz requested a review from a team as a code owner October 10, 2025 13:16
@github-actions github-actions bot added the ast Abstract Syntax Tree label Oct 10, 2025
@Kaholaz Kaholaz requested a review from mscuttari October 10, 2025 13:16
Copy link
Member

@mscuttari mscuttari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main suggestion is to defer semantic-related analyses to the lowering stage, keeping the structure of the AST nodes as close as possible to the language grammar.

The logic currently implemented in the ExperimentAnnotation class could eventually be moved to the lib/Codegen/Lowering components. More specifically, it might fit well in the ModelLowerer class, since the semantics of the annotation are closely tied to the model entity. In that context, you could traverse the annotation tree and attach the relevant information to the bmodelica.model operation. To support this, your ExperimentAnnotation class can naturally evolve into an MLIR attribute.

I've also left some other minor comments.


include(GNUInstallDirs)
include(FetchContent)
include_directories(${CMAKE_SOURCE_DIR}/include)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already handled by the MARCO_INCLUDE_DIR macro within the same file.

return result;
}

bool Annotation::hasExperimentAnnotation() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move all this logic within the lowering from the AST to the MLIR domain, thus avoiding to have a dedicated AST node for the Experiment annotation (which doesn't map to any non-terminal of the grammar).
Actually, the same holds for the other kinds of specific annotations (e.g. the inverse function annotation). Eventually, they should all be moved to be part of the lowering logic (not your job, just saying).

}

// Normally unreachable
assert(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer llvm_unreachable.


// Normally unreachable
assert(false);
return ExperimentAnnotation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer {} to default-construct.

};
} // namespace marco::ast::bmodelica

class ExperimentAnnotation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is going to disappear as per other comments, but please pay attention to where you declare it. The header file is for functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ast Abstract Syntax Tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants