|
| 1 | +--- |
| 2 | +id: frontends |
| 3 | +title: Frontends |
| 4 | +bookCollapseSection: true |
| 5 | +weight: 135 |
| 6 | +--- |
| 7 | + |
| 8 | +## Frontends |
| 9 | + |
| 10 | +Joern contains multiple frontends, each responsible for parsing the source code and generating the AST for their respective language. `X2CPG` is the base on which all of the other frontends are built, and contains common structures by all of the languages. Each frontend contains the base arguments from `x2cpg`, as well as custom arguments that are frontend specific. See each respective languages' page for a detailed explanation on what arguments are available and what each of the arguments do. |
| 11 | + |
| 12 | +## Invoking a specific frontend |
| 13 | +To generate the AST for for some program with a specific frontend, invoke the desired frontend from the `joern-cli/frontends` directory using the generated script. If the script is not there, make sure that Joern has been staged with `sbt`. As an example, to parse a given Python directory and generate an AST: |
| 14 | +```bash |
| 15 | +cd joern-cli/frontends/pysrc2cpg/ |
| 16 | +sbt scala stage |
| 17 | +./pysrc2cpg /some/input/path --output someOutput --venvDir /some/venv/dir |
| 18 | +``` |
| 19 | +The arguments given after the `pysrc2cpg` command can be a mixture of the args found in `x2cpg`, as well as the language specific args for Python. |
| 20 | + |
| 21 | +If you would like to generate the full `CPG` for a given source directory, you can do so using the `joern-parse` command: |
| 22 | +```bash |
| 23 | +./joern-parse /some/input/path --language PYTHONSRC --frontend-args --venvDir /some/venv/dir |
| 24 | +``` |
| 25 | +The language argument selects the frontend used to generate the AST. If this argument is omitted, `joern-parse` will select a frontend based on the supported file type with the largest number of files in the given input directory. The arguments passed after `--frontend-args` will be passed to the frontend that is being invoked. |
| 26 | + |
| 27 | +Below is a list of each of the different frontends and the languages that they support: |
| 28 | +| **Frontend** | **Language** | **Language Arg** | |
| 29 | +| - | - | - | |
| 30 | +| `c2cpg` | `C` | `--language C` | |
| 31 | +| `csharp2cpg` | `C#` | `--language CSHARPSRC` | |
| 32 | +| `ghidra2cpg` | `Ghidra` | `--language GHIDRA` | |
| 33 | +| `gosrc2cpg` | `Golang` | `--language GOLANG` | |
| 34 | +| `javasrc2cpg` | `Java` | `--language JAVASRC` | |
| 35 | +| `jimple2cpg` | `Java` | `--language JAVA` | |
| 36 | +| `jssrc2cpg` | `Javascript` | `--language JAVASCRIPT` | |
| 37 | +| `kotlin2cpg` | `Kotlin` | `--language KOTLIN` | |
| 38 | +| `php2cpg` | `PHP` | `--language PHP` | |
| 39 | +| `pysrc2cpg` | `Python` | `--language PYTHONSRC` | |
| 40 | +| `rubysrc2cpg` | `Ruby` | `--language RUBYSRC` | |
| 41 | +| `swiftsrc2cpg` | `Swift` | `--language SWIFTSRC` | |
0 commit comments