Commit Graph

532 Commits

Author SHA1 Message Date
Lars T Hansen
208c4e6da6 Fix a disasm formatting error 2019-03-28 14:12:39 +01:00
Lars T Hansen
141ccb9e9d Add a --disasm option to clif-util wasm and compile (#713)
- Both the `wasm` and `compile` commands get this new subcommand, and it defaults to false.  This means that test runs with `wasm` can request disassembly (the main reason I am doing this) while test runs with `compile` now must request it, this changes current behavior.
- Switch to using context.compile_and_emit directly, and make the reloc and trap printers just accumulate output, not print it.  This allows us to factor the printing code into the disasm module.
2019-03-27 12:57:13 +01:00
Dan Gohman
9eba81a8d9 Update clippy settings and fix a few clippy warnings. 2019-01-07 14:48:02 -08:00
Dan Gohman
7f250e340c Simplify ModuleEnvironment.
Remove some unneeded functions, and remove the `GlobalInit` special case
for data and elem initializer offsets; implementations that want that
information can provide it for themselves.
2019-01-07 13:42:00 -08:00
Muhammad Mominul Huque
effe6c04e4 Update to Rust 2018 edition (#632)
* initial cargo fix run

* Upgrade cranelift-entity crate

* Upgrade bforest crate

* Upgrade the codegen crate

* Upgrade the faerie crate

* Upgrade the filetests crate

* Upgrade the codegen-meta crate

* Upgrade the frontend crate

* Upgrade the cranelift-module crate

* Upgrade the cranelift-native crate

* Upgrade the cranelift-preopt crate

* Upgrade the cranelift-reader crate

* Upgrade the cranelift-serde crate

* Upgrade the cranelift-simplejit crate

* Upgrade the cranelift or cranelift-umbrella crate

* Upgrade the cranelift-wasm crate

* Upgrade cranelift-tools crate

* Use new import style on remaining files

* run format-all.sh

* run test-all.sh, update Readme and travis ci configuration
fixed an AssertionError also

* Remove deprecated functions
2018-12-26 09:49:05 -08:00
Dan Gohman
5d7ece3d15 Fix clippy warning namespaces. 2018-12-06 20:50:38 -05:00
Dan Gohman
5adab629f2 Update to the rustfmt in rust 1.31, which is now stable. 2018-12-06 16:15:48 -05:00
Dan Gohman
f8754c2cf8 Fix warnings when the "wasm" feature is disabled. 2018-11-28 16:36:59 -08:00
Zach Reizner
f028c53479 Fix incorrect wasm subcommand 'about' text. 2018-11-27 12:05:46 +01:00
Dan Gohman
d4f8eb7453 Introduce a TargetFrontendConfig type. (#570)
* Introduce a `TargetFrontendConfig` type.

`TargetFrontendConfig` is information specific to the target which is
provided to frontends to allow them to produce Cranelift IR for the
target. Currently this includes the pointer size and the default calling
convention.

The default calling convention is now inferred from the target, rather
than being a setting. cranelift-native is now just a provider of target
information, rather than also being a provider of settings, which gives
it a clearer role.

And instead of having cranelift-frontend routines require the whole
`TargetIsa`, just require the `TargetFrontendConfig`, and add a way to
get the `TargetFrontendConfig` from a `Module`.

Fixes #529.
Fixes #555.
2018-11-02 13:51:42 -07:00
Dan Gohman
07c98f5330 Fix an unused import warning. 2018-10-24 11:12:24 -07:00
Dan Gohman
6a234893eb Remove use of deprecated APIs.
std::error::Error's description() function is [deprecated]; follow the
recommended advice and use to_string() instead.

[deprecated]: https://doc.rust-lang.org/std/error/trait.Error.html#method.description
2018-10-23 17:33:20 -07:00
Boris-Chengbiao Zhou
b288c6001a Fix all clippy warnings (#564)
* Fix all clippy warnings

* Revert usage of inclusive ranges

* Remove redundant function argument

* Revert use of unavailable pointer methods

* Introduce ContiguousCaseRange
2018-10-22 21:52:35 -07:00
Benjamin Bouvier
af0a239539 Revive the -T aka --time-passes argument to report run times on the CLI; 2018-10-15 16:19:10 -07:00
Dan Gohman
bf041e3ae2 Move return_at_end out of Settings and into the wasm FuncEnvironment. (#547)
* Move `return_at_end` out of Settings and into the wasm FuncEnvironment.

The `return_at_end` flag supports users that want to append a custom
epilogue to Cranelift-produced functions. It arranges for functions to
always return via a single return statement at the end, and users are
expected to remove this return to append their code.

This patch makes two changes:
 - First, introduce a `fallthrough_return` instruction and use that
   instead of adding a `return` at the end. That's simpler than having
   users remove the `return` themselves.

 - Second, move this setting out of the Settings and into the wasm
   FuncEnvironment. This flag isn't something the code generator uses,
   it's something that the wasm translator uses. The code generator
   needs to preserve the property, however we can give the
   `fallthrough_return` instruction properties to ensure this as needed,
   such as marking it non-cloneable.
2018-10-05 06:43:22 -07:00
Dan Gohman
bed073fac0 Fix copy+pastos in debug messages. 2018-10-04 10:43:14 -07:00
Tyler McMullen
79cea5e18b Implement jump tables (#453)
* Add 'jump_table_entry' and 'indirect_jump' instructions.

* Update CodeSink to keep track of code size. Pretty up clif-util's disassembly output.

* Only disassemble the machine portion of output. Pretty print the read-only data after it.

* Update switch frontend code to use new br_table instruction w/ default.
2018-10-03 10:04:21 -07:00
Bruce Mitchener
c8a65a721c clippy: Remove useless format call. 2018-09-24 09:40:32 -07:00
Bruce Mitchener
e07e159bda filetests: run_passes can take &str, not &String. 2018-09-24 09:40:32 -07:00
Dan Gohman
10edc1b6ab Format src/wasm.rs with newer rustfmt. 2018-09-21 21:29:14 -07:00
Dan Gohman
53a0c6c67f Update to the rustfmt in rust 1.29, which is now stable. 2018-09-13 12:59:25 -07:00
Nick Fitzgerald
ea85018ccf clif-util: fix clif-util pass subcommand arguments
Because of the way that the `pass` subcommand orders its arguments, the
positional "single-file" input cannot be optional with a default value, because
it is followed by required positional arguments. If it were optional, that would
result in argument ambiguity where `clap` cannot tell if the optional positional
argument is supplied, or if the given argument is the next required positional
argument.

Before this commit:

```
$ cargo run --bin clif-util -- pass ./filetests/dce/basic.clif dce
   Compiling cranelift-tools v0.21.0 (file:///Users/fitzgen/src/cranelift)
    Finished dev [unoptimized + debuginfo] target(s) in 4.38s
     Running `target/debug/clif-util pass ./filetests/dce/basic.clif dce`
thread 'main' panicked at 'Found positional argument which is not required with a lower index than a required positional argument: "single-file" index 1', /Users/fitzgen/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.32.0/src/app/parser.rs:612:21
note: Run with `RUST_BACKTRACE=1` for a backtrace.
```

After this commit:

```
$ cargo run --bin clif-util -- pass ./filetests/dce/basic.clif dce
   Compiling cranelift-filetests v0.21.0 (file:///Users/fitzgen/src/cranelift/lib/filetests)
   Compiling cranelift-tools v0.21.0 (file:///Users/fitzgen/src/cranelift)
    Finished dev [unoptimized + debuginfo] target(s) in 5.96s
     Running `target/debug/clif-util pass ./filetests/dce/basic.clif dce`
1 tests
```
2018-09-11 10:16:14 -07:00
Nick Fitzgerald
90756a8a01 clif-util: Default to reading input files from stdin
Fixes #495
2018-09-06 17:35:26 -07:00
Nick Fitzgerald
8fb681b86d clif-util wasm: don't panic when terminal colors are unsupported
This breaks inside of Emacs' `M-x shell` and `compilation-mode`.
2018-09-06 17:35:26 -07:00
Caroline Cullen
59b83912ba Adds pass command to clif-util. (#487)
* Adds pass command to clif-util.
2018-09-04 16:31:24 -07:00
Grégoire Geis
0e67255f52 Fix error not reported if at least one other error expected. (#485)
* fix error not reported if at least one other error expected.

* Fixed unused extern crate error if wasm feature is not enabled.

* No longer reporting deref cycles multiple times.

* Fix filetest type_check.clif.

* Switched comparison order for perf.

* Fixed isa/riscv/verify-encoding.clif filetest.
2018-08-28 10:33:46 -07:00
Caroline Cullen
0f93ef5cee Changing from docopt to clap for the clif-util #434 (#463)
* Changing from docopt to clap for the clif-util

* Updates to cargo file.

* Remove filecheck subcommand.
2018-08-22 11:25:55 -07:00
Dan Gohman
3d89a8645b Fix rustfmt errors. 2018-08-16 15:26:53 -07:00
Grégoire Geis
e2badb0ad6 Improvements to error reporting (#470)
* Fixed error reporting.

* Fixed compile time error when wasm feature is disabled.

* Fixed valid instructions not being printed in print_function_error.

* Fixed errors print_function_error not writing valid instructions after end.

* Made multiple checks non-fatal.

* verify_global_values is no longer fatal.

* Slightly better formatting of errors in pretty_verifier_error.
2018-08-16 11:34:52 -07:00
Grégoire Geis
dbc547091f Verifier now accepts multiple errors (fixes #387). (#452)
* Verifier now accepts multiple errors (fixes #387).
2018-08-14 10:55:10 -07:00
Dan Gohman
3b56b2f4fb Fix rustfmt errors. 2018-08-13 12:52:09 -07:00
Dan Gohman
cc4bf1c7fb Deny unstable_features in "std" builds. 2018-08-13 12:51:49 -07:00
Benjamin Bouvier
a044f58cea Fixes #404: Use log.rs and a file-per-thread logger instead of the dbg! macro; 2018-08-13 12:51:14 -07:00
Maddy
f5d46cabe7 Use types to distinguish between wasm function body indices and wasm function indices. 2018-08-09 19:52:21 -07:00
bjorn3
01729be8d7 Add comment support (#379)
* Add comment support

* Don't print empty comments

* Add nop instruction

* Add test and note

* Add FuncWriter trait

* Remove comment support

* Add write_preamble to FuncWriter

* Fix test

* Some changes
2018-08-01 11:21:05 -07:00
Benjamin Bouvier
03159a9200 Misc refactorings when looking at the wasm code; 2018-07-19 06:39:56 -07:00
Dan Gohman
f4dbd38a4c Rename Cretonne to Cranelift! 2018-07-13 09:15:16 -07:00
Benjamin Bouvier
26523fdf5c [clippy] Pass a few argument types by value, not by reference;
Since Location is basically just a usize, and wasmparser::Type is an
enum, and both are copiable, this passes them down by value instead of
by reference, as suggested by Clippy.
2018-07-10 06:11:30 -07:00
Benjamin Bouvier
1987d4dba9 Reject with a plain text error when no ISA is defined with the wasm command; (#391)
And restructure code a bit to make it easier to understand.
2018-07-06 12:04:00 -07:00
Grégoire Geis
e5014e0fff Made Capstone an optional dependency (fixes #382) (#383)
* Made Capstone an optional dependency (fixes #382).

* Introduced feature 'disas' for disassembly (related to #382).

* Made 'disas' a default feature in cretonne-tools.

* Fixed errors in src/compile.rs introduced by get_disassembler changes.

- Moves `use` statements before the function declaration.
- Returns an error if the disassembler cannot be found created.
2018-07-03 20:54:54 -07:00
Bruce Mitchener
5c5e66cebd Update to capstone 0.4. 2018-06-06 10:15:09 -07:00
Dan Gohman
4a4453dc47 Use to_string() instead of format!("{}", ...). 2018-06-05 09:21:23 -07:00
Dan Gohman
4e67e08efd Use the target-lexicon crate.
This switches from a custom list of architectures to use the
target-lexicon crate.

 - "set is_64bit=1; isa x86" is replaced with "target x86_64", and
   similar for other architectures, and the `is_64bit` flag is removed
   entirely.

 - The `is_compressed` flag is removed too; it's no longer being used to
   control REX prefixes on x86-64, ARM and Thumb are separate
   architectures in target-lexicon, and we can figure out how to
   select RISC-V compressed encodings when we're ready.
2018-05-30 06:13:35 -07:00
Dan Gohman
a1fe0f82e1 Update to the latest stable rustfmt, 0.4.2-stable (febbb36 2018-04-12). 2018-05-29 10:37:38 -07:00
Dan Gohman
6b88cd44a8 Update to rustfmt-preview (#348)
* Update to rustfmt-preview.

* Run "cargo fmt --all" with rustfmt 0.4.1.

rustfmt 0.4.1 is the latest release of rustfmt-preview available on the
stable channel.

* Fix a long line that rustfmt 0.4.1 can't handle.

* Remove unneeded commas left behind by rustfmt.
2018-05-25 11:38:38 -07:00
Ram
4afb28ef59 Use wabt, and make the wasm subcommand optional. (#347)
* Use wabt for wasm testing.

* Use wabt in cton-util.

* Make the wasm subcommand optional.
2018-05-24 08:23:00 -07:00
Dan Gohman
89e7d56120 Allow wasm embedders to reject wasm modules with unsupported features. (#345)
Define `WasmError` (and an accompanying `WasmResult`) to represent
errors translating WebAssembly functions. Make `translate_call` and
related functions return `WasmResult`s so that embedders have the
flexibility to reject features they don't support.

Move `InvalidInput` out of `CtonError` and into `WasmError`, where it's
now named `InvalidWebAssembly`, as it's a WebAssembly-specific error
condition. Also extend it to preserve the original error message and
bytecode offset.
2018-05-21 20:49:19 -07:00
Dan Gohman
94a883abae Make settings::Flags::new consume the Builder.
This makes it more clear what the relationship is between the Builder
and the resulting Flags.
2018-04-30 13:53:36 -07:00
Tyler McMullen
8351ba3e3e Disassemble compiled binary for debugging (#308)
* Use Capstone to disassemble and print code after compilation in cton-util.

* Fix rustfmt errors
2018-04-23 20:24:02 -07:00
Dan Gohman
d7e13284b2 Mark emit_to_memory as unsafe, and introduce a safe emit. (#281)
* Mark emit_to_memory as unsafe, and provide a safe compile_and_emit.

Mark `Context::emit_to_memory` and `MemoryCodeSink::new` as unsafe, as
`MemoryCodeSink` does not perform bounds checking when writing to
memory.

Add a `Context::compile_and_emit` function which provides a convenient
interface for doing `compile` and `emit_to_memory` in one step, and
which can also provide a safe interface, since it allocates memory of
the needed size itself.

* Mention that `MemoryCodeSink` can't guarantee that the pointer is valid.
2018-04-18 06:35:47 -07:00