generated from oovm/RustTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
legion encode
commands and legion decode
commands
- Loading branch information
Showing
5 changed files
with
93 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::ToolsError; | ||
use clap::{Args, Parser, Subcommand}; | ||
use std::path::PathBuf; | ||
mod run_decode; | ||
mod run_encode; | ||
|
||
pub use self::run_encode::RunEncode; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct LegionArguments { | ||
/// Optional name to operate on | ||
name: Option<String>, | ||
|
||
/// Sets a custom config file | ||
#[arg(short, long, value_name = "FILE")] | ||
config: Option<PathBuf>, | ||
|
||
/// Turn debugging information on | ||
#[arg(short, long, action = clap::ArgAction::Count)] | ||
debug: u8, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum LegionCommands { | ||
/// does testing things | ||
Encode(RunEncode), | ||
/// does testing things | ||
Decode(RunEncode), | ||
} | ||
|
||
impl LegionCommands { | ||
pub async fn run(self, arguments: &LegionArguments) -> Result<(), ToolsError> { | ||
match self { | ||
Self::Encode(cmd) => cmd.run(arguments).await, | ||
Self::Decode(cmd) => cmd.run(arguments).await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::{ToolsError, commands::LegionArguments}; | ||
use clap::Parser; | ||
use wasmprinter::PrintFmtWrite; | ||
use wat::GenerateDwarf; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct RunDecode { | ||
#[arg(short, long, value_name = "FILE")] | ||
skeleton_only: bool, | ||
#[arg(short, long, value_name = "FILE")] | ||
indent_text: String, | ||
#[arg(short, long, value_name = "FILE")] | ||
fold_instructions: bool, | ||
} | ||
|
||
impl RunDecode { | ||
pub async fn run(self, args: &LegionArguments) -> Result<(), ToolsError> { | ||
let input = []; | ||
let mut parser = wasmprinter::Config::new(); | ||
parser.name_unnamed(true); | ||
parser.print_offsets(false); | ||
parser.print_skeleton(self.skeleton_only); | ||
parser.indent_text(self.indent_text); | ||
parser.fold_instructions(self.fold_instructions); | ||
let mut dst = String::new(); | ||
parser.print(&input, &mut PrintFmtWrite(&mut dst))?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::{ToolsError, commands::LegionArguments}; | ||
use clap::Parser; | ||
use wat::GenerateDwarf; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct RunEncode { | ||
#[arg(short, long, value_name = "FILE")] | ||
generate_dwarf: bool, | ||
} | ||
|
||
impl RunEncode { | ||
pub async fn run(self, args: &LegionArguments) -> Result<(), ToolsError> { | ||
let input = ""; | ||
let mut parser = wat::Parser::new(); | ||
if self.generate_dwarf { | ||
parser.generate_dwarf(GenerateDwarf::Full); | ||
} | ||
let bytes = parser.parse_str(None, input)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters