Llvm grammar for tree-sitter
Project description
Tree-sitter LLVM
A Tree-sitter grammar for LLVM IR assembly (.ll). This parser aims to closely follow LLVM's textual IR as parsed by LLParser, including modules, functions, types, instructions, attributes, metadata, and more.
Highlights and captures are provided in queries/highlights.scm.
Installation
-
Node.js
- npm install tree-sitter-llvm
- Usage:
- const Parser = require('tree-sitter');
- const llvm = require('tree-sitter-llvm');
- const parser = new Parser();
- parser.setLanguage(llvm);
- const tree = parser.parse('%x = alloca i32');
-
Rust
- Cargo.toml:
- tree-sitter-llvm = "1.1.0"
- Usage:
- let mut parser = tree_sitter::Parser::new();
- let language = tree_sitter_llvm::LANGUAGE;
- parser.set_language(&language.into()).unwrap();
- Cargo.toml:
-
Python (tree-sitter >= 0.25)
- pip install tree-sitter-llvm
- Usage:
- from tree_sitter import Language, Parser
- import tree_sitter_llvm
- parser = Parser()
- parser.set_language(Language(tree_sitter_llvm.language()))
-
C
- Include bindings/c/tree-sitter-llvm.h and link the generated parser in src/.
- The language symbol is: const TSLanguage *tree_sitter_llvm(void);
-
Go
- The binding is in bindings/go. Example with go-tree-sitter:
- import (
- "github.com/tree-sitter/go-tree-sitter"
- llvm "path/to/this/repo/bindings/go"
- )
- parser := sitter.NewParser()
- parser.SetLanguage(sitter.NewLanguage(llvm.Language()))
- import (
- The binding is in bindings/go. Example with go-tree-sitter:
-
Swift (SwiftPM)
- Add this repository as a dependency and use TreeSitterLlvm target.
- Example:
- import SwiftTreeSitter
- import TreeSitterLlvm
- let parser = Parser()
- let language = Language(language: tree_sitter_llvm())
- try parser.setLanguage(language)
Status and scope
- Language name: llvm (as used by grammar.js)
- Targets LLVM IR textual format (.ll). MIR is out of scope.
- Grammar rules are modeled after LLVM's LLParser constructs (target definitions, declarations/definitions, instructions incl. alloca, getelementptr, phi, cmpxchg, atomicrmw, br; comdat; metadata; summaries; attributes; etc.).
Queries
- queries/highlights.scm contains basic highlighting captures for common editors that consume Tree-sitter queries.
Development
- Prerequisites: Node.js, npm, and tree-sitter-cli (npx tree-sitter works via devDependencies)
- Generate/rebuild parser C sources:
- npx tree-sitter generate
- Run grammar tests (corpus under test/corpus):
- npx tree-sitter test
- Rust tests (ensures the language loads):
- cargo test
- Python tests:
- pip install -e .[core]
- pytest bindings/python/tests
- Swift tests:
- swift test
Example
- See example/ and test/corpus for sample LLVM IR snippets and expected parses.
Contributing
- Issues and PRs are welcome. Please run tree-sitter tests and format code before submitting.
License
- MIT (see LICENSE)
Acknowledgements
- Based on LLVM's existing bindings and textual IR structure: https://github.com/llvm/llvm-project/blob/main/llvm/utils/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_llvm-1.1.0.tar.gz.
File metadata
- Download URL: tree_sitter_llvm-1.1.0.tar.gz
- Upload date:
- Size: 404.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b51d82413afd1738e75e2d766abc78ecf63ed77696c4dbd6d3d954881a9b1b1
|
|
| MD5 |
10cbee3fa8fc71f67e8f84ffddcaab09
|
|
| BLAKE2b-256 |
d1502e43a514dbaa5c525d419b22cadaa89b1665590d6bcf7fbb512472aa4002
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-win_arm64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 145.9 kB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcbaee9705715fd18f10612c6564e0acf8ab32c51828730b5d6161ab2f3725e3
|
|
| MD5 |
c50f3659c20a20cccaa4b529a5c31f0d
|
|
| BLAKE2b-256 |
1485377f3a9255e05a248b3806628285e440e5d20e854f51f427d621b0b4ad6a
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 153.6 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf8b35a7e7025b2cb8902d9ad8ac6cf1b5043648dd33409ad1937ea42f6b8b28
|
|
| MD5 |
34a691a3195bc34e47447e62dbb21875
|
|
| BLAKE2b-256 |
b4c9084dbcab733bdf0c3d14688decd578a02420ab3edab19c92419173ee5b57
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 163.2 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8045bbe6474c88e6e2e8217a636c8cda0c48d56c9a35af446e27325e9b970585
|
|
| MD5 |
7abc9a5d49cf8d7fc42229d38102d479
|
|
| BLAKE2b-256 |
86ed34fa3e32cf0f262b461d6a3030b42b8eff49fb42847311fadff15c31210f
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 162.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d81b31b4d2d476db6fa1d92b890564195552673a59c096f590fefc088ceb5885
|
|
| MD5 |
976c4fc7b2fbb176d9cd2b21de0632bd
|
|
| BLAKE2b-256 |
edfdddbac1ac922b488712061894cb77f9c34477b65880b39265a61175c8a772
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 166.3 kB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ece3c0c6cd6f7f3bf259e5d5ff5e47545e878dd8f49458797e708cab22bd39
|
|
| MD5 |
68bf8015fbb52429d88d74c17a95e4c8
|
|
| BLAKE2b-256 |
dbb2b19fa2f2fa73dbab072237401685ce28a7d78a7d8999f1ba7686631770b9
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 160.1 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb184ad2e7f78e0df79c59ce6d2ac2baf3f0aaaf88abcc4726b37344bd50c3d
|
|
| MD5 |
c4fae19bb927e77eda7c021be7fbbf60
|
|
| BLAKE2b-256 |
f07f1d08a444dc7257659e83714b93706b2f5fc886339b7dff6f32df0d87ac81
|
File details
Details for the file tree_sitter_llvm-1.1.0-cp38-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: tree_sitter_llvm-1.1.0-cp38-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 146.3 kB
- Tags: CPython 3.8+, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee10b08af8c30ec199ffcde6934885f9b375d7e26b0a5364e61e122170ce5701
|
|
| MD5 |
3ea3cf224312c7ee2640360d45c07f94
|
|
| BLAKE2b-256 |
6282a5d8aaf650339f196d85b5ed6e8951bb2b96d3013016bc0339835ff820df
|