Public dry run dryrun-309831e1e021
Source commit: 309831e1e021f962c118452336776fd9a94025f9 Public tree identity: sha256:6fa95c1745579bd6256dbeb3d476db0b07c2f24aa9213b0f7783ce1adfc8aca5
This commit is contained in:
commit
f22d0a5791
113 changed files with 39348 additions and 0 deletions
14
crates/disasmer-macros/Cargo.toml
Normal file
14
crates/disasmer-macros/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "disasmer-macros"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
proc-macro2.workspace = true
|
||||
quote.workspace = true
|
||||
syn.workspace = true
|
||||
77
crates/disasmer-macros/src/lib.rs
Normal file
77
crates/disasmer-macros/src/lib.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
use proc_macro::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{parse::Parser, parse_macro_input, Expr, ItemFn, Lit, Meta, Token};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let function = parse_macro_input!(item as ItemFn);
|
||||
let function_name = function.sig.ident.to_string();
|
||||
let entrypoint_name = descriptor_name(
|
||||
attr,
|
||||
function_name
|
||||
.strip_suffix("_main")
|
||||
.unwrap_or(&function_name),
|
||||
);
|
||||
let descriptor = format_ident!(
|
||||
"__DISASMER_ENTRYPOINT_{}",
|
||||
function_name.to_ascii_uppercase()
|
||||
);
|
||||
|
||||
quote! {
|
||||
#function
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const #descriptor: ::disasmer::EntrypointDescriptor = ::disasmer::EntrypointDescriptor {
|
||||
name: #entrypoint_name,
|
||||
function: #function_name,
|
||||
};
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn task(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let function = parse_macro_input!(item as ItemFn);
|
||||
let function_name = function.sig.ident.to_string();
|
||||
let task_name = descriptor_name(attr, &function_name);
|
||||
let descriptor = format_ident!("__DISASMER_TASK_{}", function_name.to_ascii_uppercase());
|
||||
|
||||
quote! {
|
||||
#function
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const #descriptor: ::disasmer::TaskDescriptor = ::disasmer::TaskDescriptor {
|
||||
name: #task_name,
|
||||
function: #function_name,
|
||||
remotely_startable: true,
|
||||
};
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
fn descriptor_name(attr: TokenStream, default: &str) -> String {
|
||||
if attr.is_empty() {
|
||||
return default.to_owned();
|
||||
}
|
||||
|
||||
let parser = syn::punctuated::Punctuated::<Meta, Token![,]>::parse_terminated;
|
||||
let Ok(args) = parser.parse(attr) else {
|
||||
return default.to_owned();
|
||||
};
|
||||
|
||||
for meta in args {
|
||||
let Meta::NameValue(name_value) = meta else {
|
||||
continue;
|
||||
};
|
||||
if !name_value.path.is_ident("name") {
|
||||
continue;
|
||||
}
|
||||
if let Expr::Lit(expr) = name_value.value {
|
||||
if let Lit::Str(name) = expr.lit {
|
||||
return name.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default.to_owned()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue