Skip to content

Commit 9d60670

Browse files
Forgot to stage
1 parent a1cfc49 commit 9d60670

File tree

6 files changed

+168
-49
lines changed

6 files changed

+168
-49
lines changed

arch/crd/MockCRD-1.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ MockCRD-1:
2828
parameters:
2929
MOCK_ENUM_2_INTS: {}
3030
MOCK_ENUM_2_STRINGS: {}
31-
MOCK_BOOL: {}
32-
MOCK_64_BIT_INT: {}
31+
MOCK_BOOL_1: {}
32+
MOCK_BOOL_2:
33+
schema:
34+
const: true
35+
MOCK_1_BIT_INT: {}
36+
MOCK_2_BIT_INT: {}
3337
MOCK_25_BIT_INT: {}
34-
MOCK_INT_RANGE: {}
35-
MOCK_INT_ENUM_ARRAY: {}
36-
MOCK_BOOL_ARRAY_OF_8_FIRST_2_FALSE: {}
37-
MOCK_STRING_ENUM_ARRAY:
38+
MOCK_64_BIT_INT: {}
39+
MOCK_INT_RANGE_0_TO_127: {}
40+
MOCK_INT_RANGE_0_TO_128: {}
41+
MOCK_INT_RANGE_1_TO_128: {}
42+
MOCK_ARRAY_INT_ENUM: {}
43+
MOCK_ARRAY_BOOL_ARRAY_OF_8_FIRST_2_FALSE: {}
44+
MOCK_ARRAY_STRING_ENUM:
3845
schema:
3946
contains: { const : DEF }
4047
- name: I

arch/ext/MockExt.yaml

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MockExt:
66
description: This is just for testing
77
versions:
88
- version: "1.0.0"
9-
state: ratified
9+
state: development
1010
params:
1111
MOCK_ENUM_2_INTS:
1212
description: foo
@@ -17,8 +17,12 @@ MockExt:
1717
description: foo
1818
schema:
1919
type: string
20-
enum: ["high", "low"]
21-
MOCK_BOOL:
20+
enum: ["low", "high"]
21+
MOCK_BOOL_1:
22+
description: foo
23+
schema:
24+
type: boolean
25+
MOCK_BOOL_2:
2226
description: foo
2327
schema:
2428
type: boolean
@@ -28,19 +32,49 @@ MockExt:
2832
type: integer
2933
minimum: 0
3034
maximum: 0xffffffffffffffff
35+
MOCK_1_BIT_INT:
36+
description: foo
37+
schema:
38+
type: integer
39+
minimum: 0
40+
maximum: 1
41+
MOCK_2_BIT_INT:
42+
description: foo
43+
schema:
44+
type: integer
45+
minimum: 0
46+
maximum: 3
3147
MOCK_25_BIT_INT:
3248
description: foo
3349
schema:
3450
type: integer
3551
minimum: 0
3652
maximum: 33554431
37-
MOCK_INT_RANGE:
53+
MOCK_INT_RANGE_0_TO_2:
54+
description: foo
55+
schema:
56+
type: integer
57+
minimum: 0
58+
maximum: 2
59+
MOCK_INT_RANGE_0_TO_127:
3860
description: foo
3961
schema:
4062
type: integer
4163
minimum: 0
4264
maximum: 127
43-
MOCK_INT_ENUM_ARRAY:
65+
MOCK_INT_RANGE_0_TO_128:
66+
description: foo
67+
schema:
68+
type: integer
69+
minimum: 0
70+
maximum: 128
71+
MOCK_INT_RANGE_1_TO_128:
72+
description: foo
73+
schema:
74+
type: integer
75+
minimum: 1
76+
maximum: 128
77+
MOCK_ARRAY_INT_ENUM:
4478
description: foo
4579
schema:
4680
type: array
@@ -50,14 +84,30 @@ MockExt:
5084
minItems: 1
5185
maxItems: 2
5286
uniqueItems: true
53-
MOCK_STRING_ENUM_ARRAY:
87+
MOCK_ARRAY_MIN_ONLY:
88+
description: foo
89+
schema:
90+
type: array
91+
items:
92+
type: integer
93+
enum: [0, 1]
94+
minItems: 3
95+
MOCK_ARRAY_MAX_ONLY:
96+
description: foo
97+
schema:
98+
type: array
99+
items:
100+
type: integer
101+
enum: [0, 1]
102+
maxItems: 10
103+
MOCK_ARRAY_STRING_ENUM:
54104
description: foo
55105
schema:
56106
type: array
57107
items:
58108
type: string
59109
enum: [ABC, DEF, GHI]
60-
MOCK_BOOL_ARRAY_OF_8_FIRST_2_FALSE:
110+
MOCK_ARRAY_BOOL_ARRAY_OF_8_FIRST_2_FALSE:
61111
description: foo
62112
schema:
63113
type: array

