Util for assembling EVM code to hex (#586)

This is just for debugging the kernel. It's fully disposable.
This commit is contained in:
Jacqueline Nabaglo 2022-06-27 18:08:03 -07:00 committed by GitHub
parent 34e73db42b
commit e3834a5335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -10,6 +10,7 @@ plonky2_util = { path = "../util" }
anyhow = "1.0.40"
env_logger = "0.9.0"
ethereum-types = "0.13.1"
hex = { version = "0.4.3", optional = true }
itertools = "0.10.3"
log = "0.4.14"
pest = "2.1.3"
@ -18,3 +19,10 @@ rayon = "1.5.1"
rand = "0.8.5"
rand_chacha = "0.3.1"
keccak-rust = { git = "https://github.com/npwardberkeley/keccak-rust" }
[features]
asmtools = ["hex"]
[[bin]]
name = "assemble"
required-features = ["asmtools"]

13
evm/src/bin/assemble.rs Normal file
View File

@ -0,0 +1,13 @@
use std::env;
use std::fs;
use hex::encode;
use plonky2_evm::cpu::kernel::assemble_to_bytes;
fn main() {
let mut args = env::args();
args.next();
let file_contents: Vec<_> = args.map(|path| fs::read_to_string(path).unwrap()).collect();
let assembled = assemble_to_bytes(&file_contents[..]);
println!("{}", encode(&assembled));
}

View File

@ -13,7 +13,7 @@ const BYTES_PER_OFFSET: u8 = 3;
#[derive(PartialEq, Eq, Debug)]
pub struct Kernel {
code: Vec<u8>,
pub code: Vec<u8>,
global_labels: HashMap<String, usize>,
}

View File

@ -3,3 +3,14 @@ mod assembler;
mod ast;
mod opcodes;
mod parser;
use assembler::assemble;
use parser::parse;
/// Assemble files, outputting bytes.
/// This is for debugging the kernel only.
pub fn assemble_to_bytes(files: &[String]) -> Vec<u8> {
let parsed_files: Vec<_> = files.iter().map(|f| parse(f)).collect();
let kernel = assemble(parsed_files);
kernel.code
}