Skip to content

Commit efe87b3

Browse files
Changed $copy to be a key and only work with specific strings (right now just the description).
1 parent b0f163f commit efe87b3

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

arch/csr/mie.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ address: 0x304
88
priv_mode: M
99
length: MXLEN
1010
definedBy: Sm
11-
description: "$copy: mip.yaml#/description"
11+
description:
12+
$copy: "mip.yaml#/description"
1213
fields:
1314
SSIE:
1415
location: 1

arch/csr/mip.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ name: mip
66
long_name: Machine Interrupt Pending
77
address: 0x344
88
priv_mode: M
9+
10+
# Description is shared with mie CSR (it copies it from here).
911
description: |
10-
The `mip` register is an MXLEN-bit read/write register containing
11-
information on pending interrupts, while `mie` is the corresponding
12-
MXLEN-bit read/write register containing interrupt enable bits.
13-
Interrupt cause number _i_ (as reported in CSR `mcause`)
14-
corresponds with bit _i_ in both `mip` and
15-
`mie`. Bits 15:0 are allocated to standard interrupt causes only, while
12+
The `mie` and `mip` CSRs are MXLEN-bit read/write registers used when
13+
the CLINT or PLIC interrupt controllers are present.
14+
Note that the CLINT refers to an interrupt controller
15+
used by some RISC-V implementations but isn't a ratified
16+
RISC-V International standard.
17+
18+
The `mip` CSR contains information on pending interrupts, while `mie` is the corresponding
19+
CSR containing interrupt enable bits.
20+
Interrupt cause number _i_ (as reported in the `mcause` CSR)
21+
corresponds to bit _i_ in both `mip` and `mie`.
22+
Bits 15:0 are allocated to standard interrupt causes only, while
1623
bits 16 and above are designated for platform use.
1724
1825
NOTE: Interrupts designated for platform use may be designated for custom use

lib/test/test_yaml_loader.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ def test_copy_in_the_same_document
346346
347347
obj1:
348348
target10: abc
349-
target11: "$copy: #/$defs/target1"
349+
target11:
350+
$copy: "#/$defs/target1"
350351
target12: def
351-
target13: "$copy: #/$defs/target3"
352+
target13:
353+
$copy: "#/$defs/target3"
352354
353355
YAML
354356

@@ -382,9 +384,11 @@ def test_copy_in_the_different_document
382384
yaml2 = <<~YAML
383385
obj1:
384386
target10: abc
385-
target11: "$copy: #{f1_path.basename}#/$defs/target1"
387+
target11:
388+
$copy: "#{f1_path.basename}#/$defs/target1"
386389
target12: def
387-
target13: "$copy: #{f1_path.basename}#/$defs/target3"
390+
target13:
391+
$copy: "#{f1_path.basename}#/$defs/target3"
388392
YAML
389393

390394
f2 = Tempfile.new("yml")

lib/yaml_loader.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,27 @@ def self.expand(filename, obj, yaml_opts = {})
136136
end
137137

138138
final_obj
139+
elsif obj.keys.include?("$copy")
140+
self.get_copy_target_obj(filename, obj["$copy"], yaml_opts)
139141
else
140142
# Go through each hash entry.
141143
obj.each do |key, value|
142-
obj[key] =
143-
if value.is_a?(String) && value.start_with?("$copy:")
144-
copy_target = value.delete_prefix("$copy:").lstrip
145-
self.get_copy_target_obj(filename, copy_target, yaml_opts)
146-
else
147-
expand(filename, value, yaml_opts)
148-
end
144+
obj[key] = expand(filename, value, yaml_opts)
149145
end
150146
obj
151147
end
152148

153-
obj_keys = new_obj.keys
154-
if obj_keys.include? "$remove"
155-
remove_keys = obj["$remove"].is_a?(Array) ? obj["$remove"] : [obj["$remove"]]
156-
remove_keys.each do |key|
157-
new_obj.delete(key)
149+
if new_obj.is_a?(Hash)
150+
obj_keys = new_obj.keys
151+
if obj_keys.include? "$remove"
152+
remove_keys = obj["$remove"].is_a?(Array) ? obj["$remove"] : [obj["$remove"]]
153+
remove_keys.each do |key|
154+
new_obj.delete(key)
155+
end
158156
end
157+
new_obj.delete("$remove")
159158
end
160-
new_obj.delete("$remove")
159+
161160
new_obj
162161
end
163162

schemas/csr_schema.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,23 @@
193193
"description": "Descriptive name for the CSR"
194194
},
195195
"description": {
196-
"type": "string",
197-
"description": "A full Asciidoc description of the CSR, intended to be used as documentation."
196+
"oneOf": [
197+
{
198+
"type": "string",
199+
"description": "A full Asciidoc description of the CSR, intended to be used as documentation."
200+
},
201+
{
202+
"type": "object",
203+
"description": "A full Asciidoc description of the CSR, intended to be used as documentation.",
204+
"properties": {
205+
"$copy" : {
206+
"type": "string",
207+
"format": "uri-reference"
208+
}
209+
},
210+
"additionalProperties": false
211+
}
212+
]
198213
},
199214
"definedBy": {
200215
"$ref": "schema_defs.json#/$defs/requires_entry",

0 commit comments

Comments
 (0)