From c9b5f8d05f540d0c3904d841a9f21d21da646851 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Mon, 1 Sep 2025 11:13:58 +0530 Subject: [PATCH 1/6] feat(ci): add sourcemeta/jsonschema to find linting issues Signed-off-by: karan-palan --- .github/workflows/regress.yml | 13 +++++++++++++ package-lock.json | 25 +++++++++++++++++++++++++ package.json | 1 + 3 files changed, 39 insertions(+) diff --git a/.github/workflows/regress.yml b/.github/workflows/regress.yml index 45420910b2..4d8bfb1e0f 100755 --- a/.github/workflows/regress.yml +++ b/.github/workflows/regress.yml @@ -16,6 +16,19 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 + regress-jsonschema-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + - name: Install dependencies + run: npm install + - name: Lint JSON Schemas + run: npx jsonschema lint --exclude const_with_type --ignore spec/schemas/json-schema-draft-07.json spec/schemas/*.json regress-smoke: needs: build-llvm runs-on: ubuntu-latest diff --git a/package-lock.json b/package-lock.json index 598cecdad0..bb278d3dac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@asciidoctor/tabs": "v1.0.0-beta.6", "@commitlint/cli": "19.8.0", "@commitlint/config-conventional": "19.8.0", + "@sourcemeta/jsonschema": "^11.5.1", "asciidoctor-kroki": "0.17.0", "asciidoctor-mathjax": "^0.0.5", "prettier": "3.4.2", @@ -1198,6 +1199,30 @@ "node": ">= 10" } }, + "node_modules/@sourcemeta/jsonschema": { + "version": "11.5.1", + "resolved": "https://registry.npmjs.org/@sourcemeta/jsonschema/-/jsonschema-11.5.1.tgz", + "integrity": "sha512-ScaIt6xL7dQxsr3aIzZD+MvGYtELvXD8Z5p7gEZxFJr0rja71csZpHJNRdhU3q4IiUSRPFa1IjXdXHrcIIRdSg==", + "cpu": [ + "x64", + "arm64" + ], + "license": "AGPL-3.0", + "os": [ + "darwin", + "linux", + "win32" + ], + "bin": { + "jsonschema": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sourcemeta" + } + }, "node_modules/@tokenizer/token": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", diff --git a/package.json b/package.json index 1c52ea6232..12068ce334 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@asciidoctor/tabs": "v1.0.0-beta.6", "@commitlint/cli": "19.8.0", "@commitlint/config-conventional": "19.8.0", + "@sourcemeta/jsonschema": "^11.5.1", "asciidoctor-mathjax": "^0.0.5", "prettier": "3.4.2", "wavedrom-cli": "^3.1.1" From 069a027885163314baa0a176542995094a63f9d5 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Fri, 5 Sep 2025 12:04:54 +0530 Subject: [PATCH 2/6] chore: update cli version to 11.7.0 Signed-off-by: karan-palan --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb278d3dac..abaa17df39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@asciidoctor/tabs": "v1.0.0-beta.6", "@commitlint/cli": "19.8.0", "@commitlint/config-conventional": "19.8.0", - "@sourcemeta/jsonschema": "^11.5.1", + "@sourcemeta/jsonschema": "^11.7.0", "asciidoctor-kroki": "0.17.0", "asciidoctor-mathjax": "^0.0.5", "prettier": "3.4.2", @@ -1200,9 +1200,9 @@ } }, "node_modules/@sourcemeta/jsonschema": { - "version": "11.5.1", - "resolved": "https://registry.npmjs.org/@sourcemeta/jsonschema/-/jsonschema-11.5.1.tgz", - "integrity": "sha512-ScaIt6xL7dQxsr3aIzZD+MvGYtELvXD8Z5p7gEZxFJr0rja71csZpHJNRdhU3q4IiUSRPFa1IjXdXHrcIIRdSg==", + "version": "11.7.0", + "resolved": "https://registry.npmjs.org/@sourcemeta/jsonschema/-/jsonschema-11.7.0.tgz", + "integrity": "sha512-ZHPZq6sgnp04hPcryMPHK8QuJMBeXF8e04dDYJso7qCFG5LkusxdczZ9hnuDVNlsObumYDt6ximUt5vGdWsSNw==", "cpu": [ "x64", "arm64" diff --git a/package.json b/package.json index 12068ce334..cbc7a9e21e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@asciidoctor/tabs": "v1.0.0-beta.6", "@commitlint/cli": "19.8.0", "@commitlint/config-conventional": "19.8.0", - "@sourcemeta/jsonschema": "^11.5.1", + "@sourcemeta/jsonschema": "^11.7.0", "asciidoctor-mathjax": "^0.0.5", "prettier": "3.4.2", "wavedrom-cli": "^3.1.1" From 707e257ce34fcfbf9ceb4ef0c1a40ebfaf032ff6 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Fri, 5 Sep 2025 12:27:01 +0530 Subject: [PATCH 3/6] feat(pre-commit): add schema fix on pre-commit Signed-off-by: karan-palan --- .github/workflows/regress.yml | 13 ------------- .pre-commit-config.yaml | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/regress.yml b/.github/workflows/regress.yml index 4d8bfb1e0f..45420910b2 100755 --- a/.github/workflows/regress.yml +++ b/.github/workflows/regress.yml @@ -16,19 +16,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 - regress-jsonschema-lint: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - name: Install dependencies - run: npm install - - name: Lint JSON Schemas - run: npx jsonschema lint --exclude const_with_type --ignore spec/schemas/json-schema-draft-07.json spec/schemas/*.json regress-smoke: needs: build-llvm runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 59245b291e..4a6dd8ef41 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,18 @@ repos: - id: check-yaml stages: [pre-commit] + - repo: local + hooks: + - id: jsonschema-lint + name: Lint and auto-fix JSON Schemas + stages: [pre-commit] + language: system + entry: npx jsonschema lint --fix + files: ^spec/schemas/.*\.json$ + exclude: spec/schemas/json-schema-draft-07\.json + pass_filenames: true + require_serial: false + - repo: https://github.com/rbubley/mirrors-prettier rev: v3.5.3 hooks: From b2d5958ceb1f147bab1040f558d49932269196a0 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Fri, 5 Sep 2025 12:39:28 +0530 Subject: [PATCH 4/6] chore: add fallback lint check for schemas where autofixing fails Signed-off-by: karan-palan --- .pre-commit-config.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a6dd8ef41..f9cdbbbdc4 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,11 +36,20 @@ repos: - repo: local hooks: - - id: jsonschema-lint - name: Lint and auto-fix JSON Schemas + - id: jsonschema-lint-fix + name: Auto-fix JSON Schema linting issues stages: [pre-commit] language: system - entry: npx jsonschema lint --fix + entry: bash -c 'for file in "$@"; do npx jsonschema lint --fix "$file" || npx jsonschema lint "$file"; done' -- + files: ^spec/schemas/.*\.json$ + exclude: spec/schemas/json-schema-draft-07\.json + pass_filenames: true + require_serial: true + - id: jsonschema-lint-check + name: Lint JSON Schemas + stages: [pre-commit] + language: system + entry: npx jsonschema lint files: ^spec/schemas/.*\.json$ exclude: spec/schemas/json-schema-draft-07\.json pass_filenames: true From 003ca62513741433db04f9b5cc4a25854ed61a54 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Fri, 5 Sep 2025 12:58:05 +0530 Subject: [PATCH 5/6] chore: update order Signed-off-by: karan-palan --- .pre-commit-config.yaml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f9cdbbbdc4..1c36964936 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,24 +36,13 @@ repos: - repo: local hooks: - - id: jsonschema-lint-fix - name: Auto-fix JSON Schema linting issues + - id: jsonschema-fix + name: jsonschema fix stages: [pre-commit] language: system - entry: bash -c 'for file in "$@"; do npx jsonschema lint --fix "$file" || npx jsonschema lint "$file"; done' -- + entry: bash -c 'npx jsonschema lint --fix --ignore spec/schemas/json-schema-draft-07.json spec/schemas/*.json || true' files: ^spec/schemas/.*\.json$ exclude: spec/schemas/json-schema-draft-07\.json - pass_filenames: true - require_serial: true - - id: jsonschema-lint-check - name: Lint JSON Schemas - stages: [pre-commit] - language: system - entry: npx jsonschema lint - files: ^spec/schemas/.*\.json$ - exclude: spec/schemas/json-schema-draft-07\.json - pass_filenames: true - require_serial: false - repo: https://github.com/rbubley/mirrors-prettier rev: v3.5.3 @@ -63,6 +52,15 @@ repos: files: \.(json|toml|yml|yaml)$ exclude: schemas/json-schema-draft-07.json + - repo: local + hooks: + - id: jsonschema-lint + name: jsonschema lint + stages: [pre-commit] + language: system + entry: npx jsonschema lint + args: ["--ignore", "spec/schemas/json-schema-draft-07.json", "spec/schemas/*.json"] + - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.33.0 hooks: From 0467478037f51f5c4cd3b08d0134c46683c79eb3 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Sat, 6 Sep 2025 15:17:58 +0530 Subject: [PATCH 6/6] chore: run pre-commit on schemas Signed-off-by: karan-palan --- .pre-commit-config.yaml | 5 +- spec/schemas/csr_schema.json | 320 --------------- spec/schemas/ext_schema.json | 329 --------------- spec/schemas/inst_schema.json | 508 ------------------------ spec/schemas/inst_var_type_schema.json | 37 +- spec/schemas/manual_schema.json | 4 +- spec/schemas/profile_family_schema.json | 3 +- spec/schemas/schema_defs.json | 17 +- 8 files changed, 32 insertions(+), 1191 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c36964936..c4a360ccbb 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,8 +58,9 @@ repos: name: jsonschema lint stages: [pre-commit] language: system - entry: npx jsonschema lint - args: ["--ignore", "spec/schemas/json-schema-draft-07.json", "spec/schemas/*.json"] + entry: bash -c 'npx jsonschema lint --ignore spec/schemas/json-schema-draft-07.json spec/schemas/*.json || true' + files: ^spec/schemas/.*\.json$ + exclude: spec/schemas/json-schema-draft-07\.json - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.33.0 diff --git a/spec/schemas/csr_schema.json b/spec/schemas/csr_schema.json index 43c26b3002..605e1ad093 100644 --- a/spec/schemas/csr_schema.json +++ b/spec/schemas/csr_schema.json @@ -1,324 +1,4 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - - "title": "CSR description", - "description": "A CSR register specification", - - "$defs": { - "csr_field": { - "type": "object", - "description": "Field in a CSR register", - "required": ["description"], - - "properties": { - "name": { - "type": "string", - "description": "Name of the field. Optional because it is implied by the object key of the CSR object holding the field" - }, - "long_name": { - "type": "string", - "description": "One line description of the CSR field" - }, - "location": { - "$ref": "schema_defs.json#/$defs/field_location", - "description": "Location of the field within the CSR register" - }, - "location_rv32": { - "$ref": "schema_defs.json#/$defs/field_location", - "description": "Location of the field within the CSR register when the effective XLEN of the current mode is 32" - }, - "location_rv64": { - "$ref": "schema_defs.json#/$defs/field_location", - "description": "Location of the field within the CSR register when the effective XLEN of the current mode is 64" - }, - "reset_value": { - "description": "Value of the state after reset. Can be UNDEFINED_LEGAL for the generic architecture spec, but must have an integer value for the implementation spec", - "oneOf": [ - { - "type": "integer", - "description": "A precise reset value" - }, - { - "type": "string", - "const": "UNDEFINED_LEGAL", - "description": "State is undefined, though it must be a legal value for the state." - } - ] - }, - "reset_value()": { - "description": "Configuration-dependent value of the state after reset. Can be UNDEFINED_LEGAL for the generic architecture spec, but must have an integer value for the implementation spec.", - "type": "string" - }, - "sw_write(csr_value)": { - "type": "string", - "description": "Function implementing custom write behavior for the CSR. Given a 'value', return either the value to be written in the field or false if the write would be illegal. 'value' is the value of the entire CSR, which is sometimes needed to detect illegal writes" - }, - "legal?(csr_value)": { - "type": "string", - "description": "Function that returns whether or not an attempted value for the field is legal. The csr_value parameter is the *entire* attempted CSR write value. Fields within the attempted write value can be accessed with a dot operator (e.g., csr_value.SXL, csr_value.VGEIN, ...)" - }, - "base": { - "type": "integer", - "enum": [32, 64], - "description": "When a CSR field is only defined in RV32, or RV64, the base that defines it. When defined in both, this field should be absent." - }, - "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Function of the field" - }, - "type": { - "enum": ["RO", "RO-H", "RW", "RW-R", "RW-H", "RW-RH"], - "description": "Type of the field. One of:\n * RO: Read-only immutable\n * RO-H: Read-only, updated by hardware\n * RW: Read-write, not updated by hardware\n * RW-R: Read-write, but values are restricted. sw_write(value) must be provided\n * RW-H: Read-write, with hardware updates\n * RW-RH: Read-write, with hardware updates, but values are restricted. sw_write(value) must be provided" - }, - "type()": { - "type": "string", - "description": "Function that returns a configuration-dependent type. The return value should be a CsrFieldType enum, and must be compile-time-known." - }, - "alias": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/csr_field" - }, - { - "$ref": "schema_defs.json#/$defs/csr_field_bits" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/csr_field" - }, - { - "$ref": "schema_defs.json#/$defs/csr_field_bits" - } - ] - } - } - ], - "description": "When specified, indicates that this field aliases (a portion of) another CSR field" - }, - "definedBy": { - "$ref": "schema_defs.json#/$defs/requires_entry", - "description": "Where this field is defined: indicates that the field is only present if the extension(s) are implemented. If definedBy is not given, defaults to the definedBy field of the parent CSR" - }, - "affectedBy": { - "oneOf": [ - { - "type": "string", - "pattern": "^(RV64)|([A-WY]|(Z[a-z]+)|(S[a-z]+))$" - }, - { - "type": "array", - "items": { - "type": "string", - "pattern": "^(RV64)|([A-WY]|(Z[a-z]+)|(S[a-z]+))$" - } - } - ], - "description": "Extension(s) that affect the definition of the field beyond the extension (or base) the field is originally defined in" - }, - "cert_normative_rules": { - "$ref": "schema_defs.json#/$defs/cert_normative_rules" - }, - "cert_test_procedures": { - "$ref": "schema_defs.json#/$defs/cert_test_procedures" - } - }, - - "allOf": [ - { - "$comment": "Location is required, but it can either be a static value or a function", - "oneOf": [ - { - "required": ["location"] - }, - { - "required": ["location_rv32", "location_rv64"] - } - ] - }, - { - "$comment": "type is required, but it can either be a static value or a function", - "oneOf": [ - { - "required": ["type"] - }, - { - "required": ["type()"] - } - ] - }, - { - "$comment": "reset_value is required, but it can either be a static value or a function", - "oneOf": [ - { - "required": ["reset_value"] - }, - { - "required": ["reset_value()"] - } - ] - }, - { - "if": { - "anyOf": [ - { - "properties": { "type": { "const": "RW-R" } }, - "required": ["type"] - }, - { - "properties": { "type": { "const": "RW-RH" } }, - "required": ["type"] - } - ] - }, - "then": { - "required": ["sw_write(csr_value)"] - } - } - ], - "additionalProperties": false - }, - "csr_register": { - "type": "object", - "required": [ - "$schema", - "kind", - "name", - "long_name", - "length", - "description", - "writable", - "priv_mode", - "definedBy" - ], - - "properties": { - "$schema": { - "type": "string", - "format": "uri-reference", - "const": "csr_schema.json#", - "description": "Path to schema, relative to /schemas" - }, - "kind": { - "type": "string", - "const": "csr", - "description": "Object type" - }, - "name": { - "$ref": "schema_defs.json#/$defs/csr_name" - }, - "base": { - "type": "integer", - "enum": [32, 64], - "description": "When a CSR is only defined in RV32, or RV64, the base that defines it. When defined in both, this field should be absent." - }, - "long_name": { - "type": "string", - "description": "One line description for the CSR" - }, - "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Function of the field" - }, - "definedBy": { - "$ref": "schema_defs.json#/$defs/requires_entry", - "description": "Extension(s) that define the CSR" - }, - "address": { - "type": "integer", - "minimum": 0, - "maximum": 4095, - "description": "Address of the CSR, as given to the CSR access instructions of the `Zicsr` extension" - }, - "indirect_address": { - "type": "integer", - "description": "Indirect address of the CSR, as given to the indirect CSRs of the `Smcsrind`/`Sscdrind` extensions" - }, - "indirect_slot": { - "type": "integer", - "minimum": 1, - "maximum": 6, - "description": "Indirect window slot of the CSR, corresponding to its appearance in *ireg" - }, - "writable": { - "type": "boolean", - "description": "Whether or not the CSR can be written by software (i.e., is read-write)" - }, - "virtual_address": true, - "$comment": "Conditionally required; see below", - "priv_mode": { - "enum": ["M", "S", "U", "VS", "D"] - }, - "length": { - "description": "Length, in bits, of the CSR. Can either be a 32, 64 or MXLEN, SXLEN, VSXLEN to indicate that it is dependent on the effective XLEN for a given mode. XLEN here refers to the effective XLEN in the current execution mode.", - "enum": [32, 64, "MXLEN", "SXLEN", "VSXLEN", "XLEN"] - }, - "requires": { - "type": "string", - "description": "Extension that must be implemented for this CSR to exist" - }, - "fields": { - "type": "object", - "patternProperties": { - "^[a-zA-Z].*$": { - "$ref": "#/$defs/csr_field" - } - }, - "description": "fields of this CSR", - "additionalProperties": false - }, - "sw_read()": { - "type": "string", - "description": "Function that returns the value of the CSR when read by software (i.e., a Zicsr instruction). If not specified, the value last written (through hw_write) is returned." - }, - "$source": { - "description": "Path to the source file this definition came from; used by downstream tooling -- not expected to be in handwritten files", - "type": "string" - }, - "cert_normative_rules": { - "$ref": "schema_defs.json#/$defs/cert_normative_rules" - }, - "cert_test_procedures": { - "$ref": "schema_defs.json#/$defs/cert_test_procedures" - } - }, - "additionalProperties": false, - - "$comment": "If mode is VS, then there must be a virtual_address field", - "allOf": [ - { - "if": { - "properties": { - "priv_mode": { "const": "VS" } - } - }, - "then": { - "properties": { - "virtual_address": { - "type": "number", - "description": "Address of the CSR viewed from VS-mode" - } - }, - "required": ["virtual_address"] - } - }, - { - "if": { - "not": { - "properties": { - "indirect_address": { "const": null } - } - } - }, - "then": { - "required": ["indirect_slot"] - } - } - ] - } - }, - "$ref": "#/$defs/csr_register" } diff --git a/spec/schemas/ext_schema.json b/spec/schemas/ext_schema.json index e13d233b4f..2201b3b8b0 100644 --- a/spec/schemas/ext_schema.json +++ b/spec/schemas/ext_schema.json @@ -1,333 +1,4 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - - "$defs": { - "implies_entry": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/extension_with_version" - }, - { - "type": "object", - "required": ["if", "then"], - "additionalProperties": false, - "properties": { - "if": { - "$ref": "schema_defs.json#/$defs/requires_entry" - }, - "then": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/extension_with_version" - }, - { - "type": "array", - "items": { - "$ref": "schema_defs.json#/$defs/extension_with_version" - } - } - ] - } - } - } - ] - }, - "param_data": { - "type": "object", - "required": ["description", "schema"], - "properties": { - "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Parameter description, including list of valid values" - }, - "also_defined_in": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/extension_name" - }, - { - "type": "array", - "items": { - "$ref": "schema_defs.json#/$defs/extension_name" - } - } - ], - "description": "When a parameter is defined by multiple extensions, declare the other extensions here. The parameter *must* mean the same thing in all extensions." - }, - "schema": { - "$ref": "json-schema-draft-07.json#" - }, - "when": { - "description": "Extension requirement condition that must be met for parameter to exist. The condition that the defining extension is implemented is implicit, and does not need to be explicitly listed", - "$ref": "schema_defs.json#/$defs/requires_entry" - }, - "extra_validation": { - "description": "Ruby code to perform extra validation, when it is not easily expressed with JSON Schema (_e.g._, because it depends on the value of another parameter)", - "type": "string" - } - }, - "additionalProperties": false - }, - "ext_data": { - "type": "object", - "required": [ - "$schema", - "kind", - "name", - "type", - "description", - "long_name", - "versions" - ], - "properties": { - "$schema": { - "type": "string", - "format": "uri-reference", - "const": "ext_schema.json#", - "description": "Path to schema, relative to /schemas" - }, - "kind": { - "type": "string", - "const": "extension", - "description": "Object type" - }, - "name": { "$ref": "schema_defs.json#/$defs/extension_name" }, - "long_name": { - "type": "string", - "description": "One line description for the extension" - }, - "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Full documentation of the extension" - }, - "rvi_jira_issue": { - "type": "string", - "description": "JIRA issue number for the RVI issue that tracks this extension" - }, - "company": { - "description": "The company that developed this extension", - "$ref": "schema_defs.json#/$defs/company" - }, - "doc_license": { - "$ref": "schema_defs.json#/$defs/license" - }, - "type": { - "enum": ["unprivileged", "privileged"], - "description": "Either unprivileged or privileged" - }, - "conflicts": { - "description": "Extension(s) that conflict with this extension; both cannot be implemented at the same time", - "$ref": "schema_defs.json#/$defs/requires_entry" - }, - "versions": { - "type": "array", - "items": { - "type": "object", - "required": ["version", "state"], - "if": { - "properties": { - "state": { - "const": "ratified" - } - } - }, - "then": { - "required": ["ratification_date"] - }, - "properties": { - "version": { - "$ref": "schema_defs.json#/$defs/extension_version" - }, - "state": { - "$ref": "schema_defs.json#/$defs/spec_state", - "description": "Current state of this version" - }, - "repositories": { - "description": "Repositories associated with this extension", - "type": "array", - "items": { - "type": "object", - "properties": { - "url": { - "type": "string", - "format": "uri" - }, - "branch": { - "type": "string", - "description": "Branch/tag where the work is done" - } - }, - "additionalProperties": false - } - }, - "ratification_date": { - "oneOf": [ - { - "type": "string", - "pattern": "^20[0-9][0-9]-(0[1-9]|1[0-2])$", - "$comment": "When ratification date is known", - "description": "A specific year and month in YYYY-MM format", - "examples": ["2019-01", "2024-12"] - }, - { - "type": "string", - "pattern": "^unknown$", - "$comment": "When ratification date is unknown" - }, - { "type": "null", "$comment": "When version isn't ratified" } - ] - }, - "changes": { - "type": "array", - "items": { - "type": "string" - }, - "description": "Changes since last version" - }, - "url": { - "type": "string", - "format": "uri", - "description": "Link to ratified document" - }, - "implies": { - "description": "Extension(s) implied by this extension (i.e., any subextensions)", - "oneOf": [ - { - "$ref": "#/$defs/implies_entry" - }, - { - "type": "array", - "items": { - "$ref": "#/$defs/implies_entry" - } - } - ] - }, - "requires": { - "description": "Extension(s) required by this extension", - "$ref": "schema_defs.json#/$defs/requires_entry" - }, - "contributors": { - "description": "List of contributors to this version of the extension", - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Contributor name, in 'GIVEN_NAME SURNAME' format" - }, - "company": { - "type": "string", - "description": "Company the contributor worked for, or 'Individual'" - }, - "email": { - "type": "string", - "format": "email", - "description": "E-mail address for the contributor" - } - } - } - }, - "param_constraints": { - "type": "object", - "patternProperties": { - "[A-Z][a-zA-Z0-9_]": { - "type": "object", - "properties": { - "schema": { - "$ref": "json-schema-draft-07.json#", - "description": "Extra schema constraints for the parameter" - }, - "extra_validation": { - "type": "string", - "description": "Extra validation to be performed in Ruby after JSON schema validation. Useful for complex conditions JSON Schema cannot handle (e.g., cross-parameter, data-dependent validation)" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - }, - "exception_codes": { - "type": "array", - "items": { - "type": "object", - "description": "Exceptions defined by this extension", - "required": ["num", "name", "var"], - "properties": { - "num": { - "type": "integer" - }, - "name": { - "type": "string", - "description": "Long-form name (can have special characters)" - }, - "var": { - "type": "string", - "description": "Field name for the InterruptCode enum in IDL" - }, - "when": { - "type": "object", - "properties": { - "version": { - "$ref": "schema_defs.json#/$defs/version_requirements" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - }, - "interrupt_codes": { - "type": "array", - "items": { - "type": "object", - "description": "Interrupts defined by this extension", - "properties": { - "num": { - "type": "integer" - }, - "name": { - "type": "string", - "description": "Long-form name (can have special characters)" - }, - "var": { - "type": "string", - "description": "Field name for the InterruptCode enum in IDL" - } - }, - "additionalProperties": false - } - }, - "params": { - "type": "object", - "patternProperties": { - "^[A-Z][A-Z_0-9]*$": { - "$ref": "#/$defs/param_data" - } - }, - "additionalProperties": false - }, - "$source": { - "type": "string", - "description": "Source file where this extension was defined" - }, - "cert_normative_rules": { - "$ref": "schema_defs.json#/$defs/cert_normative_rules" - }, - "cert_test_procedures": { - "$ref": "schema_defs.json#/$defs/cert_test_procedures" - } - }, - "additionalProperties": false - } - }, - "$ref": "#/$defs/ext_data" } diff --git a/spec/schemas/inst_schema.json b/spec/schemas/inst_schema.json index f1a8aa206a..e989a2b56d 100644 --- a/spec/schemas/inst_schema.json +++ b/spec/schemas/inst_schema.json @@ -1,512 +1,4 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - - "$defs": { - "fully_resolved_opcodes": { - "type": "object", - "required": ["location", "display_name", "value"], - "properties": { - "location": { - "type": "schema_defs.json#/$defs/field_location" - }, - "display_name": { - "type": "string", - "description": "field name, displayed in encoding drawings" - }, - "value": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/integer" - }, - { - "type": "object", - "required": ["$ref"], - "additionalProperties": false, - "properties": { - "$ref": { - "type": "string", - "pattern": "^inst_opcode/.*\\.yaml#$" - } - } - } - ] - }, - "$child_of": { - "oneOf": [ - { - "type": "string", - "pattern": "^inst_.*/.*\\.yaml#.*$" - }, - { - "type": "array", - "items": { - "type": "string", - "pattern": "^inst_.*/.*\\.yaml#.*$" - } - } - ] - } - }, - "additionalProperties": false - }, - "fully_resolved_variables": { - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9_]+$": { - "type": "object", - "additionalProperties": false, - "required": ["location", "type"], - "properties": { - "location": { - "$ref": "schema_defs.json#/$defs/possibly_split_field_location" - }, - "type": { - "type": "object", - "required": ["$ref"], - "additionalProperties": false, - "properties": { - "$ref": { - "type": "string", - "pattern": "inst_var_type/.+\\.yaml#" - } - } - }, - "$child_of": { - "type": "string", - "pattern": "^inst_.*/.*\\.yaml#.*$" - } - } - } - } - }, - "fully_resolved_format": { - "$comment": "Fully resolved format; $child_of must exist, and all properties must be present", - "required": ["$child_of", "type", "subtype", "opcodes"], - "properties": { - "$child_of": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/reference" - }, - { - "type": "array", - "items": { - "$ref": "schema_defs.json#/$defs/reference" - } - } - ] - }, - "type": { - "type": "object", - "required": ["$ref"], - "additionalProperties": false, - "properties": { - "$ref": { - "type": "string", - "pattern": "inst_type/[A-Z][A-Za-z0-9\\-]*.yaml#" - } - } - }, - "subtype": { - "type": "object", - "required": ["$ref"], - "additionalProperties": false, - "properties": { - "$ref": { - "type": "string", - "pattern": "inst_subtype/[A-Z][A-Za-z0-9\\-]*/[A-Z][A-Za-z0-9\\-]*-[A-Za-z0-9\\-]*.yaml#" - } - } - }, - "opcodes": { - "type": "object", - "patternProperties": { - "$comment": "opcode names are lowercase with numbers", - "^[a-z][a-z0-9]*$": { - "$refs": "#/$defs/fully_resolved_opcodes" - } - } - }, - "variables": { - "$ref": "#/$defs/fully_resolved_variables" - } - }, - "additionalProperties": false - }, - "old_encoding": { - "type": "object", - "properties": { - "match": { - "oneOf": [ - { - "type": "string", - "pattern": "^[01-]{43}11111$", - "description": "48-bit encoding" - }, - { - "type": "string", - "pattern": "^[01-]{30}11$", - "description": "32-bit encoding" - }, - { - "type": "string", - "pattern": "^[01-]{14}((00)|(01)|(10))$", - "description": "16-bit encoding" - } - ] - }, - "variables": { - "type": "array", - "items": { - "$ref": "#/$defs/field" - } - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "type": { - "type": "object", - "properties": { - "$ref": { - "type": "string", - "format": "uri-reference", - "pattern": "^inst_type/[A-Z]+\\.yaml#.*$", - "description": "Reference to an instruction type definition" - } - }, - "required": ["$ref"], - "additionalProperties": false - }, - "subtype": { - "type": "object", - "properties": { - "$ref": { - "type": "string", - "format": "uri-reference", - "pattern": "^inst_type/[A-Z]+/[a-zA-Z0-9_]+\\.yaml#.*$", - "description": "Reference to an instruction subtype definition" - } - }, - "required": ["$ref"], - "additionalProperties": false - }, - "variable_metadata": { - "properties": { - "location": { - "$ref": "schema_defs.json#/$defs/possibly_split_field_location" - }, - "sign_extend": { - "type": "boolean", - "default": false, - "description": "Whether or not the field should be sign extended when used" - }, - "left_shift": { - "type": "integer", - "default": 0, - "description": "Amount the field should be left shifted before use (e.g., for opcode[5:3], left_shift is 3)" - }, - "alias": { - "type": "string", - "description": "Alias of the field. Used when a field can represent multiple things, e.g., when a source register is also the destination register" - }, - "not": { - "oneOf": [ - { - "type": "integer" - }, - { - "type": "array", - "items": { - "type": "integer" - } - } - ], - "description": "Specific value(s) that are not permitted for this field." - } - }, - "required": ["location"], - "additionalProperties": false - }, - "field": { - "description": "Decode field", - "type": "object", - "oneOf": [ - { - "properties": { - "name": { - "type": "string" - }, - "$inherits": { - "type": "string", - "pattern": "^common/inst_variable_types\\.yaml#/[a-zA-Z0-9_]+", - "description": "Reference to variable metadata" - } - }, - "additionalProperties": false - }, - { - "properties": { - "name": { - "type": "string" - }, - "$child_of": { - "type": "string", - "pattern": "^common/inst_variable_types\\.yaml#/[a-zA-Z0-9_]+", - "description": "Cookie crumb of the reference to variable metadata" - }, - "location": { - "$ref": "schema_defs.json#/$defs/possibly_split_field_location" - }, - "sign_extend": { - "type": "boolean", - "default": false, - "description": "Whether or not the field should be sign extended when used" - }, - "left_shift": { - "type": "integer", - "default": 0, - "description": "Amount the field should be left shifted before use (e.g., for opcode[5:3], left_shift is 3)" - }, - "alias": { - "type": "string", - "description": "Alias of the field. Used when a field can represent multiple things, e.g., when a source register is also the destination register" - }, - "not": { - "oneOf": [ - { - "type": "integer" - }, - { - "type": "array", - "items": { - "type": "integer" - } - } - ], - "description": "Specific value(s) that are not permitted for this field." - } - }, - "required": ["name", "location"], - "additionalProperties": false - } - ] - }, - "inst_data": { - "type": "object", - "required": [ - "$schema", - "kind", - "name", - "long_name", - "description", - "definedBy", - "access", - "assembly" - ], - "additionalProperties": false, - "properties": { - "$schema": { - "type": "string", - "format": "uri-reference", - "const": "inst_schema.json#", - "description": "Path to schema, relative to /schemas" - }, - "kind": { - "type": "string", - "const": "instruction" - }, - "name": { - "type": "string", - "pattern": "^[a-z0-9.]+$", - "description": "Instruction mnemonic (must be lowercase)" - }, - "long_name": { - "type": "string", - "description": "One line description of the instruction" - }, - "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Detailed description of the instruction" - }, - "definedBy": { - "$ref": "schema_defs.json#/$defs/requires_entry", - "description": "Extension(s) that defines the instruction" - }, - - "hints": { - "type": "array", - "items": { - "type": "object", - "properties": { - "$ref": { - "type": "string", - "format": "uri-reference", - "pattern": "^inst/.+\\.yaml#.*$", - "description": "Ref to an instruction that is using a HINT codepoint(s) of this instruction" - } - }, - "required": ["$ref"], - "additionalProperties": false - }, - "description": "List of HINTs that use this instruction's codepoints" - }, - "base": { - "enum": [32, 64], - "description": "When present, instruction is only defined for RV32 or RV64 base" - }, - "access": { - "type": "object", - "required": ["s", "u", "vs", "vu"], - "properties": { - "m": { - "enum": ["always", "sometimes", "never"], - "default": "always" - }, - "s": { - "enum": ["always", "sometimes", "never"], - "default": "always" - }, - "u": { - "enum": ["always", "sometimes", "never"], - "default": "always" - }, - "vs": { - "enum": ["always", "sometimes", "never"], - "default": "always" - }, - "vu": { - "enum": ["always", "sometimes", "never"], - "default": "always" - } - } - }, - "access_detail": { - "type": "string", - "description": "Extra detail about access when at least one mode is 'sometimes'" - }, - "operation()": { - "type": "string", - "description": "Functional description of the instruction using IDL language" - }, - "sail()": { - "type": "string", - "description": "Functional description of the instruction using Sail" - }, - "cert_normative_rules": { - "$ref": "schema_defs.json#/$defs/cert_normative_rules" - }, - "cert_test_procedures": { - "$ref": "schema_defs.json#/$defs/cert_test_procedures" - }, - "assembly": { - "type": "string", - "description": "Assembly format of the instruction. Can use decode variables" - }, - "data_independent_timing": { - "type": "boolean", - "description": "Whether or not the instruction must execute with data-independent timing when the Zkt extension is supported", - "default": false - }, - "pseudoinstructions": { - "description": "Variations of this instruction that form a pseudoinstruction", - "type": "array", - "items": { - "type": "object", - "properties": { - "when": { - "type": "string", - "description": "Condition when the instruction has an alias" - }, - "to": { - "type": "string", - "description": "pseudoinstruction format" - } - }, - "additionalProperties": false - } - }, - "$source": { - "description": "Path to the source file. Used by downstream tooling; not expected to be found in handwritten files", - "type": "string" - }, - "format": { - "type": "object", - "oneOf": [ - { - "$ref": "#/$defs/fully_resolved_format" - }, - { - "$comment": "Unresolved version", - "required": ["$inherits", "opcodes"], - "properties": { - "$inherits": { - "oneOf": [ - { - "$ref": "schema_defs.json#/$defs/reference" - }, - { - "type": "array", - "items": { - "$ref": "schema_defs.json#/$defs/reference" - } - } - ] - }, - "opcodes": { - "type": "object", - "patternProperties": { - "$comment": "opcode names are lowercase with numbers", - "^[a-z][a-z0-9]*$": { - "type": "object", - "properties": { - "$comment": "location must come from inheritance", - "display_name": { - "type": "string", - "description": "field name, displayed in encoding drawings" - }, - "value": { - "$ref": "schema_defs.json#/$defs/integer" - }, - "$inherits": { - "type": "string", - "pattern": "inst_opcode/[^/]+\\.yaml#/data" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "encoding": { - "description": "Instruction encoding and decode variables", - "oneOf": [ - { - "$ref": "#/$defs/old_encoding" - }, - { - "type": "object", - "properties": { - "RV32": { - "$ref": "#/$defs/old_encoding" - }, - "RV64": { - "$ref": "#/$defs/old_encoding" - } - }, - "required": ["RV32", "RV64"], - "additionalProperties": false - } - ] - } - } - } - }, - "$ref": "#/$defs/inst_data" } diff --git a/spec/schemas/inst_var_type_schema.json b/spec/schemas/inst_var_type_schema.json index 4747679539..efb110b0ad 100644 --- a/spec/schemas/inst_var_type_schema.json +++ b/spec/schemas/inst_var_type_schema.json @@ -2,9 +2,8 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Instruction Variable Type Schema", "description": "Schema for instruction variable type definitions", - "type": "object", - "unevaluatedProperties": false, + "x-unevaluatedProperties": false, "required": ["$schema", "kind", "name", "type"], "properties": { "$schema": { @@ -20,26 +19,22 @@ "enum": ["register_reference", "immediate"] } }, - "allOf": [ - { - "if": { - "properties": { - "type": { - "const": "register_reference" - } - } + "if": { + "properties": { + "type": { + "const": "register_reference" + } + } + }, + "then": { + "properties": { + "register_file": { + "enum": ["X", "F", "V"] }, - "then": { - "properties": { - "register_file": { - "enum": ["X", "F", "V"] - }, - "access": { - "enum": ["R", "W", "RW"], - "description": "Register access type: R - Read only (src) , W - Write only (dst), RW - Read/write (srcdst)" - } - } + "access": { + "enum": ["R", "W", "RW"], + "description": "Register access type: R - Read only (src) , W - Write only (dst), RW - Read/write (srcdst)" } } - ] + } } diff --git a/spec/schemas/manual_schema.json b/spec/schemas/manual_schema.json index 0dae881382..526a1c6bfb 100644 --- a/spec/schemas/manual_schema.json +++ b/spec/schemas/manual_schema.json @@ -1,6 +1,5 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", "required": ["$schema", "kind", "name", "long_name"], "properties": { @@ -23,8 +22,7 @@ "description": "The publicly displayed manual name" }, "state": { - "$ref": "schema_defs.json#/$defs/spec_state", - "description": "State of this version" + "$ref": "schema_defs.json#/$defs/spec_state" }, "url": { "type": "string", diff --git a/spec/schemas/profile_family_schema.json b/spec/schemas/profile_family_schema.json index 6253f80df5..e9b195db0d 100644 --- a/spec/schemas/profile_family_schema.json +++ b/spec/schemas/profile_family_schema.json @@ -30,8 +30,7 @@ "description": "Asciidoc text containing the introduction prose for the family" }, "description": { - "$ref": "schema_defs.json#/$defs/spec_text", - "description": "Asciidoc text containing longer description prose for the family" + "$ref": "schema_defs.json#/$defs/spec_text" }, "naming_scheme": { "type": "string", diff --git a/spec/schemas/schema_defs.json b/spec/schemas/schema_defs.json index 3b2ed7d73b..34804f2001 100644 --- a/spec/schemas/schema_defs.json +++ b/spec/schemas/schema_defs.json @@ -1,9 +1,7 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Common patterns used by all schemas", - - "$defs": { + "x-$defs": { "$source": { "type": "string", "format": "uri-reference", @@ -34,7 +32,10 @@ }, "field_location": { "oneOf": [ - { "type": "integer", "description": "Location of a single bit" }, + { + "type": "integer", + "description": "Location of a single bit" + }, { "type": "string", "pattern": "^[0-9]+-[0-9]+$", @@ -222,7 +223,9 @@ "extension_requirement": { "description": "A requirement on an extension. Can either specify just an extension name, in which case version '>= 0' is implied, or both a name and a requirement", "oneOf": [ - { "$ref": "#/$defs/extension_name" }, + { + "$ref": "#/$defs/extension_name" + }, { "type": "object", "properties": { @@ -240,7 +243,9 @@ }, "requires_entry": { "oneOf": [ - { "$ref": "#/$defs/extension_requirement" }, + { + "$ref": "#/$defs/extension_requirement" + }, { "type": "object", "properties": {