Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Aug 8, 2024
1 parent d02e554 commit cfbc626
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ pub(super) struct FrameTableBuilder {

current_unreturned: Vec<FrameTableEntry>,
current_returned: Vec<FrameTableEntry>,

last_jump_eid: Vec<u32>,
}

impl FrameTableBuilder {
Expand All @@ -65,27 +63,19 @@ impl FrameTableBuilder {

current_unreturned: Vec::new(),
current_returned: Vec::new(),

last_jump_eid: Vec::new(),
}
}

pub(super) fn invoke_exported_function_pre_hook(&mut self) {
self.last_jump_eid.push(0);
}

pub(super) fn push(&mut self, frame_id: u32, callee_fid: u32, fid: u32, iid: u32) {
fn push(&mut self, frame_id: u32, next_frame_id: u32, callee_fid: u32, fid: u32, iid: u32) {
self.current_unreturned.push(FrameTableEntry {
frame_id,
next_frame_id: *self.last_jump_eid.last().unwrap(),
next_frame_id,
callee_fid,
fid,
iid,
inherited: false,
returned: false,
});

self.last_jump_eid.push(frame_id);
}

pub(super) fn push_static_entry(&mut self, callee_fid: u32, fid: u32, iid: u32) {
Expand All @@ -103,8 +93,14 @@ impl FrameTableBuilder {
self.initial_frame_entries.push(entry);
}

fn pop(&mut self) {
let mut entry = self.current_unreturned.pop().unwrap();
entry.returned = true;
self.current_returned.push(entry);
}

// Prepare for the next slice. This will remove all the entries that are returned
pub(super) fn flush(&mut self) -> specs::jtable::FrameTable {
fn flush(&mut self) -> specs::jtable::FrameTable {
let frame_table = {
let inherited = self
.current_returned
Expand All @@ -126,13 +122,6 @@ impl FrameTableBuilder {
inherited: Arc::new(inherited.into()),
called: CalledFrameTable::new(called),
}

// match self.backend.as_ref() {
// TraceBackend::Memory => TableBackend::Memory(frame_table),
// TraceBackend::File {
// frame_table_writer, ..
// } => TableBackend::Json(frame_table_writer(self.slices.len(), &frame_table)),
// }
};

self.current_returned.clear();
Expand All @@ -143,13 +132,6 @@ impl FrameTableBuilder {
frame_table
}

pub(super) fn pop(&mut self) {
let mut entry = self.current_unreturned.pop().unwrap();
entry.returned = true;
self.current_returned.push(entry);
self.last_jump_eid.pop();
}

pub(super) fn build_initial_frame_table(&self) -> InheritedFrameTable {
self.initial_frame_entries
.iter()
Expand All @@ -171,10 +153,20 @@ impl FrameTableBuilder {
pub(super) fn build(&mut self, entries: &[EventTableEntry]) -> specs::jtable::FrameTable {
for entry in entries {
match entry.step_info {
StepInfo::Call { index } => self.push(entry.eid, index, entry.fid, entry.iid + 1),
StepInfo::CallIndirect { func_index, .. } => {
self.push(entry.eid, func_index, entry.fid, entry.iid + 1)
}
StepInfo::Call { index } => self.push(
entry.eid,
entry.last_jump_eid,
index,
entry.fid,
entry.iid + 1,
),
StepInfo::CallIndirect { func_index, .. } => self.push(
entry.eid,
entry.last_jump_eid,
func_index,
entry.fid,
entry.iid + 1,
),
StepInfo::Return { .. } => {
self.pop();
}
Expand Down
40 changes: 4 additions & 36 deletions crates/zkwasm/src/runtime/monitor/plugins/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl TablePlugin {
let br_table = Arc::new(itable.create_brtable());
let elem_table = Arc::new(ElemTable::new(self.elements.clone()));
let configure_table = Arc::new(self.configure_table);

let initialization_state = Arc::new(InitializationState {
eid: 1,
fid: self.start_fid.unwrap(),
Expand Down Expand Up @@ -235,34 +236,11 @@ impl TablePlugin {
self.host_transaction.insert(event);
}

fn push_frame(
&mut self,
frame_id: u32,
// next_frame_id: u32,
// callee_fid: u32,
// fid: u32,
// iid: u32,
) {
// self.frame_table
// .push(frame_id, next_frame_id, callee_fid, fid, iid);

fn push_frame(&mut self, frame_id: u32) {
self.last_jump_eid.push(frame_id);
}

// fn push_static_frame(
// &mut self,
// frame_id: u32,
// next_frame_id: u32,
// callee_fid: u32,
// fid: u32,
// iid: u32,
// ) {
// self.frame_table
// .push_static_entry(frame_id, next_frame_id, callee_fid, fid, iid);
// }

fn pop_frame(&mut self) {
//self.frame_table.pop();
self.last_jump_eid.pop();
}

Expand Down Expand Up @@ -599,10 +577,6 @@ impl Monitor for TablePlugin {

fn invoke_exported_function_pre_hook(&mut self) {
self.last_jump_eid.push(0);
self.host_transaction
.slice_builder
.frame_table_builder
.invoke_exported_function_pre_hook();
}

fn invoke_instruction_pre_hook(
Expand Down Expand Up @@ -646,7 +620,7 @@ impl Monitor for TablePlugin {
|| matches!(step_info, StepInfo::ExternalHostCall { .. })
{
self.unresolved_host_call = Some(EventTableEntry {
eid: self.eid,
eid: self.eid + 1,
fid,
iid,
sp,
Expand All @@ -670,13 +644,7 @@ impl Monitor for TablePlugin {
InstructionOutcome::ExecuteCall(func_ref) => {
if let FuncInstanceInternal::Internal { index, .. } = func_ref.as_internal() {
if !self.phantom_helper.is_in_phantom_function() {
self.push_frame(
self.eid,
// *self.last_jump_eid.last().unwrap(),
// *index as u32,
// fid,
// iid + 1,
);
self.push_frame(self.eid);
}

if self.phantom_helper.is_phantom_function(*index as u32) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub(super) struct SliceBuilder {
}

impl SliceBuilder {
pub fn new() -> Self {
pub(super) fn new() -> Self {
SliceBuilder {
frame_table_builder: FrameTableBuilder::new(),
}
}

pub fn build(&mut self, logs: Vec<EventTableEntry>) -> Slice {
pub(super) fn build(&mut self, logs: Vec<EventTableEntry>) -> Slice {
let external_host_call_table = ExternalHostCallTable::new(
logs.iter()
.filter_map(|entry| ExternalHostCallEntry::try_from(&entry.step_info).ok())
Expand Down

0 comments on commit cfbc626

Please sign in to comment.