-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(cargo-miden): support building Wasm component from a Cargo pr…
…oject
- Loading branch information
Showing
46 changed files
with
4,142 additions
and
1,141 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ use midenc_hir::{FunctionIdent, InstBuilder, SourceSpan, Type::*, Value}; | |
|
||
use crate::module::function_builder_ext::FunctionBuilderExt; | ||
|
||
pub(crate) const INTRINSICS_FELT_MODULE_NAME: &str = "miden:stdlib/intrinsics_felt"; | ||
pub(crate) const MODULE_ID: &str = "miden:core-import/[email protected]"; | ||
|
||
/// Convert a call to a felt op intrinsic function into instruction(s) | ||
pub(crate) fn convert_felt_intrinsics( | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ use midenc_hir::{AbiParam, FunctionIdent, InstBuilder, Signature, SourceSpan, Ty | |
|
||
use crate::module::function_builder_ext::FunctionBuilderExt; | ||
|
||
pub const MODULE_ID: &str = "miden:core-import/[email protected]"; | ||
|
||
/// Convert a call to a memory intrinsic function | ||
pub(crate) fn convert_mem_intrinsics( | ||
func_id: FunctionIdent, | ||
|
@@ -10,7 +12,7 @@ pub(crate) fn convert_mem_intrinsics( | |
span: SourceSpan, | ||
) -> Vec<Value> { | ||
match func_id.function.as_symbol().as_str() { | ||
"heap_base" => { | ||
"heap-base" => { | ||
assert_eq!(args.len(), 0, "{} takes no arguments", func_id); | ||
if builder | ||
.data_flow_graph() | ||
|
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 |
---|---|---|
|
@@ -3,28 +3,28 @@ use midenc_hir_type::Type::*; | |
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub(crate) const BLAKE3_HASH_1TO1: &str = "hash_1to1"; | ||
pub const MODULE_ID: &str = "miden:core-import/[email protected]"; | ||
|
||
pub(crate) const BLAKE3_HASH_1TO1: &str = "blake3-hash-one-to-one"; | ||
pub(crate) const BLAKE3_HASH_2TO1: &str = "hash_2to1"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut blake3: FunctionTypeMap = Default::default(); | ||
blake3.insert( | ||
BLAKE3_HASH_1TO1, | ||
//Accepts and returns a 8 Felt elements | ||
FunctionType::new( | ||
[I32, I32, I32, I32, I32, I32, I32, I32], | ||
[I32, I32, I32, I32, I32, I32, I32, I32], | ||
), | ||
); | ||
blake3.insert( | ||
BLAKE3_HASH_2TO1, | ||
// Accepts 16 and returns a 8 Felt elements | ||
FunctionType::new( | ||
[I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32], | ||
[I32, I32, I32, I32, I32, I32, I32, I32], | ||
), | ||
); | ||
m.insert("std::crypto::hashes::blake3", blake3); | ||
m.insert(MODULE_ID, blake3); | ||
m | ||
} |
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 |
---|---|---|
|
@@ -3,8 +3,10 @@ use midenc_hir_type::Type::*; | |
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub const ADD_ASSET: &str = "add_asset"; | ||
pub const REMOVE_ASSET: &str = "remove_asset"; | ||
pub const MODULE_ID: &str = "miden:core-import/[email protected]"; | ||
|
||
pub const ADD_ASSET: &str = "add-asset"; | ||
pub const REMOVE_ASSET: &str = "remove-asset"; | ||
pub const GET_ID: &str = "get_id"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
|
@@ -17,6 +19,6 @@ pub(crate) fn signatures() -> ModuleFunctionTypeMap { | |
FunctionType::new([Felt, Felt, Felt, Felt], [Felt, Felt, Felt, Felt]), | ||
); | ||
account.insert(GET_ID, FunctionType::new([], [Felt])); | ||
m.insert("miden::account", account); | ||
m.insert(MODULE_ID, account); | ||
m | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,9 @@ use midenc_hir_type::Type::*; | |
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub const CREATE_NOTE: &str = "create_note"; | ||
pub const MODULE_ID: &str = "miden:core-import/[email protected]"; | ||
|
||
pub const CREATE_NOTE: &str = "create-note"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
|
@@ -12,6 +14,6 @@ pub(crate) fn signatures() -> ModuleFunctionTypeMap { | |
CREATE_NOTE, | ||
FunctionType::new([Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], [Felt]), | ||
); | ||
m.insert("miden::tx", note); | ||
m.insert(MODULE_ID, note); | ||
m | ||
} |
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 |
---|---|---|
|
@@ -2,13 +2,13 @@ use miden_stdlib_sys::Felt; | |
|
||
use crate::bindings::tx::{AccountId, CoreAsset, NoteId, NoteType, Tag}; | ||
|
||
#[link(wasm_import_module = "miden::account")] | ||
#[link(wasm_import_module = "miden:core-import/account@1.0.0")] | ||
extern "C" { | ||
#[link_name = "get_id<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_account_get_id() -> AccountId; | ||
#[link_name = "add_asset<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
#[link_name = "add-asset"] | ||
pub fn extern_account_add_asset(_: Felt, _: Felt, _: Felt, _: Felt, ptr: *mut CoreAsset); | ||
#[link_name = "remove_asset<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
#[link_name = "remove-asset"] | ||
pub fn extern_account_remove_asset(_: Felt, _: Felt, _: Felt, _: Felt, ptr: *mut CoreAsset); | ||
} | ||
|
||
|
@@ -18,9 +18,9 @@ extern "C" { | |
pub fn extern_note_get_inputs(ptr: *mut Felt) -> usize; | ||
} | ||
|
||
#[link(wasm_import_module = "miden::tx")] | ||
#[link(wasm_import_module = "miden:core-import/[email protected]")] | ||
extern "C" { | ||
#[link_name = "create_note<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
#[link_name = "create-note"] | ||
pub fn extern_tx_create_note( | ||
asset_f0: Felt, | ||
asset_f1: Felt, | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; | ||
|
||
#[link(wasm_import_module = "miden:stdlib/intrinsics_felt")] | ||
#[link(wasm_import_module = "miden:core-import/[email protected]")] | ||
extern "C" { | ||
#[link_name = "from_u64_unchecked"] | ||
fn extern_from_u64_unchecked(value: u64) -> Felt; | ||
|
@@ -80,8 +80,10 @@ pub enum FeltError { | |
} | ||
|
||
#[repr(transparent)] | ||
#[derive(Copy, Clone)] | ||
pub struct Felt(f32); | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct Felt { | ||
pub inner: f32, | ||
} | ||
|
||
impl Felt { | ||
/// Field modulus = 2^64 - 2^32 + 1 | ||
|
@@ -141,26 +143,34 @@ impl From<Felt> for u64 { | |
|
||
impl From<u32> for Felt { | ||
fn from(value: u32) -> Self { | ||
Self(unsafe { core::mem::transmute::<u32, f32>(value) }) | ||
Self { | ||
inner: unsafe { core::mem::transmute::<u32, f32>(value) }, | ||
} | ||
} | ||
} | ||
|
||
impl From<u16> for Felt { | ||
fn from(value: u16) -> Self { | ||
Self(unsafe { core::mem::transmute::<u32, f32>(value as u32) }) | ||
Self { | ||
inner: unsafe { core::mem::transmute::<u32, f32>(value as u32) }, | ||
} | ||
} | ||
} | ||
|
||
impl From<u8> for Felt { | ||
fn from(value: u8) -> Self { | ||
Self(unsafe { core::mem::transmute::<u32, f32>(value as u32) }) | ||
Self { | ||
inner: unsafe { core::mem::transmute::<u32, f32>(value as u32) }, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_pointer_width = "32")] | ||
impl From<usize> for Felt { | ||
fn from(value: usize) -> Self { | ||
Self(unsafe { core::mem::transmute(value as u32) }) | ||
Self { | ||
inner: unsafe { core::mem::transmute(value as u32) }, | ||
} | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.