1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{Function, Result};
use ristretto_classfile::{ClassFile, Method};
/// Java Virtual Machine (JVM) bytecode to wasm code compiler.
///
/// This is a no-op compiler that does not actually compile any code.
#[derive(Clone, Debug)]
pub struct Compiler {}
impl Compiler {
/// Creates a new instance of the compiler for the host machine.
///
/// # Errors
///
/// This function currently never returns an error, but the signature is kept consistent
/// with the non-wasm compiler implementation.
pub fn new() -> Result<Self> {
Ok(Compiler {})
}
/// Returns whether the method can potentially be JIT compiled.
///
/// Always returns `false` on wasm since native JIT is not supported.
#[must_use]
pub fn can_compile(_method: &Method) -> bool {
false
}
/// Compiles the given bytecode into WASM code.
///
/// # Errors
///
/// Always returns an error as this is a no-op compiler.
pub fn compile(
&self,
_class_file: &ClassFile,
_method: &Method,
_symbols: &[(&str, *const u8)],
) -> Result<Function> {
Err(crate::Error::InternalError("Not implemented".to_string()))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compiler_new() {
let result = Compiler::new();
assert!(result.is_ok());
}
#[test]
fn test_can_compile() {
let method = Method::default();
assert!(!Compiler::can_compile(&method));
}
}