|
1 |
| -# Rust Stable MIR Pretty Printing |
| 1 | +# Rust Stable MIR JSON Generator |
2 | 2 |
|
3 |
| -This package provides a program that will emit a JSON serialisation of the Stable MIR of a Rust program |
| 3 | +This package provides a program that will emit a JSON serialisation of the Stable MIR of a Rust program, along with a comprehensive JSON schema for validation and tooling integration. |
4 | 4 |
|
5 | 5 | ## Building
|
6 | 6 |
|
@@ -79,4 +79,53 @@ cargo run --bin cargo_stable_mir_json -- $PWD [OPTIONAL-PATH-FOR-DIR]
|
79 | 79 | ```bash
|
80 | 80 | RUSTC=<PATH-TO-.stable_mir_json>/<PROFILE>.sh cargo build
|
81 | 81 | ```
|
82 |
| -NOTE: by default `<PATH-TO-.stable_mir_json>` is `~/.stable_mir_json` |
| 82 | +NOTE: by default `<PATH-TO-.stable_mir_json>` is `~/.stable_mir_json` |
| 83 | + |
| 84 | +## JSON Schema |
| 85 | + |
| 86 | +This repository includes a comprehensive JSON schema for the Stable MIR JSON format, enabling validation, tooling integration, and documentation. |
| 87 | + |
| 88 | +### Schema Location |
| 89 | + |
| 90 | +- **Schema file**: [`schema/stable-mir.schema.json`](schema/stable-mir.schema.json) |
| 91 | +- **Documentation**: [`docs/schema.md`](docs/schema.md) |
| 92 | + |
| 93 | +### Validation |
| 94 | + |
| 95 | +Validate your generated JSON files against the schema: |
| 96 | + |
| 97 | +```shell |
| 98 | +# Validate all test files |
| 99 | +./scripts/validate-schema.sh |
| 100 | + |
| 101 | +# Validate specific files |
| 102 | +./scripts/validate-schema.sh path/to/your/file.smir.json |
| 103 | + |
| 104 | +# Verbose validation with detailed output |
| 105 | +./scripts/validate-schema.sh --verbose |
| 106 | +``` |
| 107 | + |
| 108 | +### Schema Features |
| 109 | + |
| 110 | +- **Complete coverage** of all Stable MIR data structures |
| 111 | +- **Type safety** with detailed type definitions and constraints |
| 112 | +- **Documentation** with descriptions for all fields and structures |
| 113 | +- **Validation support** for development and CI/CD pipelines |
| 114 | +- **Tool integration** compatible with standard JSON Schema validators |
| 115 | + |
| 116 | +### Using with External Tools |
| 117 | + |
| 118 | +```shell |
| 119 | +# Using ajv-cli (npm install -g ajv-cli) |
| 120 | +ajv validate -s schema/stable-mir.schema.json -d "file.smir.json" |
| 121 | + |
| 122 | +# Using Python jsonschema (pip install jsonschema) |
| 123 | +python -c " |
| 124 | +import json, jsonschema |
| 125 | +schema = json.load(open('schema/stable-mir.schema.json')) |
| 126 | +data = json.load(open('file.smir.json')) |
| 127 | +jsonschema.validate(data, schema) |
| 128 | +" |
| 129 | +``` |
| 130 | + |
| 131 | +For detailed schema documentation, see [`docs/schema.md`](docs/schema.md). |
0 commit comments