added -p -c -l -o options to uw8 run command

This commit is contained in:
2021-11-26 23:45:29 +01:00
parent fcf24110c5
commit 0cb169d62e
11 changed files with 321 additions and 17 deletions

93
uw8-tool/Cargo.lock generated
View File

@@ -30,12 +30,50 @@ dependencies = [
"sacabase",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "leb128"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "num-traits"
version = "0.2.14"
@@ -45,6 +83,18 @@ dependencies = [
"autocfg",
]
[[package]]
name = "pbr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff5751d87f7c00ae6403eb1fcbba229b9c76c9a30de8c1cf87182177b168cea2"
dependencies = [
"crossbeam-channel",
"libc",
"time",
"winapi",
]
[[package]]
name = "pico-args"
version = "0.4.2"
@@ -60,13 +110,25 @@ dependencies = [
"num-traits",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]]
name = "upkr"
version = "0.1.0"
source = "git+https://github.com/exoticorn/upkr.git?rev=11b43f9bc4460d960a13829a8a64ff4af11d1665#11b43f9bc4460d960a13829a8a64ff4af11d1665"
source = "git+https://github.com/exoticorn/upkr.git?rev=7d280bd#7d280bd533b037d579b6cdf12fb69046eb5c2c91"
dependencies = [
"anyhow",
"cdivsufsort",
"pbr",
"pico-args",
]
@@ -75,12 +137,19 @@ name = "uw8-tool"
version = "0.1.0"
dependencies = [
"anyhow",
"pbr",
"pico-args",
"upkr",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasm-encoder"
version = "0.8.0"
@@ -95,3 +164,25 @@ name = "wasmparser"
version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -10,4 +10,5 @@ wasmparser = "0.81"
wasm-encoder = "0.8"
anyhow = "1"
pico-args = "0.4"
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "5e82c65" }
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "7d280bd" }
pbr = "1"

View File

@@ -195,7 +195,7 @@ impl BaseModule {
pub fn create_binary(path: &Path) -> Result<()> {
let base1 = BaseModule::for_format_version(1)?.to_wasm();
let data = upkr::pack(&base1);
let data = upkr::pack(&base1, 4, None);
File::create(path)?.write_all(&data)?;
Ok(())
}

View File

@@ -14,19 +14,24 @@ use wasmparser::{
};
pub struct PackConfig {
compression: bool,
compression: Option<u8>,
}
impl PackConfig {
pub fn with_compression(mut self) -> Self {
self.compression = true;
self.compression = Some(2);
self
}
pub fn with_compression_level(mut self, level: u8) -> Self {
self.compression = Some(level);
self
}
}
impl Default for PackConfig {
fn default() -> PackConfig {
PackConfig { compression: false }
PackConfig { compression: None }
}
}
@@ -46,9 +51,21 @@ pub fn pack(data: &[u8], config: PackConfig) -> Result<Vec<u8>> {
let parsed_module = ParsedModule::parse(data)?;
let result = parsed_module.pack(&base)?;
if config.compression {
if let Some(level) = config.compression {
let mut uw8 = vec![2];
uw8.extend_from_slice(&upkr::pack(&result[8..]));
let content = &result[8..];
let mut pb = pbr::ProgressBar::new(content.len() as u64);
pb.set_units(pbr::Units::Bytes);
uw8.extend_from_slice(&upkr::pack(
&result[8..],
level,
Some(&mut |pos| {
pb.set(pos as u64);
}),
));
pb.finish();
Ok(uw8)
} else {
let mut uw8 = vec![1];