Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ jobs:

- name: Install unit tests requirements
run: |
python3 -m venv .env
. .env/bin/activate
pip install -r tests/unit_tests/requirements.txt
pipx install uv
uv sync

- name: Build
run: |
. .env/bin/activate
. .venv/bin/activate

cmake . \
-Bbuild \
Expand Down Expand Up @@ -83,13 +82,12 @@ jobs:

- name: Install unit tests requirements
run: |
python3 -m venv .env
. .env/bin/activate
pip install -r tests/unit_tests/requirements.txt
pipx install uv
uv sync

- name: Build
run: |
. .env/bin/activate
. .venv/bin/activate

cmake . \
-Bbuild \
Expand All @@ -112,10 +110,13 @@ jobs:

- name: Install unit tests requirements
run: |
pip install -r tests\unit_tests\requirements.txt
pipx install uv
uv sync

- name: Build
run: |
.\.venv\Scripts\activate

cmake . -Bbuild

cmake --build build --config Release
Expand Down Expand Up @@ -181,13 +182,12 @@ jobs:

- name: Install unit tests requirements
run: |
python3 -m venv .env
. .env/bin/activate
pip install -r tests/unit_tests/requirements.txt
pipx install uv
uv sync

- name: Build
run: |
. .env/bin/activate
. .venv/bin/activate

cmake . \
-Bbuild \
Expand Down
100 changes: 50 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# A compiler front end for the C++ language

cxx-frontend is a work-in-progress compiler frontend for C++23
cxx-frontend is a work-in-progress compiler frontend for C++26 and C23

The compiler frontend is designed to be a powerful tool for developers, enabling them to parse, analyze, and modify C++ source code. This project aims to provide a robust foundation for building a complete C++ frontend, staying
up-to-date with the latest language features and standards.
Expand All @@ -17,53 +17,60 @@ For updates, improvements, and recent features in cxx-frontend, please consult t

- **Multi-Language Support**: In addition to C++, the library provides APIs for TypeScript and JavaScript.

- **C++-23 Support**: Latest language enhancements, syntax, and features (WIP).
- **C++-26 and C23 Support**: Latest language enhancements, syntax, and features (WIP).

## Syntax Checker and AST Browser Showcase
## Playground

Storybook and CodeMirror are used to demonstrate how to create a syntax checker and navigate the Abstract Syntax Tree (AST)
The playground uses the Monaco Editor to demonstrate how to create a syntax checker and navigate the Abstract Syntax Tree (AST).

https://robertoraggi.github.io/cplusplus/

## Installing from npm
## Native Build and CLI tools

To integrate the latest stable version of the C++ Compiler Frontend bindings into your project, you can install them from npm:
On Linux, macOS and Windows:

install the python packages required to run the unit tests (optional)

```sh
npm install cxx-frontend
uv sync && source .venv/bin/activate
```

Once installed, you can use the bindings in your Node.js or web projects as needed.
configure the source code

## Getting Started Using Example Projects
```sh
cmake --preset default
```

These projects are pre-configured and serve as starting points for various [use cases](https://github.com/robertoraggi/cplusplus/tree/main/templates).
build

For Node.js
```sh
cmake --build build
```

run the unit tests

```sh
npx degit robertoraggi/cplusplus/templates/cxx-parse cxx-parse
cd cxx-parse
npm install
node .
cd build
ctest --progress
```

For web-based applications, use these commands to clone, set up, and start a development server:
Dump the AST to stdout

```sh
npx degit robertoraggi/cplusplus/templates/cxx-browser-esm-vite cxx-browser-esm-vite
cd cxx-browser-esm-vite
npm install
npm run dev
./build/src/frontend/cxx tests/manual/source.cc -ast-dump
```

## Build the npm package (requires docker)

prepare the package

```sh
# prepare the package
npm ci
```

compile WASM and TypeScript code

# compile WASM and TypeScript code
```sh
npm run build:cxx-frontend
```

Expand All @@ -72,55 +79,48 @@ npm run build:cxx-frontend
```sh
npm ci
npm run build:wasi
```

# run the C++ front end CLI tool using wasmtime
run the C++ front end CLI tool using wasmtime

```sh
wasmtime \
--mapdir=/::build.wasi/install \
--mapdir tests::tests \
build.wasi/install/usr/bin/cxx.wasm -- \
tests/manual/source.cc -ast-dump
```

## Native Build and CLI tools
## Installing from npm

On Linux, macOS and Windows:
To integrate the latest stable version of the C++ Compiler Frontend bindings into your project, you can install them from npm:

```sh
# install the python packages required to run the unit tests (optional)
pip install -r tests/unit_tests/requirements.txt

# configure the source code
cmake . \
-G Ninja \
-B build \
-DCMAKE_BUILD_TYPE=Release \
-DCXX_INTERPROCEDURAL_OPTIMIZATION=1
npm install cxx-frontend
```

# build
cmake --build build
Once installed, you can use the bindings in your Node.js or web projects as needed.

# run the unit tests
cd build
ctest --progress
```
## Getting Started Using Example Projects

## Serialize the AST
These projects are pre-configured and serve as starting points for various [use cases](https://github.com/robertoraggi/cplusplus/tree/main/templates).

Use `-emit-ast` to serialize the AST of a C++ program to a flatbuffer binary file
For Node.js

```sh
# serialize the AST
$ ./build/src/frontend/cxx -emit-ast source.cc -o source.ast
npx degit robertoraggi/cplusplus/templates/cxx-parse cxx-parse
cd cxx-parse
npm install
node .
```

You can use any flatbuffers supported decoder to read the AST, e.g.
For web-based applications, use these commands to clone, set up, and start a development server:

```sh
# Use flatc to dump the AST to JSON
$ ./build/_deps/flatbuffers-build/flatc --raw-binary -t build/src/parser/cxx/ast.bfbs -- source.ast

$ ll source.*
source.ast source.cc source.json
npx degit robertoraggi/cplusplus/templates/cxx-browser-esm-vite cxx-browser-esm-vite
cd cxx-browser-esm-vite
npm install
npm run dev
```

## License
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "cplusplus"
version = "1.1.27"
description = "A compiler frontend for C++23"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"filecheck>=1.0.2",
"lit>=18.1.8",
]
2 changes: 0 additions & 2 deletions tests/unit_tests/requirements.txt

This file was deleted.

36 changes: 36 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.