Auto-generate the hostcalls module of wasi-common (#846)

* Auto-generate shims for old `wasi_unstable` module

This commit is effectively just doing what #707 already did, but
applying it to the `snapshot_0` module as well. The end result is the
same, where we cut down on all the boilerplate in `snapshot_0` and bring
it in line with the main `wasi_snapshot_preview1` implementation. The
goal here is to make it easier to change the two in tandem since they're
both doing the same thing.

* Migrate `wasi_common::hostcalls` to a macro

This commit migrates the `hostcalls` module to being auto-generated by a
macro rather than duplicating a handwritten signature for each wasi
syscall.

* Auto-generate snapshot_0's `hostcalls` module

Similar to the previous commit, but for `snapshot_0`

* Delete the `wasi-common-cbindgen` crate

This is no longer needed with the hostcalls macro now, we can easily
fold the definition of the cbindgen macro into the same crate.

* Rustfmt

* Fix windows build errors

* Rustfmt

* Remove now no-longer-necessary code

* rustfmt
This commit is contained in:
Alex Crichton
2020-01-22 14:54:39 -06:00
committed by GitHub
parent 5d7635c351
commit 5953215bac
44 changed files with 391 additions and 2742 deletions

View File

@@ -45,13 +45,7 @@ pub fn add_wrappers_to_module(args: TokenStream) -> TokenStream {
let mut hostcall_args = Vec::new();
for param in func.params.iter() {
let name = format_ident!(
"{}",
match param.name.as_str() {
"in" | "type" => format!("r#{}", param.name.as_str()),
s => s.to_string(),
}
);
let name = utils::param_name(param);
// Registers a new parameter to the shim we're making with the
// given `name`, the `abi_ty` wasm type and `hex` defines
@@ -89,6 +83,11 @@ pub fn add_wrappers_to_module(args: TokenStream) -> TokenStream {
};
match &*param.tref.type_() {
witx::Type::Int(e) => match e.repr {
witx::IntRepr::U64 => add_param(&name, Abi::I64, false),
_ => add_param(&name, Abi::I32, false),
},
witx::Type::Enum(e) => match e.repr {
witx::IntRepr::U64 => add_param(&name, Abi::I64, false),
_ => add_param(&name, Abi::I32, false),
@@ -99,12 +98,14 @@ pub fn add_wrappers_to_module(args: TokenStream) -> TokenStream {
_ => add_param(&name, Abi::I32, true),
},
witx::Type::Builtin(witx::BuiltinType::S8)
witx::Type::Builtin(witx::BuiltinType::Char8)
| witx::Type::Builtin(witx::BuiltinType::S8)
| witx::Type::Builtin(witx::BuiltinType::U8)
| witx::Type::Builtin(witx::BuiltinType::S16)
| witx::Type::Builtin(witx::BuiltinType::U16)
| witx::Type::Builtin(witx::BuiltinType::S32)
| witx::Type::Builtin(witx::BuiltinType::U32) => {
| witx::Type::Builtin(witx::BuiltinType::U32)
| witx::Type::Builtin(witx::BuiltinType::USize) => {
add_param(&name, Abi::I32, false);
}
@@ -208,7 +209,7 @@ pub fn add_wrappers_to_module(args: TokenStream) -> TokenStream {
Ok(e) => e,
Err(e) => #handle_early_error,
};
wasi_common::hostcalls::#name_ident(
hostcalls::#name_ident(
wasi_ctx,
memory,
#(#hostcall_args),*