Skip to content

Commit

Permalink
Add "Metadata" symbol to Symbol enum
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jan 4, 2023
1 parent 398c138 commit 5df8789
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions lib/compiler-llvm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +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::LocalFunction(index) => format!("f{}", index.index()),
Symbol::Section(index) => format!("s{}", index.index()),
Symbol::FunctionCallTrampoline(index) => format!("t{}", index.index()),
Expand All @@ -55,6 +56,10 @@ impl SymbolRegistry for ShortNames {
return None;
}
let (ty, idx) = name.split_at(1);
if ty.starts_with('M') {
return Some(Symbol::Metadata(idx.to_string()));
}

let idx = idx.parse::<u32>().ok()?;
match ty.chars().next().unwrap() {
'f' => Some(Symbol::LocalFunction(LocalFunctionIndex::from_u32(idx))),
Expand Down
25 changes: 12 additions & 13 deletions lib/types/src/compilation/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ use serde::{Deserialize, Serialize};

/// The kinds of wasmer_types objects that might be found in a native object file.
#[derive(
RkyvSerialize,
RkyvDeserialize,
Archive,
Copy,
Clone,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Debug,
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),

/// A function defined in the wasm.
LocalFunction(LocalFunctionIndex),

Expand Down Expand Up @@ -154,6 +147,9 @@ impl ModuleMetadata {
impl SymbolRegistry for ModuleMetadataSymbolRegistry {
fn symbol_to_name(&self, symbol: Symbol) -> String {
match symbol {
Symbol::Metadata(prefix) => {
format!("WASMER_METADATA_{}", prefix)
}
Symbol::LocalFunction(index) => {
format!("wasmer_function_{}_{}", self.prefix, index.index())
}
Expand All @@ -176,7 +172,10 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry {
}

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

0 comments on commit 5df8789

Please sign in to comment.