Add methods Stmt::CoveringMacros() and Stmt::CoveredBy().
Stmt::CoveringMacros() returns a vector containing all the macros that cover a given statement. This will enable us to lower all macros covering a statement down to MLIR, not just the lowest covering macro.
Stmt::CoveredBy() accepts a single macro as an argument, and returns true if that macro covers the given statement. We can use this to determine which AST subtrees of a macro expansion's covered statement were expanded from the macro's arguments by traversing the statement's AST, and returning those subtrees which are covered by any of the macro's arguments. Once we have the set of AST subtrees that are expanded from a macro's arguments, we can then determine which parts of the statement that the macro covers were expanded solely from the macro's body, solely from its arguments, or both. We can then lower all this information down to MLIR for further analyses.
Add the method Macro::KindName() to get the name of a macro's MacroKind as a string. I used Peter's X-macro for defining the MacroKind enum class to do this.
Add a binary and associated tests for Stmt::CoveringMacros(). I have not added tests for Stmt::CoveredBy(). In the future a simple way to test this would be to first verify that Stmt::CoveringMacros() is correct, and then check that calling Stmt::CoveredBy() on each macro that covers a statement returns true for each of them. This will not check for false positives though, just for false negatives.
Stmt::CoveringMacros()
andStmt::CoveredBy()
.Stmt::CoveringMacros()
returns a vector containing all the macros that cover a given statement. This will enable us to lower all macros covering a statement down to MLIR, not just the lowest covering macro.Stmt::CoveredBy()
accepts a single macro as an argument, and returns true if that macro covers the given statement. We can use this to determine which AST subtrees of a macro expansion's covered statement were expanded from the macro's arguments by traversing the statement's AST, and returning those subtrees which are covered by any of the macro's arguments. Once we have the set of AST subtrees that are expanded from a macro's arguments, we can then determine which parts of the statement that the macro covers were expanded solely from the macro's body, solely from its arguments, or both. We can then lower all this information down to MLIR for further analyses.Macro::KindName()
to get the name of a macro'sMacroKind
as a string. I used Peter's X-macro for defining theMacroKind
enum class to do this.Stmt::CoveringMacros()
. I have not added tests forStmt::CoveredBy()
. In the future a simple way to test this would be to first verify thatStmt::CoveringMacros()
is correct, and then check that callingStmt::CoveredBy()
on each macro that covers a statement returns true for each of them. This will not check for false positives though, just for false negatives.