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

add assembly parser #9

Merged
merged 6 commits into from Feb 7, 2017
Merged

add assembly parser #9

merged 6 commits into from Feb 7, 2017

Conversation

rlane
Copy link
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
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.

_ => 1,
});
let hex =
string("0x").with(many1(hex_digit())).map(|x: String| i64::from_str_radix(&x, 16).unwrap());
Copy link
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?

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
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

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
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

fn format_info(info: &Info<char, &str>) -> String {
match *info {
Info::Token(x) => format!("{:?}", x),
Info::Range(ref x) => format!("{:?}", x),
Copy link
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

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
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.)

src/lib.rs Outdated

pub mod disassembler;
pub mod ebpf;
pub mod helpers;
pub mod asm_parser;
Copy link
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
Contributor Author

rlane commented Feb 7, 2017

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

@qmonnet
Copy link
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.

None yet

2 participants