Skip to content

Commit

Permalink
Remove prefix from Symbol::Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jan 4, 2023
1 parent 5df8789 commit b963d2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/compiler-llvm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ShortNames {}
impl SymbolRegistry for ShortNames {
fn symbol_to_name(&self, symbol: Symbol) -> String {
match symbol {
Symbol::Metadata(prefix) => format!("M{}", prefix),
Symbol::Metadata => "M".to_string(),
Symbol::LocalFunction(index) => format!("f{}", index.index()),
Symbol::Section(index) => format!("s{}", index.index()),
Symbol::FunctionCallTrampoline(index) => format!("t{}", index.index()),
Expand All @@ -57,7 +57,7 @@ impl SymbolRegistry for ShortNames {
}
let (ty, idx) = name.split_at(1);
if ty.starts_with('M') {
return Some(Symbol::Metadata(idx.to_string()));
return Some(Symbol::Metadata);
}

let idx = idx.parse::<u32>().ok()?;
Expand Down
11 changes: 6 additions & 5 deletions lib/types/src/compilation/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use serde::{Deserialize, Serialize};
RkyvSerialize, RkyvDeserialize, Archive, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug,
)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[archive(as = "Self")]
pub enum Symbol {
/// A metadata section, indexed by a unique prefix
/// (usually the wasm file SHA256 hash)
Metadata(String),
Metadata,

/// A function defined in the wasm.
LocalFunction(LocalFunctionIndex),
Expand Down Expand Up @@ -147,8 +148,8 @@ impl ModuleMetadata {
impl SymbolRegistry for ModuleMetadataSymbolRegistry {
fn symbol_to_name(&self, symbol: Symbol) -> String {
match symbol {
Symbol::Metadata(prefix) => {
format!("WASMER_METADATA_{}", prefix)
Symbol::Metadata => {
format!("WASMER_METADATA_{}", self.prefix)
}
Symbol::LocalFunction(index) => {
format!("wasmer_function_{}_{}", self.prefix, index.index())
Expand All @@ -172,8 +173,8 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry {
}

fn name_to_symbol(&self, name: &str) -> Option<Symbol> {
if let Some(prefix) = name.strip_prefix("WASMER_METADATA_") {
Some(Symbol::Metadata(prefix.to_string()))
if name == format!("WASMER_METADATA_{}", self.prefix) {
Some(Symbol::Metadata)
} else if let Some(index) = name.strip_prefix(&format!("wasmer_function_{}_", self.prefix))
{
index
Expand Down

0 comments on commit b963d2c

Please sign in to comment.