Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercice: A basic CLI [Julien D] #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 233 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.1.2", features = ["derive"] }
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use clap::Parser;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// Instruction to parse
#[clap(short, long)]
instruction: String,
}

#[derive(Debug)]
struct Instruction {
opcode: OpCode,
Expand Down Expand Up @@ -60,7 +70,11 @@ fn main() {
// 0001 1000 0100 0010
// 1 8 4 2
// 0b0001100001000010 = 0x1842
let insn: u32 = 0x1842;
let args = Args::parse();
let raw_insn = args.instruction.trim_start_matches("0x");
let insn: u32 = u32::from_str_radix(&raw_insn, 16)
.ok()
.expect("Unable to parse this instruction");
let mut r1: u32 = 20;
let r3: u32 = 12;

Expand Down