Skip to content

Commit 174c708

Browse files
Merge pull request #55 from UnionCompilerDesign/dev
Dev
2 parents f993237 + ee5bd9f commit 174c708

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4045
-3260
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["-W", "unused-imports", "-W", "missing-docs", "-W", "unused-variables", "-W", "dead-code"]

.github/ISSUE_TEMPLATE/issue.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Details
2+
3+
### Issue Type
4+
- [ ] Feature
5+
- [ ] Bugfix
6+
- [ ] Documentation
7+
- [ ] Refactoring
8+
- [ ] Other:
9+
10+
### Requirements
11+
12+
### Dependencies
13+
14+
### Notes

.github/README_TEMPLATE/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# [Module Name]
2+
3+
## Overview
4+
This document provides details about the [Module Name] in the SafeLLVM project. The [Module Name] module is designed to [briefly describe the purpose and functionality].
5+
6+
## Features
7+
List the main features of the module:
8+
- **Feature 1**:
9+
- **Feature 2**;
10+
11+
## Usage
12+
Explain how to use the module with examples:
13+
14+
```
15+
use safe_llvm::module_name::{function1, function2};
16+
17+
function1(); // Example usage of function1
18+
function2(); // Example usage of function2
19+
```
20+
21+
Provide any necessary warnings or special instructions for using the module correctly.
22+
23+
## FAQ
24+
25+
## Further Information
26+
For further information or questions regarding the use of `[Module Name]`, feel free to contact the main contributors or raise an issue on the GitHub repository.

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: SafeLLVM
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
13+
jobs:
14+
build-and-test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Install Dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y ca-certificates wget curl gnupg software-properties-common build-essential cmake libfreetype6-dev libfontconfig1-dev xclip valgrind libzstd-dev
25+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
26+
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main"
27+
sudo apt-get update
28+
sudo apt-get install -y clang-17 llvm-17 llvm-17-dev llvm-17-tools libpolly-17-dev
29+
30+
- name: Install Rust
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: stable
34+
profile: minimal
35+
components: rustfmt, clippy
36+
override: true
37+
38+
- name: Set Environment Variables
39+
run: |
40+
echo "LLVM_SYS_170_PREFIX=/usr/lib/llvm-17" >> $GITHUB_ENV
41+
echo "PATH=$PATH:/root/.cargo/bin:/usr/lib/llvm-17/bin" >> $GITHUB_ENV
42+
43+
- name: Build Project
44+
uses: actions-rs/cargo@v1
45+
with:
46+
command: build
47+
args: --all --verbose
48+
49+
- name: Run Tests
50+
uses: actions-rs/cargo@v1
51+
with:
52+
command: test
53+
args: --all --verbose

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/Cargo.lock
22
/target/
3-
/Dockerfile
43
/app.log
54
/dev_toolchain/target/
65
/dev_toolchain/app.log
76
/dev_toolchain/Cargo.lock
7+
/.vscode/
8+
/jit/target/
9+
/jit/app.log
10+
/ir/target/
11+
/ir/app.log

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing to SafeLLVM
2+
3+
Welcome to the SafeLLVM project! We appreciate your interest in contributing to SafeLLVM, a wrapper around **[llvm-sys](https://github.com/tari/llvm-sys.rs)** designed to serve as the backend for the Simple Instructional C99 Compiler (SICC).
4+
5+
## Getting Started
6+
7+
Before contributing, please make sure to familiarize yourself with the project structure and the goals of both SafeLLVM and SICC. This understanding will help you make meaningful contributions that align with the project's objectives.
8+
9+
### Setting Up Your Development Environment
10+
11+
1. **Install the prerequisites found in README.md**
12+
13+
2. **Fork and clone the repository:**
14+
Start by cloning the SafeLLVM repository to your local machine.
15+
```
16+
git clone [email protected]:UnionCompilerDesign/safe_llvm.git
17+
```
18+
19+
3. **Build and test the project:**
20+
```
21+
cd safe_llvm
22+
cargo build --all
23+
cargo test --all
24+
```
25+
26+
## Making Contributions
27+
28+
### Reporting Bugs
29+
30+
If you find a bug, please report it by opening a new issue on GitHub. Include as much detail as possible and please use the template found in `safe_llvm/.github/ISSUE_TEMPLATE`.
31+
32+
### Suggesting Enhancements
33+
34+
We welcome suggestions for improvements! If you have an idea to enhance SafeLLVM, please create an issue to discuss so we can discuss it.
35+
36+
### Pull Requests
37+
38+
We actively welcome your pull requests:
39+
40+
1. Fork the repo and create your branch from `main`.
41+
2. If you've added code that should be tested, add tests.
42+
3. Ensure your code lints (use `cargo clippy`).
43+
4. Issue the pull request!
44+
45+
### Coding Guidelines
46+
47+
- Follow the [Rust style guide](https://doc.rust-lang.org/1.0.0/style/README.html).
48+
- Write clean, readable code and include comments where necessary.
49+
- Ensure that all tests pass before you make a pull request.
50+
51+
## Recognition
52+
53+
Contributors who make significant improvements will be recognized as "Contributors" in the project README.
54+
55+
Thank you for your interest in contributing to SafeLLVM! We look forward to your contributions and are excited to see how the project grows and evolves with your help.

Cargo.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,32 @@ edition = "2021"
55

66
[dependencies]
77
llvm-sys = "170"
8-
mockall = "0.10.2"
98
slog = "2.7"
109
slog-async = "2.6"
1110
slog-term = "2.8"
1211
slog-json = "2.4"
1312

13+
ir = { path = "./ir" }
14+
analysis = { path = "./analysis" }
15+
common = { path = "./common" }
16+
jit = { path = "./jit" }
17+
logging = { path = "./logging" }
18+
1419
[dev-dependencies]
1520
llvm-sys = "170"
16-
mockall = "0.10.2"
1721
slog = "2.7"
1822
slog-async = "2.6"
1923
slog-term = "2.8"
20-
slog-json = "2.4"
24+
slog-json = "2.4"
25+
26+
[workspace]
27+
members = [
28+
"./ir",
29+
"./analysis",
30+
"./common",
31+
"./jit",
32+
"./logging",
33+
]
34+
35+
[build-dependencies]
36+
pkg-config = "0.3"

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ubuntu:20.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
WORKDIR /usr/src/safe_llvm
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
ca-certificates \
10+
wget \
11+
curl \
12+
gnupg \
13+
software-properties-common \
14+
build-essential \
15+
cmake \
16+
libfreetype6-dev \
17+
libfontconfig1-dev \
18+
xclip \
19+
valgrind \
20+
libzstd-dev && \
21+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
22+
apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" && \
23+
apt-get update && \
24+
apt-get install -y clang-17 llvm-17 llvm-17-dev llvm-17-tools libpolly-17-dev && \
25+
rm -rf /var/lib/apt/lists/*
26+
27+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
28+
29+
ENV PATH="/root/.cargo/bin:/usr/lib/llvm-17/bin:$PATH"
30+
31+
ENV LLVM_SYS_170_PREFIX="/usr/lib/llvm-17"
32+
33+
COPY . .
34+
35+
RUN cargo build --verbose
36+
37+
CMD ["bash"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2024] Caleb L'Italien
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Safe LLVM
2+
3+
## Contributors
4+
Caleb L'Italien, John Daly
5+
6+
## Overview
7+
SafeLLVM is a Rust-based library designed to provide a safe and user-friendly interface to llvm-sys. It is developed specifically for the Simple Instructional C99 Compiler (SICC). The library aims to encapsulate the complexity of LLVM’s API, making it accessible for undergraduate work.
8+
9+
## Disclaimer
10+
11+
SafeLLVM is designed for educational purposes and is not intended for production use. If you are looking for a production-level LLVM crate for Rust projects, consider using the following crates:
12+
13+
- **[Inkwell](https://github.com/TheDan64/inkwell)**
14+
- **[llvm-ir](https://github.com/cdisselkoen/llvm-ir)**
15+
16+
## Project Structure
17+
- `analysis/`: Tools for performing various analyses on LLVM IR.
18+
- `common/`: Common utilities and helper functions shared across the project.
19+
- `ir/`: Manages the creation of LLVM Intermediate Representation (IR).
20+
- `jit/`: Implements an ExecutionEngine for execution of pre-compiled LLVM modules.
21+
- `logging/`: Handles logging functionalities for debugging.
22+
23+
## Getting Started
24+
25+
### Usage
26+
To use SafeLLVM in your Rust projects, you can include it directly via Cargo by adding it as a dependency in your `Cargo.toml` file using its GitHub repository URL. Here's how to do it:
27+
28+
1. **Add SafeLLVM as a dependency in your `Cargo.toml`:**
29+
```toml
30+
[dependencies]
31+
safe_llvm = { git = "[email protected]:UnionCompilerDesign/safe_llvm.git", branch = "main" }
32+
```
33+
34+
2. **Refer to specific `README`s in each directory:**
35+
For more specific usage details, please refer to the READMEs located in each directory. These documents provide further instructions and examples on how to use the components within SafeLLVM.
36+
37+
### How to Contribute
38+
Contributions are welcome! Please refer to the `CONTRIBUTING` file for guidelines on how to contribute.
39+
40+
### License
41+
Distributed under the MIT License. See the `LICENSE` file for more details.
42+
43+
### Acknowledgements
44+
Special thanks to Professor Aaron Cass of Union College for his guidance and expertise throughout the development of this project.
45+
46+
### Contact
47+
For any inquiries, contact Caleb L'Italien at [email protected].

analysis/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "analysis"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
name = "analysis"
8+
path = "src/lib.rs"
9+
10+
[dependencies]
11+
llvm-sys = "170"
12+
common = { path = "../common" }

analysis/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Analysis Tools for SafeLLVM
2+
3+
## Overview
4+
The Analysis module is a component of the SafeLLVM project for checking the correctness of LLVM modules and functions.
5+
6+
## Features
7+
- **Module Validator**: Determines if an LLVM module is well-formed.
8+
- **Function Validator**: Determines if an LLVM function is well-formed.
9+
10+
## Usage
11+
1. Initialize the Validator with a module: Create a Validator instance by passing a protected reference to the LLVM module you wish to validate.
12+
2. Validate Functions or Modules:
13+
- To validate an LLVM module, call the is_valid_module() method on your Validator instance:
14+
```
15+
let validator = Validator::new(module_pointer);
16+
let is_module_valid = validator.is_valid_module();
17+
eprintln!("Module is valid: ", is_module_valid);
18+
```
19+
- Similarly, to validate a specific function within a module, provide a protected reference to the LLVM function to the is_valid_function() method:
20+
```
21+
let validator = Validator::new(module_pointer);
22+
let is_function_valid = validator.is_valid_function(function_pointer);
23+
eprintln!("Function is valid: ", is_function_valid);
24+
```
25+
26+
Provide any necessary warnings or special instructions for using the module correctly, such as ensuring that pointers are correctly managed and threads are safely handled due to the use of Arc and RwLock.
27+
28+
## FAQ
29+
30+
## Further Information
31+
For further information or questions regarding the use of the analysis tools, feel free to contact the main contributors or raise an issue on the GitHub repository.

analysis/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Analysis Toolchain.
2+
3+
pub mod validator;

0 commit comments

Comments
 (0)