This commit is contained in:
Able 2022-02-10 21:34:02 -06:00
commit e80a8927c5
5 changed files with 88 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
Cargo.lock

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "libwasm"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

7
src/lib.rs Normal file
View file

@ -0,0 +1,7 @@
#[macro_use]
pub mod logger;
pub mod syscalls;
pub use core::*;
use logger::LogLevel;

67
src/logger/mod.rs Normal file
View file

@ -0,0 +1,67 @@
#![allow(unused_macros)]
#[repr(C)]
pub enum LogLevel {
Error,
Warn,
Info,
Debug,
Trace,
}
extern "C" {
pub fn host_log(log_level: LogLevel, log_message: *const u8, log_message_len: u32);
}
macro_rules! log {
($a:expr, $b:expr) => {{
let log_level: LogLevel = $a;
let log_message: &[u8] = $b;
let pointer = log_message.as_ptr();
unsafe {
$crate::logger::host_log(log_level, pointer, log_message.len() as u32);
}
}};
}
macro_rules! debug {
($a:expr) => {
use crate::logger::{LogLevel::*, *};
log!(Debug, $a);
};
}
macro_rules! error {
($a:expr) => {
use crate::logger::{LogLevel::*, *};
log!(Error, $a);
};
}
macro_rules! trace {
($a:expr) => {
use crate::logger::*;
log!(Trace, $a);
};
}
macro_rules! warn {
($a:expr) => {
use crate::logger::{LogLevel::*, *};
log!(Warn, $a);
};
}
macro_rules! info {
($a:expr) => {
use crate::logger::{LogLevel::*, *};
log!(Info, $a);
};
}

4
src/syscalls.rs Normal file
View file

@ -0,0 +1,4 @@
/// All system calls are defined here.
extern "C" {
pub fn add(a: u32, b: u32) -> u32;
}