make wiggle-generate ordinary lib, and wiggle the proc-macro lib
this allows us to reuse the code in wiggle-generate elsewhere, because a proc-macro=true lib can only export a #[proc_macro] and not ordinary functions. In lucet, I will depend on wiggle-generate to define a proc macro that glues wiggle to the specifics of the runtime.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
extern crate proc_macro;
|
||||
|
||||
mod config;
|
||||
mod funcs;
|
||||
mod lifetimes;
|
||||
@@ -7,20 +5,16 @@ mod module_trait;
|
||||
mod names;
|
||||
mod types;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
use config::Config;
|
||||
use funcs::define_func;
|
||||
use module_trait::define_module_trait;
|
||||
use names::Names;
|
||||
use types::define_datatype;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn from_witx(args: TokenStream) -> TokenStream {
|
||||
let config = parse_macro_input!(args as Config);
|
||||
pub use config::Config;
|
||||
pub use funcs::define_func;
|
||||
pub use module_trait::define_module_trait;
|
||||
pub use names::Names;
|
||||
pub use types::define_datatype;
|
||||
|
||||
pub fn generate(config: Config) -> TokenStream {
|
||||
let doc = witx::load(&config.witx.paths).expect("loading witx");
|
||||
|
||||
let names = Names::new(config); // TODO parse the names from the invocation of the macro, or from a file?
|
||||
@@ -43,10 +37,10 @@ pub fn from_witx(args: TokenStream) -> TokenStream {
|
||||
)
|
||||
});
|
||||
|
||||
TokenStream::from(quote!(
|
||||
quote!(
|
||||
mod types {
|
||||
#(#types)*
|
||||
}
|
||||
#(#modules)*
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user