Skip to content

pattern-gen: introduce behavior AST scaffolding for frontend/backend split#2

Open
zhouguangyuan0718 wants to merge 1 commit intollvm-20.1.0from
codex/refactor-coredsl-behavior-parsing
Open

pattern-gen: introduce behavior AST scaffolding for frontend/backend split#2
zhouguangyuan0718 wants to merge 1 commit intollvm-20.1.0from
codex/refactor-coredsl-behavior-parsing

Conversation

@zhouguangyuan0718
Copy link
Owner

Motivation

  • Separate behavior parsing front-end from LLVM IR emission to enable a clean frontend/backend split for CoreDSL Behavior handling.
  • Represent statements and expressions explicitly (e.g. declarations, if/while/for, assignments, index operations) so future passes can traverse a structured AST instead of relying solely on immediate IR lowering.
  • Keep existing LLVM IR generation intact during this refactor to preserve current behavior while introducing the new scaffold.

Description

  • Add BehaviorExpression and BehaviorStatement structs to model expression kinds (Generic, Assignment, Index) and statement kinds (Scope, If, While, For, Declaration, Expr).
  • Introduce classify_expression(...) which runs the existing ParseExpression pipeline and then heuristically classifies the parsed source slice (looking for [ or assignment = vs ==) into expression kinds.
  • Thread an optional AST pointer through ParseDeclaration, ParseStatement, and ParseScope (added optional BehaviorStatement *ast parameter) so parsing can populate a lightweight AST while continuing to emit LLVM IR via the current code paths.
  • In ParseBehaviour create a top-level BehaviorStatement behaviorAST and invoke ParseStatement(..., &behaviorAST), thereby constructing the new frontend representation without changing the current lowering that follows.

Testing

  • Applied the patch successfully to llvm/tools/pattern-gen/lib/Parser.cpp and inspected the resulting diff with git diff, confirming the structural changes were introduced as intended.
  • Committed the change with git -C /workspace/CoreDSL2LLVM commit ... and the commit succeeded.
  • No full LLVM build or compile-time tests were executed in this environment because no build directory / configured LLVM build was available, so runtime/compile validation was not performed.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant