Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ircmaxell/php-cfg
A Control Flow Graph implementation in PHP
https://github.com/ircmaxell/php-cfg
Last synced: 9 days ago
JSON representation
A Control Flow Graph implementation in PHP
- Host: GitHub
- URL: https://github.com/ircmaxell/php-cfg
- Owner: ircmaxell
- License: mit
- Created: 2015-06-24T15:23:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-24T13:08:46.000Z (6 months ago)
- Last Synced: 2024-09-19T03:14:32.570Z (about 2 months ago)
- Language: PHP
- Size: 552 KB
- Stars: 244
- Watchers: 14
- Forks: 43
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://github.com/ircmaxell/php-cfg/actions/workflows/main.yml/badge.svg)](https://github.com/ircmaxell/php-cfg/actions)
[![Latest Stable Version](https://poser.pugx.org/ircmaxell/php-cfg/v/stable)](https://packagist.org/packages/ircmaxell/php-cfg)# PHP-CFG
Pure PHP implementation of a control flow graph (CFG) with instructions in static single assignment (SSA) form.
The used SSA construction algorithm is based on "Simple and Efficient Construction of Static Single Assignment Form" by
Braun et al. This algorithm constructs SSA form directly from the abstract syntax tree, without going through a non-SSA
IR first. If you're looking for dominance frontiers, you won't find them here...The constructed SSA form is minimal and pure (or is supposed to be).
## Usage
To bootstrap the parser, you need to give it a `PhpParser` instance:
```php
$parser = new PHPCfg\Parser(
(new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7)
);
```
Then, just call parse on a block of code, giving it a filename:
```php
$script = $parser->parse(file_get_contents(__FILE__), __FILE__);
```
To dump the graph, simply use the built-in dumper:
```php
$dumper = new PHPCfg\Printer\Text();
echo $dumper->printScript($script);
```