MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / generate

Function generate

crates/explorer/src/lib.rs:19–92  ·  view source on GitHub ↗
(
    config: &wasmtime::Config,
    target: Option<&str>,
    clif_dir: Option<&Path>,
    wasm: &[u8],
    dest: &mut dyn Write,
)

Source from the content-addressed store, hash-verified

17use wasmtime_environ::demangle_function_name;
18
19pub fn generate(
20 config: &wasmtime::Config,
21 target: Option<&str>,
22 clif_dir: Option<&Path>,
23 wasm: &[u8],
24 dest: &mut dyn Write,
25) -> Result<()> {
26 let target = match target {
27 None => target_lexicon::Triple::host(),
28 Some(target) => target_lexicon::Triple::from_str(target)?,
29 };
30
31 let wat = annotate_wat(wasm)?;
32 let wat_json = serde_json::to_string(&wat)?;
33 let asm = annotate_asm(config, &target, wasm)?;
34 let asm_json = serde_json::to_string(&asm)?;
35 let clif_json = clif_dir
36 .map::<wasmtime::Result<String>, _>(|clif_dir| {
37 let clif = annotate_clif(clif_dir, &asm)?;
38 Ok(serde_json::to_string(&clif)?)
39 })
40 .transpose()?;
41
42 let index_css = include_str!("./index.css");
43 let index_js = include_str!("./index.js");
44
45 write!(
46 dest,
47 r#"
48<!DOCTYPE html>
49<html>
50 <head>
51 <title>Wasmtime Compiler Explorer</title>
52 <style>
53 {index_css}
54 </style>
55 </head>
56 <body class="hbox">
57 <pre id="wat"></pre>
58 "#
59 )?;
60 if clif_json.is_some() {
61 write!(dest, r#"<div id="clif"></div>"#)?;
62 }
63 write!(
64 dest,
65 r#"
66 <div id="asm"></div>
67 <script>
68 window.WAT = {wat_json};
69 "#
70 )?;
71 if let Some(clif_json) = clif_json {
72 write!(
73 dest,
74 r#"
75 window.CLIF = {clif_json};
76 "#

Callers 9

executeMethod · 0.50
executeMethod · 0.50
newMethod · 0.50
generateMethod · 0.50
generate_optMethod · 0.50
generate_listMethod · 0.50
arbtestFunction · 0.50
intern_Method · 0.50
targetFunction · 0.50

Calls 6

annotate_watFunction · 0.85
annotate_asmFunction · 0.85
annotate_clifFunction · 0.85
OkFunction · 0.85
to_stringFunction · 0.50
is_someMethod · 0.45

Tested by 1

arbtestFunction · 0.40