Skip to content

Latest commit

 

History

History
114 lines (92 loc) · 2.87 KB

File metadata and controls

114 lines (92 loc) · 2.87 KB

accparser

accparser (ACCP): a standalone OpenACC parser based on ANTLR 4. It supports both C and Fortran.

Prerequisite

accparser requires ANTLR 4 and its C++ runtime, which are available on Ubuntu 20.04 or later. For other systems, they may need to be manually built.

sudo apt update
sudo apt install -y \
    antlr4 \
    libantlr4-runtime-dev \
    build-essential \
    g++ \
    cmake

clang/clang++ and gcc/g++ are both fine.

Build

mkdir build
cd build
cmake ..
make

It will produce a library libaccparser.so and an executable acc_demo.out.

Header Organization

accparser provides two levels of headers for different use cases:

For Standard Usage (Recommended)

#include "OpenACCParser.h"  // Standalone parser interface
  • No ANTLR dependencies required
  • Suitable for external parser implementations
  • Provides parseOpenACC() and C API functions

For ANTLR-based Development

#include "OpenACCASTConstructor.h"  // ANTLR implementation details
  • Requires ANTLR4 runtime
  • For extending the ANTLR-based parser
  • Includes OpenACCParser.h transitively

For AST Manipulation Only

#include "OpenACCIR.h"  // AST node classes
  • No parser dependencies
  • For working with existing AST structures

This separation allows external projects to provide alternative parser implementations while reusing the OpenACC IR classes.

Run

Given a test file foo.txt with the following content to try accparser.

Input:

#pragma acc parallel private(a, b, c)
./acc_demo.out ./foo.txt

The output includes the OpenACC source code, recognized tokens, parse tree, and the OpenACC code unparsed from the generated OpenACC IR.

Output:

======================================
Line: 1
GIVEN INPUT: #pragma acc parallel private(a, b, c)
======================================
TOKEN : TOKEN_STRING
ACC : "acc"
PARALLEL : "parallel"
PRIVATE : "private"
LEFT_PAREN : "("
EXPR : "a"
EXPR : "b"
EXPR : "c"
RIGHT_PAREN : ")"
EOF : "<EOF>"
======================================
PARSE TREE:
(accparallelprivate(abc)<EOF> acc 
        (parallelprivate(abc) 
            (parallelprivate(abc) parallel 
                (private(abc) 
                    (private(abc) 
                        (private(abc) private ( 
                            (abc 
                                (a a) 
                                (b b) 
                                (c c)) )))))) <EOF>)
======================================
GENERATED OUTPUT: #pragma acc parallel private (a, b, c)
======================================

At each line of the parse tree section, the output follows the format (root child_1 child_2 ... child_n). For example, the first line shows that the root is accparallelprivate(abc). Its children include acc and parallelprivate(abc). The latter has its own children that are listed at other lines.