arch/ext/Sm.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,16 @@ Sm:
243243
244244
[separator="!"]
245245
!===
246-
! high ! Misaligned load/store/AMO exceptions are always higher priority than load/store/AMO page-fault and access-fault exceptions.
247246
! low ! Misaligned load/store/AMO exceptions are always lower priority than load/store/AMO page-fault and access-fault exceptions.
247+
! high ! Misaligned load/store/AMO exceptions are always higher priority than load/store/AMO page-fault and access-fault exceptions.
248248
!===
249249
250250
MISALIGNED_LDST_EXCEPTION_PRIORITY cannot be "high" when MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE
251251
is non-zero, since the atomicity of an access cannot be determined in that case until after
252252
address translation.
253253
schema:
254254
type: string
255-
enum: ["high", "low"]
255+
enum: ["low", "high"]
256256
extra_validation: |
257257
assert (MISALIGNED_LDST_EXCEPTION_PRIORITY == "low") if MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE.positive?
258258
MAX_MISALIGNED_ATOMICITY_GRANULE_SIZE:
@@ -407,7 +407,7 @@ Sm:
407407
Must be greater than or equal to _max_(`PHYS_ADDR_WIDTH`, `VA_SIZE`)
408408
schema:
409409
type: integer
410-
maximum: 0xffffffffffffffff
410+
maximum: 64
411411
CONFIG_PTR_ADDRESS:
412412
description: |
413413
Physical address of the unified discovery configuration data structure.

lib/arch_obj_models/crd.rb

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,32 @@ def in_scope_extensions
151151
end
152152

153153
# @return [Array<ExtensionRequirements>] - # Extensions with their CRD information.
154-
# XXX Good example of why I filed issue 75
155-
def in_scope_ext_reqs
156-
return @in_scope_ext_reqs unless @in_scope_ext_reqs.nil?
157-
158-
@in_scope_ext_reqs = []
154+
# If desired_status is provided, only returns extensions with that status.
155+
def in_scope_ext_reqs(desired_status = nil)
156+
in_scope_ext_reqs = []
159157
@data["extensions"]&.each do |ext_crd|
160-
status = ext_crd["status"]
161-
raise "Missing extension status for extension #{ext_crd["name"]}" if status.nil?
158+
actual_status = ext_crd["status"]
159+
raise "Missing extension status for extension #{ext_crd["name"]}" if actual_status.nil?
162160

163-
if (status != "mandatory") && (status != "optional")
164-
raise "Unknown extension status of #{status} for extension #{ext_crd["name"]}"
161+
if (actual_status != "mandatory") && (actual_status != "optional")
162+
raise "Unknown extension status of #{actual_status} for extension #{ext_crd["name"]}"
165163
end
166164

167-
@in_scope_ext_reqs <<
168-
ExtensionRequirement.new(ext_crd["name"], ext_crd["version"], status: status,
169-
note: ext_crd["note"], req_id: "REQ-EXT-" + ext_crd["name"])
165+
add = false
166+
167+
if desired_status.nil?
168+
add = true
169+
elsif desired_status == actual_status
170+
add = true
171+
end
172+
173+
if add
174+
in_scope_ext_reqs <<
175+
ExtensionRequirement.new(ext_crd["name"], ext_crd["version"], status: actual_status,
176+
note: ext_crd["note"], req_id: "REQ-EXT-" + ext_crd["name"])
177+
end
170178
end
171-
@in_scope_ext_reqs
179+
in_scope_ext_reqs
172180
end
173181

174182
###################################
@@ -185,32 +193,31 @@ def initialize(param_db, schema_hash, note)
185193
raise ArgumentError, "Expecting schema_hash to be a hash" unless schema_hash.is_a?(Hash)
186194

187195
@param_db = param_db
188-
@schema_constraint = Schema.new(schema_hash)
196+
@schema_crd = Schema.new(schema_hash)
189197
@note = note
190198
end
191199

192200
def single_value?
193-
@schema_constraint.single_value?
201+
@schema_crd.single_value?
194202
end
195203

196204
def name
197205
@param_db.name
198206
end
199207

200-
def value
201-
raise "Parameter schema_constraint for #{@param_db.name} is not a single value" unless single_value?
202-
203-
@schema_constraint.value
208+
def idl_type
209+
@param_db.type
204210
end
205211

206-
# Pretty convert just CRD's parameter constraint to a string.
207-
def schema_constraint_pretty
208-
@schema_constraint.pretty
212+
def value
213+
raise "Parameter schema_crd for #{name} is not a single value" unless single_value?
214+
215+
@schema_crd.value
209216
end
210217

