mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-05-10 06:27:57 +00:00
test for codesizes
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -18,3 +18,5 @@ era-compiler-llvm-context = { path = "../llvm-context" }
|
||||
|
||||
[dev-dependencies]
|
||||
sha1 = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"Baseline": 3551,
|
||||
"Computation": 5912,
|
||||
"Fibonacci": 4909
|
||||
}
|
||||
@@ -117,3 +117,52 @@ impl Contract {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde::{de::Deserialize, Serialize};
|
||||
use std::{collections::HashMap, fs::File};
|
||||
|
||||
use super::Contract;
|
||||
|
||||
#[test]
|
||||
fn codesize() {
|
||||
let path = "codesize.json";
|
||||
|
||||
let existing = File::open(path)
|
||||
.map(|file| {
|
||||
HashMap::<String, usize>::deserialize(&mut serde_json::Deserializer::from_reader(
|
||||
file,
|
||||
))
|
||||
.expect("should be able to deserialze codesize data")
|
||||
})
|
||||
.ok();
|
||||
|
||||
let sizes = HashMap::from([
|
||||
("Baseline", Contract::baseline().pvm_runtime.len()),
|
||||
("Computation", Contract::odd_product(0).pvm_runtime.len()),
|
||||
("Fibonacci", Contract::fib_iterative(0).pvm_runtime.len()),
|
||||
]);
|
||||
|
||||
for (name, bytes) in sizes.iter() {
|
||||
let change = existing
|
||||
.as_ref()
|
||||
.and_then(|map| map.get(*name))
|
||||
.map(|old| {
|
||||
let new = *bytes as f32;
|
||||
let old = *old as f32;
|
||||
let p = (new - old) / new * 100.0;
|
||||
format!("({p}% change from {old} bytes)")
|
||||
})
|
||||
.unwrap_or_else(String::new);
|
||||
|
||||
println!("{name}: {bytes} bytes {change}");
|
||||
}
|
||||
|
||||
sizes
|
||||
.serialize(&mut serde_json::Serializer::pretty(
|
||||
File::create(path).unwrap(),
|
||||
))
|
||||
.unwrap_or_else(|err| panic!("can not write codesize data to '{}': {}", path, err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ description = "Shared front end code of the EraVM compilers"
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[features]
|
||||
riscv-zbb = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
semver = { workspace = true }
|
||||
|
||||
@@ -29,6 +29,12 @@ impl TargetMachine {
|
||||
/// The LLVM target triple.
|
||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf";
|
||||
|
||||
/// LLVM target features.
|
||||
#[cfg(feature = "riscv-zbb")]
|
||||
pub const VM_FEATURES: &'static str = "+zbb,+e,+m";
|
||||
#[cfg(not(feature = "riscv-zbb"))]
|
||||
pub const VM_FEATURES: &'static str = "+e,+m";
|
||||
|
||||
///
|
||||
/// A shortcut constructor.
|
||||
///
|
||||
@@ -40,7 +46,7 @@ impl TargetMachine {
|
||||
.create_target_machine(
|
||||
&inkwell::targets::TargetTriple::create(target.triple()),
|
||||
"generic-rv32",
|
||||
"+e,+m",
|
||||
Self::VM_FEATURES,
|
||||
optimizer_settings.level_back_end,
|
||||
inkwell::targets::RelocMode::PIC,
|
||||
inkwell::targets::CodeModel::Default,
|
||||
|
||||
Reference in New Issue
Block a user