Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/klitsche/clang-ffi
A library for PHP exposing libclang via FFI.
https://github.com/klitsche/clang-ffi
clang-ffi ffi libclang llvm php php-ffi wrapper
Last synced: about 1 month ago
JSON representation
A library for PHP exposing libclang via FFI.
- Host: GitHub
- URL: https://github.com/klitsche/clang-ffi
- Owner: klitsche
- License: mit
- Created: 2021-01-01T21:51:36.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-08T07:38:32.000Z (almost 3 years ago)
- Last Synced: 2024-11-16T08:45:39.130Z (about 2 months ago)
- Topics: clang-ffi, ffi, libclang, llvm, php, php-ffi, wrapper
- Language: PHP
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# clang-ffi
[![Build](https://github.com/klitsche/clang-ffi/workflows/Build/badge.svg)](https://github.com/klitsche/clang-ffi/actions?query=workflow%3Atest)
[![Build macOS](https://github.com/klitsche/clang-ffi/workflows/Build%20macOS/badge.svg)](https://github.com/klitsche/clang-ffi/actions?query=workflow%3Atest-macos)[![Test Coverage](https://api.codeclimate.com/v1/badges/439f6cf45adc85c463cc/test_coverage)](https://codeclimate.com/github/klitsche/clang-ffi/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/439f6cf45adc85c463cc/maintainability)](https://codeclimate.com/github/klitsche/clang-ffi/maintainability)
[![Packagist](https://img.shields.io/packagist/v/klitsche/clang-ffi)](https://packagist.org/packages/klitsche/clang-ffi)A library for PHP exposing libclang via FFI.
It allows easy traversing and analyzing of an abstract syntax tree of a c / c++ file.
Unfortunately PHP FFI does not currently support Struct By Value as parameter or return value in
function calls. That is why a c based wrapper is provided for libclang itself, which can then be
bound via FFI. This wrapper must be compiled before use.The wrapper is taken from [dart ffigen](https://github.com/dart-lang/ffigen) and has been slightly extended.
Expect breaking changes along all 0.* pre-releases.
## Requirements
* PHP >= 7.4
* FFI extension enabled
* LLVM >= 9 with clang and libclang-dev## Quick Start
Install llvm with clang ...
... on macOS (see https://formulae.brew.sh/formula/llvm)
brew install llvm@11
... on Debian / Ubuntu (see https://apt.llvm.org/)
apt-get update; \
apt-get install wget lsb-release software-properties-common ca-certificates gnupg; \
wget -q https://apt.llvm.org/llvm.sh; \
chmod +x llvm.sh; \
sudo ./llvm.sh 11; \
apt-get install libclang-11-dev;Install in your project
composer require klitsche/clang-ffi
Add to composer.json (this will trigger compilation of wrapped libclang library)
```json
"scripts": {
"post-autoload-dump": "Klitsche\\Clang\\FFI\\libclang\\Compiler::run",
},
```Dump autoload to trigger compilation
composer dump-autoload
## Run examples
Checkout & prepare
git clone https://github.com/klitsche/clang-ffi.git; \
cd clang-ffi; \
docker-compose build;Print parsed file
docker-compose run --rm php74 php examples/print.php
Collect and dump simplified AST nodes as json
docker-compose run --rm php74 php examples/json.php
Dump found issues during parsing
docker-compose run --rm php74 php examples/issues.php
## Todos
* [ ] Add ffigen
* [ ] Add multiversion support for llvm >9 (some const values are different)
* [ ] Add documentation
* [ ] Add support for Windows## License
See [LICENSE.md](LICENSE.md) for details.
[LICENSE.wrapper.c.md](LICENSE.wrapper.c.md) covers file src/FFI/libclang/wrapper.c.