211-
# Pretty convert CRD's parameter constraint merged with extension schema to a string.
212-
def schema_merge_pretty
213-
Schema.new(@param_db.schema).merge!(@schema_constraint).pretty
218+
# Pretty convert CRD's parameter constraint merged into extension schema to a string.
219+
def schema_pretty_crd_merged_with_param_db
220+
Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
214221
end
215222

216223
# sorts by name

lib/arch_obj_models/extension.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative "obj"
4+
require_relative "schema"
45

56
# A parameter (AKA option, AKA implementation-defined value) supported by an extension
67
class ExtensionParameter
@@ -26,6 +27,11 @@ class ExtensionParameter
2627
# @returns [Idl::Type] Type of the parameter
2728
attr_reader :type
2829

30+
# Pretty convert extension schema to a string.
31+
def schema_type
32+
Schema.new(@schema).to_pretty_s
33+
end
34+
2935
def initialize(name, desc, schema, extra_validation, exts)
3036
@name = name
3137
@desc = desc

lib/arch_obj_models/schema.rb

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@ def initialize(schema_hash)
77
@schema_hash = schema_hash
88
end
99

10-
def pretty(schema_hash = @schema_hash)
10+
def to_pretty_s(schema_hash = @schema_hash)
1111
raise ArgumentError, "Expecting hash" unless schema_hash.is_a?(Hash)
1212
raise ArgumentError, "Expecting non-empty hash" if schema_hash.empty?
1313

1414
if schema_hash.key?("const")
1515
"#{schema_hash["const"]}"
1616
elsif schema_hash.key?("enum")
17-
"One of: [#{schema_hash["enum"].join(', ')}]"
17+
"[#{schema_hash["enum"].join(', ')}]"
1818
elsif schema_hash.key?("type")
1919
case schema_hash["type"]
2020
when "integer"
2121
min = schema_hash["minimum"]
2222
max = schema_hash["maximum"]
2323
if min && max
24-
"#{min} to #{max}"
24+
sz = num_bits(min, max)
25+
(sz > 0) ? "#{sz}-bit integer" : "#{min} to #{max}"
2526
elsif min
2627
"&#8805; #{min}"
2728
elsif max
2829
"&#8804; #{max}"
2930
else
30-
"any integer"
31+
"integer"
3132
end
3233
when "string"
3334
format = schema_hash["format"]
@@ -42,14 +43,50 @@ def pretty(schema_hash = @schema_hash)
4243
when "boolean"
4344
"boolean"
4445
when "array"
45-
"TODO: array"
46+
items = schema_hash["items"]
47+
min_items = schema_hash["minItems"]
48+
max_items = schema_hash["maxItems"]
49+
size_str = if min_items && max_items
50+
if min_items == max_items
51+
"#{min_items}-element "
52+
else
53+
"#{min_items}-element to #{max_items}-element "
54+
end
55+
elsif min_items
56+
"at least #{min_items}-element "
57+
elsif max_items
58+
"at most #{max_items}-element "
59+
else
60+
""
61+
end
62+
63+
if items.nil?
64+
size_str + "array"
65+
else
66+
if items.is_a?(Hash)
67+
"#{size_str}array of #{to_pretty_s(items)}"
68+
elsif items.is_a?(Array)
69+
str = size_str + "array where: +\n"
70+
items.each_with_index do |item,index|
71+
str = str + "&nbsp;&nbsp;[#{index}] is #{to_pretty_s(item)} +\n"
72+
end
73+
additional_items = schema_hash["additionalItems"]
74+
if additional_items
75+
str = str + "additional items are: +\n&nbsp;&nbsp;" +
76+
to_pretty_s(additional_items)
77+
end
78+
str
79+
else
80+
raise "to_pretty_s unknown array items #{items} in #{schema_hash}"
81+
end
82+
end
4683
else
47-
raise "TODO: Pretty schema unknown type #{schema_hash["type"]} in #{schema_hash}"
84+
raise "to_pretty_s unknown type #{schema_hash["type"]} in #{schema_hash}"
4885
end
4986
elsif schema_hash.key?("contains")
50-
"Contains : [#{pretty(schema_hash["contains"])}]"
87+
"Contains : [#{to_pretty_s(schema_hash["contains"])}]"
5188
else
52-
raise "TODO: Pretty schema for #{schema_hash}"
89+
raise "TODO: to_pretty_s schema for #{schema_hash}"
5390
end
5491
end
5592

@@ -72,5 +109,17 @@ def value
72109

73110
@schema_hash["const"]
74111
end
112+
113+
def is_power_of_two?(num)
114+
return false if num < 1
115+
return (num & (num-1)) == 0
116+
end
117+
118+
# If min to max range represents an unsigned number of bits, return the number of bits.
119+
# Otherwise return 0
120+
def num_bits(min, max)
121+
return 0 unless min == 0
122+
is_power_of_two?(max+1) ? max.bit_length : 0
123+
end
75124
end
76125

0 commit comments

Comments
 (0)