Skip to content

Commit

Permalink
ci: download llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Mar 21, 2024
1 parent 0d4c14e commit 5b7029f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 48 deletions.
59 changes: 37 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,53 @@ on:

env:
CARGO_TERM_COLOR: always
LLVM_VERSION: "17.0"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
name: test ${{ matrix.rust }} ${{ matrix.flags }}
name: test
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
rust: ["stable", "nightly"]
# flags: [""]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
- uses: KyleMayes/install-llvm-action@v1
with:
toolchain: ${{ matrix.rust }}
version: ${{ env.LLVM_VERSION }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: test
run: cargo test --workspace # ${{ matrix.flags }}
run: cargo test --workspace

# feature-checks:
# runs-on: ubuntu-latest
# timeout-minutes: 30
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# - uses: taiki-e/install-action@cargo-hack
# - uses: Swatinem/rust-cache@v2
# with:
# cache-on-failure: true
# - name: cargo hack
# run: cargo hack check --feature-powerset --depth 2
feature-checks:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2

clippy:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
- uses: dtolnay/rust-toolchain@clippy
- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -64,13 +67,25 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo doc --workspace --all-features --no-deps --document-private-items
env:
RUSTDOCFLAGS: "--cfg docsrs -D warnings"
RUSTDOCFLAGS:
--cfg docsrs -D warnings --show-type-layout --generate-link-to-definition
--enable-index-page -Zunstable-options
# - name: Deploy documentation
# uses: peaceiris/actions-gh-pages@v3
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: target/doc
# force_orphan: true

fmt:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions crates/revm-jit-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! TODO

#![allow(missing_docs)]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod context;
pub use context::*;
Expand Down
1 change: 1 addition & 0 deletions crates/revm-jit-cranelift/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use cranelift::{codegen::ir::StackSlot, prelude::*};
use cranelift_jit::{JITBuilder, JITModule};
Expand Down
1 change: 1 addition & 0 deletions crates/revm-jit-llvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! TODO
// #![doc = include_str!("../README.md")]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use inkwell::{
attributes::{Attribute, AttributeLoc},
Expand Down
57 changes: 33 additions & 24 deletions crates/revm-jit/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ impl<'a> RawBytecodeIter<'a> {
}

impl<'a> Iterator for RawBytecodeIter<'a> {
type Item = BytecodeOpcode<'a>;
type Item = RawOpcode<'a>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().copied().map(|opcode| {
let immediate = imm_len(opcode).and_then(|len| {
let len = imm_len(opcode);
let immediate = if len > 0 {
let r = self.iter.as_slice().get(..len);
// TODO: Use `advance_by` when stable.
self.iter.by_ref().take(len).for_each(drop);
r
});
BytecodeOpcode { opcode, immediate }
} else {
None
};
RawOpcode { opcode, immediate }
})
}

Expand All @@ -76,20 +79,20 @@ impl std::iter::FusedIterator for RawBytecodeIter<'_> {}

/// An opcode and its immediate data. Returned by [`RawBytecodeIterator`].
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct BytecodeOpcode<'a> {
pub struct RawOpcode<'a> {
/// The opcode.
pub opcode: u8,
/// The immediate data, if any.
pub immediate: Option<&'a [u8]>,
}

impl fmt::Debug for BytecodeOpcode<'_> {
impl fmt::Debug for RawOpcode<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}

impl fmt::Display for BytecodeOpcode<'_> {
impl fmt::Display for RawOpcode<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match OPCODE_JUMPMAP[self.opcode as usize] {
Some(s) => f.write_str(s),
Expand All @@ -102,13 +105,22 @@ impl fmt::Display for BytecodeOpcode<'_> {
}
}

/// Returns the length of the immediate data for the given opcode, if any.
/// Returns the length of the immediate data for the given opcode, or `0` if none.
#[inline]
pub const fn imm_len(op: u8) -> Option<usize> {
pub const fn imm_len(op: u8) -> usize {
match op {
op::PUSH1..=op::PUSH32 => Some((op - op::PUSH0) as usize),
// op::DUPN | op::SWAPN => Some(2),
_ => None,
op::PUSH1..=op::PUSH32 => (op - op::PUSH0) as usize,
// op::DATALOADN => 1,
//
// op::RJUMP => 2,
// op::RJUMPI => 2,
// op::RJUMPV => 2,
// op::CALLF => 2,
// op::JUMPF => 2,
// op::DUPN => 1,
// op::SWAPN => 1,
// op::EXCHANGE => 1,
_ => 0,
}
}

Expand All @@ -127,11 +139,11 @@ mod tests {
let bytecode = [0x01, 0x02, 0x03, 0x04, 0x05];
let mut iter = RawBytecodeIter::new(&bytecode);

assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x01, immediate: None }));
assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x02, immediate: None }));
assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x03, immediate: None }));
assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x04, immediate: None }));
assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x05, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x01, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x02, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x03, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x04, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x05, immediate: None }));
assert_eq!(iter.next(), None);
}

Expand All @@ -140,14 +152,11 @@ mod tests {
let bytecode = [op::PUSH0, op::PUSH1, 0x69, op::PUSH2, 0x01, 0x02];
let mut iter = RawBytecodeIter::new(&bytecode);

assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: op::PUSH0, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH0, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH1, immediate: Some(&[0x69]) }));
assert_eq!(
iter.next(),
Some(BytecodeOpcode { opcode: op::PUSH1, immediate: Some(&[0x69]) })
);
assert_eq!(
iter.next(),
Some(BytecodeOpcode { opcode: op::PUSH2, immediate: Some(&[0x01, 0x02]) })
Some(RawOpcode { opcode: op::PUSH2, immediate: Some(&[0x01, 0x02]) })
);
assert_eq!(iter.next(), None);
}
Expand All @@ -157,7 +166,7 @@ mod tests {
let bytecode = [op::PUSH2, 0x69];
let mut iter = RawBytecodeIter::new(&bytecode);

assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: op::PUSH2, immediate: None }));
assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH2, immediate: None }));
assert_eq!(iter.next(), None);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm-jit/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ impl<B: Builder> FunctionCx<B> {
}

fn translate_opcode(&mut self, opcode: u8, imm: Option<&[u8]>) -> Result<()> {
self.bcx.nop();
/*
self.bcx.nop();
if self.clif_comments.enabled() {
let inst = self.last_inst();
let mut comment = String::with_capacity(16);
Expand Down
3 changes: 2 additions & 1 deletion crates/revm-jit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(test), warn(unused_extern_crates))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use revm_primitives::U256;

Expand All @@ -24,7 +25,7 @@ mod compiler;
pub use compiler::JitEvm;

mod bytecode;
pub use bytecode::{format_bytecode, imm_len, BytecodeOpcode, RawBytecodeIter};
pub use bytecode::{format_bytecode, imm_len, RawBytecodeIter, RawOpcode};

#[allow(dead_code)]
const MINUS_1: U256 = U256::MAX;
Expand Down

0 comments on commit 5b7029f

Please sign in to comment.