pepyakin / binaryen-rs

Binaryen bindings for Rust.
Apache License 2.0
74 stars 17 forks source link

Optimisation passes API #24

Closed axic closed 5 years ago

axic commented 5 years ago

From https://github.com/pepyakin/binaryen-rs/pull/22#discussion_r245003965.

Binaryen has optimisation passes which have a name and a description, both are strings. The list of names (keys) can be retrieved via std::vector<std::string> PassRegistry::getRegisteredNames() and the descriptions via std::string PassRegistry::getPassDescription(std::string name).

Would be nice if we could design a dynamic API exposing this to Rust.

Two alternatives: 1) hardcode them in Rust (such as a enum as suggested by @pepyakin, where though the description could still be dynamic) 2) generate Rust code at compile time

pepyakin commented 5 years ago

Can you expand on the pt.2 ?

axic commented 5 years ago

Could have a small C/C++ snippet which calls getRegisteredNames and generates a Rust file with for example an enum from the names received:

pub enum OptimisationPasses {
  Untee,
  Vacuum,
  // ...
}
pepyakin commented 5 years ago

That's really interesting approach.

axic commented 5 years ago

Or to be quick, we could do a regex on src/passes/pass.cpp:

registerPass\("([^"]+)", "([^"]+)", [^)]+\);
pepyakin commented 5 years ago

Hm that's tempting... But we need to make sure that we don't require any new dependencies (i.e. we don't want to require grep to be installed).