|
Revision tags: dev, v36.0.9, v44.0.1, v43.0.2, v36.0.8, v24.0.8, v44.0.0, v43.0.1, v42.0.2, v36.0.7, v24.0.7, v43.0.0, v42.0.1, v41.0.4, v42.0.0, v40.0.4, v36.0.6, v24.0.6, v41.0.3, v41.0.2, v41.0.1, v36.0.5, v40.0.3, v41.0.0, v36.0.4, v39.0.2, v40.0.2, v40.0.1, v40.0.0, v39.0.1, v39.0.0, v38.0.4, v37.0.3, v36.0.3, v24.0.5, v38.0.3, v38.0.2, v38.0.1, v37.0.2, v37.0.1, v37.0.0, v36.0.2, v36.0.1, v36.0.0, v35.0.0, v24.0.4, v33.0.2, v34.0.2, v34.0.1, v33.0.1, v24.0.3, v32.0.1, v34.0.0, v33.0.0, v32.0.0, v31.0.0 |
|
| #
c3bf042a |
| 07-Mar-2025 |
Andrew Brown <[email protected]> |
meta: deduplicate source generation infrastructure (#10348)
* Move `Formatter` and `Error` to new crate: `cranelift-srcgen`
The `cranelift-codegen-meta` crate emits both Rust and ISLE source code u
meta: deduplicate source generation infrastructure (#10348)
* Move `Formatter` and `Error` to new crate: `cranelift-srcgen`
The `cranelift-codegen-meta` crate emits both Rust and ISLE source code using a `Formatter` which may fail with an `Error`. The `cranelift-assembler-x64-meta` crate uses a subset of this functionality. To deduplicate efforts, this creates a new crate, `cranelift-srcgen`, and moves only the `cranelift-codgen-meta` functionality there (for now).
* Add notion of a formatted `Language`; append file locations
While developing `cranelift-assembler-x64`, it became clear that knowing the source code location that _generated_ some code was extremely useful. This change alters the `fmtln!` macro to append file locations as comments to the generated code; this doesn't change all the `fmt.line()` invocations but it's a start. To do this, we need to know which language we are generating to emit the correct comment kind. This led to adding a new `enum Language` to identify that.
* Rename `update_file` to `write`
* Use shared `Formatter` in `cranelift-assembler-x64-meta`
This change removes the duplicate implementation of `Formatter` in `cranelift-assembler-x64-meta` and replaces it with the shared `Formatter` in `cranelift-srcgen`.
* Add `Formatter::add_block`
While implementing all these changes, I noticed an opportunity: by adding `Formatter::add_block` we can automatically adds braces and indentation. This should be more safe (i.e., harder to forget to append the ending `}`) and result in less verbose generator code (no need for `fmtln!(...)` then `f.indent(|f| ...)`). This refactoring does touch a large amount of code, though.
Now with `Formatter::add_block`, we can allow the `fmtln!` macro to auto-format no-arg format strings (e.g., `fmtln!(f, "{x}")`), which should be a bit more ergonomic. This does mean that a few locations that weren't covered by `Formatter::add_block` need some extra escaping (e.g., `{` -> `{{`).
* Avoid appending a file location comment to a Rust comment
* Make `cranelift-srcgen` publishable
This ensures the crate has a version and is tracked by `cranelift-srcgen`.
show more ...
|