accparser Compatibility Layer
ROUP provides a drop-in compatibility layer for projects using accparser, allowing you to switch to ROUP’s faster, safer Rust-based parser without changing your code.
What is it?
A compatibility layer that provides:
- Same API as accparser - no code changes needed
- Drop-in replacement via
libaccparser.so - Zero ANTLR4 dependency - no need to install antlr4 runtime or toolchain
- ROUP backend - faster, safer parsing in Rust
- Reuses accparser methods - toString(), generateDOT(), etc. (zero duplication)
Quick Start
One-Command Build
cd compat/accparser
./build.sh
The script will:
- Check prerequisites (git, cmake, gcc, cargo)
- Initialize accparser submodule
- Build ROUP core library
- Build
libaccparser.so - Run the full upstream accparser ctest suite (900+ cases)
Manual Build
# 1. Initialize accparser submodule
git submodule update --init --recursive
# 2. Build ROUP core
cd /path/to/roup
cargo build --release
# 3. Build compatibility layer
cd compat/accparser
mkdir -p build && cd build
cmake ..
make
# 4. Run tests
ctest --output-on-failure
Usage
Drop-in Replacement
Install system-wide and use exactly like original accparser:
# Install
cd compat/accparser/build
sudo make install
sudo ldconfig
# Use (unchanged!)
g++ mycompiler.cpp -laccparser -o mycompiler
Code Example
Your existing accparser code works without changes:
#include <OpenACCIR.h>
#include <iostream>
int main() {
// Set language mode
setLang(ACC_Lang_C);
// Parse OpenACC directive
OpenACCDirective* dir = parseOpenACC("acc parallel num_gangs(4)", nullptr);
if (dir) {
// Use accparser methods (all work!)
std::cout << "Kind: " << dir->getKind() << std::endl;
std::cout << "String: " << dir->toString() << std::endl;
// Access clauses
auto* clauses = dir->getAllClauses();
std::cout << "Clauses: " << clauses->size() << std::endl;
delete dir;
}
return 0;
}
CMake Integration
Option 1: pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(ACCPARSER REQUIRED accparser)
target_link_libraries(your_app ${ACCPARSER_LIBRARIES})
target_include_directories(your_app PRIVATE ${ACCPARSER_INCLUDE_DIRS})
Option 2: Direct linking
target_link_libraries(your_app
${PATH_TO_ROUP}/compat/accparser/build/libaccparser.so
)
What’s Included
libaccparser.so
Single self-contained library with:
- ROUP parser (statically embedded) - Rust-based, safe parsing
- accparser methods - toString, etc.
- Compatibility wrapper - Seamless integration layer
- Self-contained - No libroup.so dependency
Comprehensive Testing
The bundled ctest run exercises the upstream accparser test matrix (directives, clauses, aliases, unparsing) against the ROUP-backed shim. It also validates end-paired directives, wait/cache data, and alias spellings under the ROUP_ACC_* namespace.
Architecture
Your Application (OpenACC directives to parse)
↓
compat_impl.cpp (~220 lines) - Minimal wrapper
↓
ROUP C API (acc_parse, acc_directive_kind, etc.)
↓
ROUP Rust Parser (safe parser core)
↓
Returns: OpenACCDirective with accparser methods
Key Design:
- Reuses 90% of accparser code (no duplication)
- Git submodule approach - automatic accparser upgrades
- No ANTLR4 dependency - cleaner build process
- Minimal unsafe code, all at FFI boundary
Supported Features
Directives (17+)
- Compute:
parallel,kernels,serial,loop - Data:
data,enter data,exit data,host_data - Synchronization:
wait,atomic - Other:
declare,routine,init,shutdown,set,update,end
Clauses (45+)
- Compute:
num_gangs,num_workers,vector_length,async,wait - Data:
copy,copyin,copyout,create,delete,present - Loop:
gang,worker,vector,seq,independent,collapse,tile - Other:
private,firstprivate,reduction,if,default
See compat/accparser/src/roup_constants.h (and the auto-generated
src/roup_constants.h) for the complete list of generated macros. Note that
generated OpenACC macros now use the ROUP_ACC_* prefix (for example
ROUP_ACCD_parallel and ROUP_ACCC_async). The legacy
ACC_* aliases are not emitted by the generator.
Known Limitations
The shim inherits ROUP’s canonical token choices. Generated OpenACC macros use the ROUP_ACC_* prefix (for example ROUP_ACCD_parallel); legacy ACC_* names are intentionally not emitted.
Documentation
Complete documentation in compat/accparser/:
- README.md - Complete compatibility layer guide with build instructions and examples
For detailed ROUP API documentation, see API Reference.
Requirements
- Rust toolchain (for ROUP core)
- CMake 3.10+
- C++11 compiler (gcc/clang)
- Git (for submodule management)
- NO antlr4 required!
CI/CD
The compatibility layer is tested automatically via GitHub Actions (.github/workflows/ci.yml):
- Tests ROUP core (always)
- Tests compat layer (if submodule initialized)
- Verifies library builds successfully
- Validates drop-in functionality
- Checks constants synchronization (checksum validation)
FAQ
Q: Do I need to change my code? A: No! It’s a drop-in replacement with the same API.
Q: What about ANTLR4 dependency? A: ROUP completely eliminates the ANTLR4 dependency. You only need Rust, CMake, and a C++ compiler.
Q: What if I don’t need compat layer? A: ROUP works perfectly standalone. The compat layer is optional.
Q: How do I get accparser upgrades?
A: git submodule update --remote pulls latest accparser automatically.
Q: What about performance? A: ROUP’s hand-written parser is 2-5x faster than ANTLR-generated parsers for typical OpenACC pragmas.
Q: Is it stable? A: Thoroughly tested (38 tests) and ready for use. All tests passing.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: See Contributing Guide