Skip to content
João Bispo edited this page May 4, 2023 · 10 revisions

Introduction

Clava is a C/C++ (and OpenCL and CUDA...) source-to-source compiler. It parses code into an Abstract-Syntax Tree (AST), which you can analyze or transform a custom script and generate the code again.

It is based on the LARA framework, so it uses LARA scripts (basically JavaScript) to analyze and transform the AST.

Why a source-to-source compiler?

Some of the things we do with Clava you could implement directly on a compiler such as gcc or Clang. Why use Clava?

  • Ease of use: Clava provides a JavaScript-based interface with high-level abstractions, and can be installed in under a minute. No need to mess with the internals of a compiler;
  • Gradual learning curve: you can start with simple examples, and advance to more complex transformations gradually;
  • No compiler lock-in: you can do analyses/transformations with Clava, and then use any compiler to compile your code;

Examples

Clava AST

Clava uses the concept of "join points" to refer to points of interest that can be selected in the underlying AST. They work as a wrapper around the AST nodes, and are a key concept in the LARA framework which allows to reuse the same technology across source-to-source compilers for different languages.

The image below shows the available join points in Clava, and their class hierarchy relationships:

Clava Join Point Hierarchy

Clone this wiki locally