feat: impl some conversion methods on CheckedModule
This commit is contained in:
parent
d55b7844f0
commit
cb0ae0c074
|
@ -728,12 +728,6 @@ where
|
||||||
input_path: path,
|
input_path: path,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut module_bytes = vec![];
|
|
||||||
|
|
||||||
ciborium::into_writer(&checked_module, &mut module_bytes).unwrap();
|
|
||||||
|
|
||||||
println!("{name}\n{}", hex::encode(&module_bytes));
|
|
||||||
|
|
||||||
self.checked_modules.insert(name, checked_module);
|
self.checked_modules.insert(name, checked_module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use aiken_lang::{
|
||||||
use petgraph::{algo, graph::NodeIndex, Direction, Graph};
|
use petgraph::{algo, graph::NodeIndex, Direction, Graph};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
|
io,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
@ -181,6 +182,26 @@ pub struct CheckedModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckedModule {
|
impl CheckedModule {
|
||||||
|
pub fn to_cbor(&self) -> Vec<u8> {
|
||||||
|
let mut module_bytes = vec![];
|
||||||
|
|
||||||
|
ciborium::into_writer(&self, &mut module_bytes)
|
||||||
|
.expect("modules should not fail to serialize");
|
||||||
|
|
||||||
|
module_bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_cbor(bytes: &[u8]) -> Result<Self, ciborium::de::Error<io::Error>> {
|
||||||
|
ciborium::from_reader(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_cbor_hex(&self) -> (String, Vec<u8>) {
|
||||||
|
let module_bytes = self.to_cbor();
|
||||||
|
let hex_str = hex::encode(&module_bytes);
|
||||||
|
|
||||||
|
(hex_str, module_bytes)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_node(&self, byte_index: usize) -> Option<Located<'_>> {
|
pub fn find_node(&self, byte_index: usize) -> Option<Located<'_>> {
|
||||||
self.ast.find_node(byte_index)
|
self.ast.find_node(byte_index)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue