-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): implement all log APIs (#125)
* refactor(zink): remove size in log API * refactor(codegen): wrap dataset with extra methods * feat(codegen): support log1 * refactor(codegen): introduce new log parser * feat(compiler): tests for log3 and log4
- Loading branch information
Showing
19 changed files
with
363 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Dataset in code generation | ||
use crate::{Error, Result}; | ||
use std::{ | ||
collections::BTreeMap, | ||
ops::{Deref, DerefMut}, | ||
}; | ||
|
||
/// Data section conversion | ||
/// | ||
/// NOTE: current only support constant expression. | ||
#[derive(Default, Clone, Debug)] | ||
pub struct DataSet(BTreeMap<i32, Vec<u8>>); | ||
|
||
impl DataSet { | ||
/// Load data from offset and size | ||
pub fn load(&self, offset: i32, size: usize) -> Result<Vec<u8>> { | ||
for ptr in self.0.keys().cloned().rev() { | ||
if offset >= ptr { | ||
let start = (offset - ptr) as usize; | ||
let data = self.get(&ptr).ok_or(Error::DataNotFound(offset, size))?; | ||
|
||
return Ok(data[start..start + size].to_vec()); | ||
} | ||
} | ||
|
||
Err(Error::DataNotFound(offset, size)) | ||
} | ||
} | ||
|
||
impl Deref for DataSet { | ||
type Target = BTreeMap<i32, Vec<u8>>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for DataSet { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
(module | ||
(type (;0;) (func (param i32 i32))) | ||
(type (;1;) (func)) | ||
(import "evm" "log0" (func (;0;) (type 0))) | ||
(type (;0;) (func)) | ||
(type (;1;) (func (param i32 i32))) | ||
(import "evm" "log0" (func (;0;) (type 1))) | ||
(import "env" "memory" (memory (;0;) 17)) | ||
(func (;1;) (type 1) | ||
(func (;2;) (type 0) | ||
i32.const 1048576 | ||
i32.const 4 | ||
call 0) | ||
(global (;0;) i32 (i32.const 1048580)) | ||
(global (;0;) i32 (i32.const 1048584)) | ||
(global (;1;) i32 (i32.const 1048592)) | ||
(export "log" (func 1)) | ||
(export "log0" (func 1)) | ||
(export "__data_end" (global 0)) | ||
(export "__heap_base" (global 1)) | ||
(data (;0;) (i32.const 1048576) "Ping")) |
Oops, something went wrong.