Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions crates/compiler/src/a_simplify_lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,10 +1132,7 @@ fn handle_const_arguments_helper(
for (arg_expr, (arg_var, is_constant)) in args.iter().zip(&func.arguments) {
if *is_constant {
let const_eval = arg_expr.naive_eval().unwrap_or_else(|| {
panic!(
"Failed to evaluate constant argument: {}",
arg_expr.to_string()
)
panic!("Failed to evaluate constant argument: {arg_expr}")
});
const_evals.push((arg_var.clone(), const_eval));
}
Expand Down Expand Up @@ -1332,11 +1329,7 @@ impl ToString for VarOrConstMallocAccess {
malloc_label,
offset,
} => {
format!(
"ConstMallocAccess({}, {})",
malloc_label,
offset.to_string()
)
format!("ConstMallocAccess({malloc_label}, {offset})")
}
}
}
Expand All @@ -1352,28 +1345,17 @@ impl SimpleLine {
arg0,
arg1,
} => {
format!(
"{} = {} {} {}",
var.to_string(),
arg0.to_string(),
operation.to_string(),
arg1.to_string()
)
format!("{} = {} {} {}", var.to_string(), arg0, operation, arg1)
}
Self::DecomposeBits {
var: result,
to_decompose,
label: _,
} => {
format!("{} = decompose_bits({})", result, to_decompose.to_string())
format!("{result} = decompose_bits({to_decompose})")
}
Self::RawAccess { res, index, shift } => {
format!(
"{} = memory[{} + {}]",
res.to_string(),
index,
shift.to_string()
)
format!("{res} = memory[{index} + {shift}]")
}
Self::IfNotZero {
condition,
Expand All @@ -1393,20 +1375,10 @@ impl SimpleLine {
.join("\n");

if else_branch.is_empty() {
format!(
"if {} != 0 {{\n{}\n{}}}",
condition.to_string(),
then_str,
spaces
)
format!("if {condition} != 0 {{\n{then_str}\n{spaces}}}")
} else {
format!(
"if {} != 0 {{\n{}\n{}}} else {{\n{}\n{}}}",
condition.to_string(),
then_str,
spaces,
else_str,
spaces
"if {condition} != 0 {{\n{then_str}\n{spaces}}} else {{\n{else_str}\n{spaces}}}"
)
}
}
Expand Down Expand Up @@ -1476,14 +1448,14 @@ impl SimpleLine {
} else {
"malloc"
};
format!("{} = {}({})", var, alloc_type, size.to_string())
format!("{var} = {alloc_type}({size})")
}
Self::ConstMalloc {
var,
size,
label: _,
} => {
format!("{} = malloc({})", var, size.to_string())
format!("{var} = malloc({size})")
}
Self::Panic => "panic".to_string(),
};
Expand Down
43 changes: 19 additions & 24 deletions crates/compiler/src/intermediate_bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::{collections::BTreeMap, fmt};

use p3_field::{PrimeCharacteristicRing, PrimeField64};
use vm::{Label, Operation};
Expand Down Expand Up @@ -73,6 +73,18 @@ impl HighLevelOperation {
}
}

impl fmt::Display for HighLevelOperation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Add => write!(f, "+"),
Self::Mul => write!(f, "*"),
Self::Sub => write!(f, "-"),
Self::Div => write!(f, "/"),
Self::Exp => write!(f, "**"),
}
}
}

#[derive(Debug, Clone)]
pub(crate) enum IntermediateInstruction {
Computation {
Expand Down Expand Up @@ -191,7 +203,7 @@ impl ToString for IntermediateValue {
Self::Constant(value) => value.to_string(),
Self::Fp => "fp".to_string(),
Self::MemoryAfterFp { offset } => {
format!("m[fp + {}]", offset.to_string())
format!("m[fp + {offset}]")
}
}
}
Expand All @@ -200,7 +212,7 @@ impl ToString for IntermediateValue {
impl ToString for IntermediaryMemOrFpOrConstant {
fn to_string(&self) -> String {
match self {
Self::MemoryAfterFp { offset } => format!("m[fp + {}]", offset.to_string()),
Self::MemoryAfterFp { offset } => format!("m[fp + {offset}]"),
Self::Fp => "fp".to_string(),
Self::Constant(c) => c.to_string(),
}
Expand All @@ -214,12 +226,7 @@ impl ToString for IntermediateInstruction {
shift_0,
shift_1,
res,
} => format!(
"{} = m[m[fp + {}] + {}]",
res.to_string(),
shift_0.to_string(),
shift_1.to_string()
),
} => format!("{} = m[m[fp + {}] + {}]", res.to_string(), shift_0, shift_1),
Self::DotProduct {
arg0,
arg1,
Expand All @@ -230,7 +237,7 @@ impl ToString for IntermediateInstruction {
arg0.to_string(),
arg1.to_string(),
res.to_string(),
size.to_string()
size
),
Self::MultilinearEval {
coeffs,
Expand All @@ -242,7 +249,7 @@ impl ToString for IntermediateInstruction {
coeffs.to_string(),
point.to_string(),
res.to_string(),
n_vars.to_string()
n_vars
),
Self::DecomposeBits {
res_offset,
Expand Down Expand Up @@ -318,7 +325,7 @@ impl ToString for IntermediateInstruction {
vectorized,
} => format!(
"m[fp + {}] = {}({})",
offset.to_string(),
offset,
if *vectorized { "malloc_vec" } else { "malloc" },
size.to_string(),
),
Expand All @@ -335,18 +342,6 @@ impl ToString for IntermediateInstruction {
}
}

impl ToString for HighLevelOperation {
fn to_string(&self) -> String {
match self {
Self::Add => "+".to_string(),
Self::Mul => "*".to_string(),
Self::Sub => "-".to_string(),
Self::Div => "/".to_string(),
Self::Exp => "**".to_string(),
}
}
}

impl ToString for IntermediateBytecode {
fn to_string(&self) -> String {
let mut res = String::new();
Expand Down
Loading