Skip to content
João Bispo edited this page Jul 18, 2021 · 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), then you can analyze or transform it, and generate 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;

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 they class hierarchy relationships:

Clava Join Point Hierarchy

Clone this wiki locally