Skip to content

Commit

Permalink
Merge pull request #177 from 0xPolygonMiden/greenhat/abi-transform-tests
Browse files Browse the repository at this point in the history
[1/2] stdlib blake3 call MASM compilation test
  • Loading branch information
bitwalker authored May 24, 2024
2 parents 8d0d9e3 + 95f268a commit 6acf836
Show file tree
Hide file tree
Showing 13 changed files with 790 additions and 25 deletions.
8 changes: 7 additions & 1 deletion codegen/masm/src/codegen/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ impl<'b, 'f: 'b> BlockEmitter<'b, 'f> {
.function
.globals
.get_computed_addr(&self.function.f.id, op.global)
.expect("expected linker to identify all undefined symbols");
.unwrap_or_else(|| {
panic!(
"expected linker to identify all undefined symbols, but failed on func id: \
{}, gv: {}",
self.function.f.id, op.global
)
});
match self.function.f.dfg.global_value(op.global) {
hir::GlobalValueData::Load { ref ty, .. } => {
let mut emitter = self.inst_emitter(inst_info.inst);
Expand Down
2 changes: 1 addition & 1 deletion frontend-wasm/src/miden_abi/stdlib/crypto/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ pub(crate) fn signatures() -> ModuleFunctionTypeMap {
[Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt],
),
);
m.insert("miden:prelude/std_crypto_hashes", crypto);
m.insert("std::crypto_hashes", crypto);
m
}
15 changes: 10 additions & 5 deletions hir/src/asm/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ impl ModuleImportInfo {
let module_id = id.module;
match self.modules.entry(module_id) {
Entry::Vacant(entry) => {
let alias = match module_id.as_str().rsplit_once("::") {
None => module_id.as_symbol(),
Some((_, alias)) => Symbol::intern(alias),
};
let alias = module_id_alias(module_id);
let span = module_id.span();
let alias_id = if self.aliases.contains_key(&alias) {
// The alias is already used by another module, we must
Expand Down Expand Up @@ -69,7 +66,8 @@ impl ModuleImportInfo {
self.functions.entry(alias_id).or_default().insert(id);
}
Entry::Occupied(_) => {
let alias = self.aliases[&module_id];
let module_id_alias = module_id_alias(module_id);
let alias = self.aliases[&module_id_alias];
let functions = self.functions.entry(alias).or_default();
functions.insert(id);
}
Expand Down Expand Up @@ -137,6 +135,13 @@ impl ModuleImportInfo {
}
}

fn module_id_alias(module_id: Ident) -> Symbol {
match module_id.as_str().rsplit_once("::") {
None => module_id.as_symbol(),
Some((_, alias)) => Symbol::intern(alias),
}
}

/// This represents an import statement in Miden Assembly
#[derive(Debug, Copy, Clone, Spanned)]
pub struct MasmImport {
Expand Down
3 changes: 2 additions & 1 deletion sdk/prelude/src/stdlib/crypto/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! value per element.
use crate::Felt;

#[link(wasm_import_module = "miden:prelude/std_crypto_hashes")]
// #[link(wasm_import_module = "miden:prelude/std_crypto_hashes")]
#[link(wasm_import_module = "std::crypto_hashes")]
extern "C" {
/// Computes BLAKE3 1-to-1 hash.
///
Expand Down
Loading

0 comments on commit 6acf836

Please sign in to comment.