Skip to content

add assembly parser#9

Merged
qmonnet merged 6 commits intoqmonnet:masterfrom
rlane:asm2
Feb 7, 2017
Merged

add assembly parser#9
qmonnet merged 6 commits intoqmonnet:masterfrom
rlane:asm2

Conversation

@rlane
Copy link
Copy Markdown
Contributor

@rlane rlane commented Feb 6, 2017

Uses the combine crate to parse ubpf-style assembly to Instruction
structs. A future assembler module will consume these, check that
the instruction and operands are valid, and output ebpf::Insn.

Uses the combine crate to parse ubpf-style assembly to Instruction
structs. A future assembler module will consume these, check that
the instruction and operands are valid, and output ebpf::Insn.
@qmonnet qmonnet mentioned this pull request Feb 6, 2017
Copy link
Copy Markdown
Owner

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlane, many thanks for this first PR! The parser looks very clean. The minor comments I added below were returned by rust-clippy (Rust linter), would you mind fixing them before we merge? Or I can add a commit once it's merged if you prefer me to do it.

Comment thread src/asm_parser.rs Outdated
_ => 1,
});
let hex =
string("0x").with(many1(hex_digit())).map(|x: String| i64::from_str_radix(&x, 16).unwrap());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single line in file that is more than 100 character long, do you think we could split it?

Comment thread src/asm_parser.rs Outdated
fn operand<I>(input: I) -> ParseResult<Operand, I>
where I: Stream<Item = char>
{
let register_operand = parser(register).map(|x: i64| Operand::Register(x));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cargo clippy -- -A doc_markdown -A match_same_arms
[...]
warning: redundant closure found, #[warn(redundant_closure)] on by default
  --> src/asm_parser.rs:66:49
   |
66 |     let register_operand = parser(register).map(|x: i64| Operand::Register(x));
   |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: remove closure as shown:
   |     let register_operand = parser(register).map(Operand::Register);
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#redundant_closure

Comment thread src/asm_parser.rs Outdated
where I: Stream<Item = char>
{
let register_operand = parser(register).map(|x: i64| Operand::Register(x));
let immediate = parser(integer).map(|x: i64| Operand::Integer(x));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cargo clippy -- -A doc_markdown -A match_same_arms
[...]
warning: redundant closure found, #[warn(redundant_closure)] on by default
  --> src/asm_parser.rs:67:41
   |
67 |     let immediate = parser(integer).map(|x: i64| Operand::Integer(x));
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: remove closure as shown:
   |     let immediate = parser(integer).map(Operand::Integer);
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#redundant_closure

Comment thread src/asm_parser.rs Outdated
fn format_info(info: &Info<char, &str>) -> String {
match *info {
Info::Token(x) => format!("{:?}", x),
Info::Range(ref x) => format!("{:?}", x),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cargo clippy -- -A doc_markdown -A match_same_arms
[...]
warning: this pattern creates a reference to a reference, #[warn(needless_borrow)] on by default
  --> src/asm_parser.rs:92:21
   |
92 |         Info::Range(ref x) => format!("{:?}", x),
   |                     ^^^^^
   |
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrow

Comment thread src/asm_parser.rs Outdated
Info::Token(x) => format!("{:?}", x),
Info::Range(ref x) => format!("{:?}", x),
Info::Owned(ref x) => x.clone(),
Info::Borrowed(ref x) => x.to_string(),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cargo clippy -- -A doc_markdown -A match_same_arms
[...]
warning: this pattern creates a reference to a reference, #[warn(needless_borrow)] on by default
  --> src/asm_parser.rs:94:24
   |
94 |         Info::Borrowed(ref x) => x.to_string(),
   |                        ^^^^^
   |
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrow

(Note we do need to keep the ref on line 93, though.)

Comment thread src/lib.rs Outdated
pub mod disassembler;
pub mod ebpf;
pub mod helpers;
pub mod asm_parser;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah also, can we keep includes in alphabetical order (in each one of the crate/public module/private module section)? Also, for dependencies in the Cargo.toml file?

@rlane
Copy link
Copy Markdown
Contributor Author

rlane commented Feb 7, 2017

Thanks for the pointer to rust-clippy. Pushed a few commits.

@qmonnet
Copy link
Copy Markdown
Owner

qmonnet commented Feb 7, 2017

Thanks a lot! Merging.

@qmonnet qmonnet merged commit b6ee3d6 into qmonnet:master Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants