Goal
Document and fix the string-heavy OpenACC parsing/unparsing so directives/clauses are structural (enum + typed payloads) with no post-unparse hacks, preserving separators/ordering and failing fast on unknowns.
Problems
- Clause payloads are raw strings (
OpenACCClause::addLangExpr, OpenACCVarListClause): async/default_async IDs, device/device_num/num_gangs/num_workers/tile, gang(dim/static/num) args, wait queue lists, routine/bind identifiers, data-like clauses (copy/copyin/copyout/create/present/use_device/link/deviceptr/device_resident/no_create/attach), device selectors, reduction operands, if conditions—none are typed.
- Clause merging (
enable_clause_merging) dedups by kind and var string, dropping distinct self/wait/data clauses or altering order; alias spellings aren’t preserved structurally.
- Unparser hacks in
OpenACCIRToString.cpp: append space/comma then substr trim; pre-open parens then trim when empty. Spacing is fragile (e.g., copyin(...)create(...)).
- Unknown directives/clauses often flow through generic paths instead of fatal errors, hiding parser/API mismatches.
Impact/Analysis
- Round-trip spacing/separator bugs and payload loss (queues, gang args, async IDs, data lists) because data is stringly and merged. Aliases (pcreate/create, bind identifiers) are not distinguished.
- Spacing hacks make output dependent on every toString appending a trailing space/comma, causing regressions when code changes.
Actionable Plan
- AST Typing: Add typed structs/enums for all clause payloads (async/default_async IDs, gang args with num/dim/static, wait queue lists with order, bind/routine identifiers, device selectors, device/num_gangs/num_workers/tile, data clause var-sections, reduction operands, if conditions). Record separators and ordering.
- Grammar layer: Update ANTLR actions to build typed payloads directly; avoid storing raw strings. Add missing enums in
OpenACCKinds.h as the single source of truth.
- IR/C API: Expose structured payloads; remove string reparsing. Unknown kinds/payload mismatches should be fatal.
- Unparser: Emit from structured data; remove trailing-space/comma
substr hacks and only open parens when there is content. Honor recorded separators (comma vs space) and clause order.
- Merging: Disable or limit clause merging to spec-allowed cases; keep one clause per appearance for self/wait/data unless a semantic merge is explicitly valid.
- Alias fidelity: Preserve original keyword spelling via typed fields (identifier vs string literal) instead of raw strings.
- Testing: Strengthen OpenACCV-V round-trip and ctest coverage for async/wait/gang/tile/device/data/reduction/routine/bind cases; require 100% round-trip without spacing hacks.
Goal
Document and fix the string-heavy OpenACC parsing/unparsing so directives/clauses are structural (enum + typed payloads) with no post-unparse hacks, preserving separators/ordering and failing fast on unknowns.
Problems
OpenACCClause::addLangExpr,OpenACCVarListClause): async/default_async IDs, device/device_num/num_gangs/num_workers/tile, gang(dim/static/num) args, wait queue lists, routine/bind identifiers, data-like clauses (copy/copyin/copyout/create/present/use_device/link/deviceptr/device_resident/no_create/attach), device selectors, reduction operands, if conditions—none are typed.enable_clause_merging) dedups by kind and var string, dropping distinct self/wait/data clauses or altering order; alias spellings aren’t preserved structurally.OpenACCIRToString.cpp: append space/comma thensubstrtrim; pre-open parens then trim when empty. Spacing is fragile (e.g.,copyin(...)create(...)).Impact/Analysis
Actionable Plan
OpenACCKinds.has the single source of truth.substrhacks and only open parens when there is content. Honor recorded separators (comma vs space) and clause order.