2022-06-20 20:32:29 -07:00
|
|
|
use ethereum_types::U256;
|
|
|
|
|
|
2022-07-23 11:16:45 +02:00
|
|
|
use crate::cpu::kernel::prover_input::ProverInputFn;
|
|
|
|
|
|
2022-06-20 20:32:29 -07:00
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub(crate) struct File {
|
|
|
|
|
pub(crate) body: Vec<Item>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-31 13:13:39 -07:00
|
|
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
2022-06-20 20:32:29 -07:00
|
|
|
pub(crate) enum Item {
|
2022-07-07 08:59:53 -07:00
|
|
|
/// Defines a new macro: name, params, body.
|
|
|
|
|
MacroDef(String, Vec<String>, Vec<Item>),
|
|
|
|
|
/// Calls a macro: name, args.
|
|
|
|
|
MacroCall(String, Vec<PushTarget>),
|
2022-07-14 14:55:17 -07:00
|
|
|
/// Repetition, like `%rep` in NASM.
|
2022-07-31 11:58:41 -07:00
|
|
|
Repeat(U256, Vec<Item>),
|
2022-07-19 15:28:34 -07:00
|
|
|
/// A directive to manipulate the stack according to a specified pattern.
|
|
|
|
|
/// The first list gives names to items on the top of the stack.
|
|
|
|
|
/// The second list specifies replacement items.
|
|
|
|
|
/// Example: `(a, b, c) -> (c, 5, 0x20, @SOME_CONST, a)`.
|
2022-09-09 12:05:58 -07:00
|
|
|
StackManipulation(Vec<StackPlaceholder>, Vec<StackReplacement>),
|
2022-06-20 20:32:29 -07:00
|
|
|
/// Declares a global label.
|
|
|
|
|
GlobalLabelDeclaration(String),
|
|
|
|
|
/// Declares a label that is local to the current file.
|
|
|
|
|
LocalLabelDeclaration(String),
|
2022-08-04 12:23:48 -07:00
|
|
|
/// Declares a label that is local to the macro it's declared in.
|
|
|
|
|
MacroLabelDeclaration(String),
|
2022-06-20 20:32:29 -07:00
|
|
|
/// A `PUSH` operation.
|
|
|
|
|
Push(PushTarget),
|
2022-07-23 11:16:45 +02:00
|
|
|
/// A `ProverInput` operation.
|
|
|
|
|
ProverInput(ProverInputFn),
|
2022-06-20 20:32:29 -07:00
|
|
|
/// Any opcode besides a PUSH opcode.
|
|
|
|
|
StandardOp(String),
|
|
|
|
|
/// Literal hex data; should contain an even number of hex chars.
|
2022-07-31 11:58:41 -07:00
|
|
|
Bytes(Vec<u8>),
|
2022-06-20 20:32:29 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 12:05:58 -07:00
|
|
|
/// The left hand side of a %stack stack-manipulation macro.
|
|
|
|
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
|
|
|
|
pub(crate) enum StackPlaceholder {
|
|
|
|
|
Identifier(String),
|
|
|
|
|
Block(String, usize),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The right hand side of a %stack stack-manipulation macro.
|
2022-07-31 13:13:39 -07:00
|
|
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
2022-07-19 15:28:34 -07:00
|
|
|
pub(crate) enum StackReplacement {
|
2022-09-21 08:42:56 -07:00
|
|
|
Literal(U256),
|
2022-07-30 21:51:55 -07:00
|
|
|
/// Can be either a named item or a label.
|
|
|
|
|
Identifier(String),
|
2022-09-21 08:42:56 -07:00
|
|
|
Label(String),
|
2022-08-04 12:23:48 -07:00
|
|
|
MacroLabel(String),
|
2022-07-19 15:28:34 -07:00
|
|
|
MacroVar(String),
|
|
|
|
|
Constant(String),
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 08:42:56 -07:00
|
|
|
impl From<PushTarget> for StackReplacement {
|
|
|
|
|
fn from(target: PushTarget) -> Self {
|
|
|
|
|
match target {
|
|
|
|
|
PushTarget::Literal(x) => Self::Literal(x),
|
|
|
|
|
PushTarget::Label(l) => Self::Label(l),
|
|
|
|
|
PushTarget::MacroLabel(l) => Self::MacroLabel(l),
|
|
|
|
|
PushTarget::MacroVar(v) => Self::MacroVar(v),
|
|
|
|
|
PushTarget::Constant(c) => Self::Constant(c),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 20:32:29 -07:00
|
|
|
/// The target of a `PUSH` operation.
|
2022-07-30 21:51:55 -07:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
2022-06-20 20:32:29 -07:00
|
|
|
pub(crate) enum PushTarget {
|
2022-07-31 11:58:41 -07:00
|
|
|
Literal(U256),
|
2022-06-20 20:32:29 -07:00
|
|
|
Label(String),
|
2022-08-04 12:23:48 -07:00
|
|
|
MacroLabel(String),
|
2022-07-07 08:59:53 -07:00
|
|
|
MacroVar(String),
|
2022-07-08 08:56:46 -07:00
|
|
|
Constant(String),
|
2022-06-20 20:32:29 -07:00
|
|
|
}
|