Minres / CoreDSL

Xtext project to parse CoreDSL files
Apache License 2.0
16 stars 3 forks source link

New Analysis #76

Closed AtomCrafty closed 1 year ago

AtomCrafty commented 1 year ago

How to interface with the analyzer API

The one-stop solution for all of your analysis needs should be the analysis.CoreDslAnalyzer.analyze method. It takes the DescriptionContent representing the file you want to analyze, as well as a ValidationMessageAcceptor. The latter is used to report any errors found during analysis. The method returns an AnalysisResults instance that contains a map from each root ISA to its corresponding AnalysisContext, which in turn can be used to access all analysis results, like types, constant values, storage classes, etc. for said root ISA.

If you need more granular access, you can call the various methods on analysis.CoreDslConstantExpressionEvaluator and analysis.CoreDslTypeProvider. The entire analysis API consists of static methods, so you won't need to instantiate any of the classes providing analysis services. All API methods instead require the AnalysisContext for the ISA currently being analyzed. This context can be obtained via the analysis.CoreDslElaborator.elaborate method, which executes the elaboration phase for a given ISA to prepare it for analysis.

Data provided by the analysis

Each data point can be retrieved through one of the AnalysisContext.get* methods. Please be advised that these functions will always either return a value set during analysis or throw an exception in case no such value was set. Use the corresponding is*Set method to check whether a value was set for a given node if you are not certain it has to be.

Rough outline of the internal changes

jopperm commented 1 year ago

Mario tells me that he's still working on overhauling the tests (hence the checks are failing), and the PR is a bit too large and monolithic to do a proper line-by-line review. However, I've been using the new analysis in the MLIR code generator tool, and it works great there. @eyck WDYT, any objections to merging this soon?

eyck commented 1 year ago

No objections at all.

eyck commented 1 year ago

AFAIK this comes from the XText seeding and Xtext uses them,,,.