Skip to content

Commit 419011f

Browse files
author
Derek Hower
committed
Add IDL pass to determine if variable is written; exclusive partial configs
1 parent 03dcc87 commit 419011f

File tree

3 files changed

+199
-146
lines changed

3 files changed

+199
-146
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
module Idl
4+
class AstNode
5+
def written?(symtab, varname, in_assignment: false)
6+
add_symbol(symtab) if is_a?(Declaration)
7+
8+
if children.empty?
9+
false
10+
else
11+
children.any? { |child| child.written?(symtab, varname, in_assignment:) }
12+
end
13+
end
14+
end
15+
class IdAst
16+
def written?(symtab, varname, in_assignment: false)
17+
in_assignment && (text_value == varname)
18+
end
19+
end
20+
class VariableAssignmentAst
21+
def written?(symtab, varname, in_assignment: false)
22+
lhs.written?(symtab, varname, in_assignment: true) || \
23+
rhs.written?(symtab, varname, in_assignment:)
24+
end
25+
end
26+
class AryElementAssignmentAst
27+
def written?(symtab, varname, in_assignment: false)
28+
lhs.written?(symtab, varname, in_assignment: true) || \
29+
idx.written?(symtab, varname, in_assignment:) || \
30+
rhs.written?(symtab, varname, in_assignment:)
31+
end
32+
end
33+
class AryRangeAssignmentAst
34+
def written?(symtab, varname, in_assignment: false)
35+
variable.written?(symtab, varname, in_assignment: true) || \
36+
msb.written?(symtab, varname, in_assignment:) || \
37+
lsb.written?(symtab, varname, in_assignment:) || \
38+
write_value.written?(symtab, varname, in_assignment:)
39+
end
40+
end
41+
class FieldAssignmentAst
42+
def written?(symtab, varname, in_assignment: false)
43+
field_access.written?(symtab, varname, in_assignment: true) || \
44+
write_value.written?(symtab, varname, in_assignment:)
45+
end
46+
end
47+
class MultiVariableAssignmentAst
48+
def written?(symtab, varname, in_assignment: false)
49+
variables.any? { |variable| variable.written?(symtab, varname, in_assignment: true) } || \
50+
function_call.written?(symtab, varname, in_assignment:)
51+
end
52+
end
53+
end

lib/config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def initialize(cfg_file_path, data)
9898
@mxlen.freeze
9999
end
100100

101+
def additional_extensions_allowed? = @data.key?("additional_extensions") ? @data["additional_extensions"] : true
102+
101103
def implemented_extensions = raise "implemented_extensions is only availabe for a FullConfig"
102104

103105
# @return [Array<Hash{String => String,Array<String}>]

schemas/config_schema.json

Lines changed: 144 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,163 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33

4-
"type": "object",
5-
"title": "Architecture configuration",
6-
"required": ["$schema", "kind", "type", "name", "description"],
7-
"allOf": [
8-
{
9-
"if": {
10-
"properties": {
11-
"type": { "const": "fully configured" }
12-
}
13-
},
14-
"then": {
15-
"required": ["implemented_extensions", "params"],
16-
"properties": {
17-
"params": {
18-
"type": "object"
19-
},
20-
"mandatory_extensions": {
21-
"type": "null"
22-
},
23-
"non_mandatory_extensions": {
24-
"type": "null"
25-
},
26-
"prohbited_extensions": {
27-
"type": "null"
28-
},
29-
"implemented_extensions": {
30-
"description": "Extensions implemented by this architecture",
31-
"type": "array",
32-
"items": {
33-
"type": "object",
34-
"required": ["name", "version"],
35-
"properties": {
36-
"name": {
37-
"type": "string",
38-
"pattern": "^([A-WY]|([SXZ][a-z0-9]+))$",
39-
"description": "Extension name"
40-
},
41-
"version": {
42-
"oneOf": [
43-
{
44-
"type": "string",
45-
"description": "Extension version"
46-
},
47-
{
48-
"type": "number"
49-
}
50-
]
51-
}
4+
"$defs": {
5+
"full_configuration": {
6+
"type": "object",
7+
"required": [
8+
"$schema",
9+
"kind",
10+
"type",
11+
"description",
12+
"name",
13+
"implemented_extensions",
14+
"params"
15+
],
16+
"properties": {
17+
"$schema": {
18+
"type": "string",
19+
"format": "uri-reference",
20+
"const": "config_schema.json#"
21+
},
22+
"kind": {
23+
"type": "string",
24+
"const": "architecture configuration"
25+
},
26+
"type": {
27+
"type": "string",
28+
"const": "fully configured"
29+
},
30+
"name": {
31+
"type": "string",
32+
"description": "Name of the configuration"
33+
},
34+
"description": {
35+
"type": "string",
36+
"description": "An asciidoc description of the configuration"
37+
},
38+
"params": {
39+
"type": "object"
40+
},
41+
"implemented_extensions": {
42+
"description": "Extensions implemented by this architecture",
43+
"type": "array",
44+
"items": {
45+
"type": "object",
46+
"required": ["name", "version"],
47+
"properties": {
48+
"name": {
49+
"$ref": "schema_defs.json#/$defs/extension_name",
50+
"description": "Extension name"
5251
},
53-
"additionalProperties": false
52+
"version": {
53+
"$ref": "schema_defs.json#/$defs/extension_version"
54+
}
5455
}
5556
}
5657
}
57-
}
58-
},
59-
{
60-
"if": {
61-
"properties": {
62-
"type": { "const": "partially configured" }
63-
}
6458
},
65-
"then": {
66-
"anyOf": [
67-
{
68-
"required": ["mandatory_extensions"]
69-
},
70-
{
71-
"required": ["params"]
72-
}
73-
],
74-
"properties": {
75-
"params": {
76-
"type": "object"
77-
},
78-
"mandatory_extensions": {
79-
"description": "Extensions mandatory in this architecture",
80-
"type": "array",
81-
"items": {
82-
"$ref": "schema_defs.json#/$defs/extension_requirement"
83-
},
84-
"default": {
85-
"const": []
86-
}
87-
},
88-
"non_mandatory_extensions": {
89-
"description": "Extensions that are not mandatory but are still _special_ in this architecture. This could mean different things depending on the context: for certificates or generated IP, this would correspond to _optional supported_, and extensions not in non_mandatory are not possible. For profiles, this corresponds to some type of _profile optional_, but extensions in non_mandatory are still possible.",
90-
"type": "array",
91-
"items": {
92-
"$ref": "schema_defs.json#/$defs/extension_requirement"
93-
},
94-
"default": {
95-
"const": []
96-
}
97-
},
98-
"prohibited_extensions": {
99-
"description": "Extensions explicitly prohibited in this architecture. Does *not* need to include extensions that are excluded because of a conflict-by-definition with a mandatory extension, as those will be calculated automatically",
100-
"type": "array",
101-
"items": {
102-
"$ref": "schema_defs.json#/$defs/extension_requirement"
103-
},
104-
"default": {
105-
"const": []
106-
}
107-
},
108-
"implemented_extensions": {
109-
"type": "null"
110-
}
111-
}
112-
}
59+
"additionalProperties": false
11360
},
114-
{
115-
"if": {
116-
"properties": {
117-
"type": { "const": "unconfigured" }
118-
}
119-
},
120-
"then": {
61+
"partial_configuration": {
62+
"type": "object",
63+
"required": [
64+
"$schema",
65+
"kind",
66+
"type",
67+
"name",
68+
"description",
69+
"mandatory_extensions"
70+
],
71+
"properties": {
72+
"$schema": {
73+
"type": "string",
74+
"format": "uri-reference",
75+
"const": "config_schema.json#"
76+
},
77+
"kind": {
78+
"type": "string",
79+
"const": "architecture configuration"
80+
},
81+
"type": {
82+
"type": "string",
83+
"const": "partially configured"
84+
},
85+
"name": {
86+
"type": "string",
87+
"description": "Name of the configuration"
88+
},
89+
"description": {
90+
"type": "string",
91+
"description": "An asciidoc description of the configuration"
92+
},
93+
"params": {
94+
"type": "object"
95+
},
12196
"mandatory_extensions": {
122-
"type": "null"
97+
"description": "Extensions mandatory in this architecture",
98+
"type": "array",
99+
"items": {
100+
"$ref": "schema_defs.json#/$defs/extension_requirement"
101+
}
123102
},
124103
"non_mandatory_extensions": {
125-
"type": "null"
104+
"description": "Extensions that are not mandatory but are still _special_ in this architecture. This could mean different things depending on the context: for certificates or generated IP, this would correspond to _optional supported_, and extensions not in non_mandatory are not possible. For profiles, this corresponds to some type of _profile optional_, but extensions in non_mandatory are still possible.",
105+
"type": "array",
106+
"items": {
107+
"$ref": "schema_defs.json#/$defs/extension_requirement"
108+
}
126109
},
127-
"prohbited_extensions": {
128-
"type": "null"
110+
"prohibited_extensions": {
111+
"description": "Extensions explicitly prohibited in this architecture. Does *not* need to include extensions that are excluded because of a conflict-by-definition with a mandatory extension, as those will be calculated automatically",
112+
"type": "array",
113+
"items": {
114+
"$ref": "schema_defs.json#/$defs/extension_requirement"
115+
}
129116
},
130-
"params": {
117+
"implemented_extensions": {
131118
"type": "null"
119+
},
120+
"additional_extensions": {
121+
"type": "boolean",
122+
"default": true,
123+
"description": "Whether or not a compliant instance of this partial config can have more extensions than those listed in mandatory_extensions/non_mandatory_extensions"
132124
}
133-
}
134-
}
135-
],
136-
"properties": {
137-
"type": {
138-
"type": "string",
139-
"description": "Type of the arch",
140-
"enum": ["unconfigured", "partially configured", "fully configured"]
141-
},
142-
"$schema": {
143-
"type": "string",
144-
"format": "uri-reference",
145-
"const": "config_schema.json#"
146-
},
147-
"kind": {
148-
"type": "string",
149-
"const": "architecture configuration"
150-
},
151-
"name": {
152-
"type": "string"
153-
},
154-
"description": {
155-
"type": "string",
156-
"description": "An asciidoc description of the configuration"
125+
},
126+
"additionalProperties": false
157127
},
158-
"params": true,
159-
"mandatory_extensions": true,
160-
"non_mandatory_extensions": true,
161-
"prohibited_extensions": true,
162-
"implemented_extensions": true
128+
"unconfiguration": {
129+
"type": "object",
130+
"required": ["$schema", "kind", "type", "name", "description"],
131+
"properties": {
132+
"$schema": {
133+
"type": "string",
134+
"format": "uri-reference",
135+
"const": "config_schema.json#"
136+
},
137+
"kind": {
138+
"type": "string",
139+
"const": "architecture configuration"
140+
},
141+
"type": {
142+
"type": "string",
143+
"const": "unconfigured"
144+
},
145+
"name": {
146+
"type": "string",
147+
"description": "Name of the configuration"
148+
},
149+
"description": {
150+
"type": "string",
151+
"description": "An asciidoc description of the configuration"
152+
}
153+
},
154+
"additionalProperties": false
155+
}
163156
},
164-
"additionalProperties": false
157+
158+
"oneOf": [
159+
{ "$ref": "#/$defs/full_configuration" },
160+
{ "$ref": "#/$defs/partial_configuration" },
161+
{ "$ref": "#/$defs/unconfiguration" }
162+
]
165163
}

0 commit comments

Comments
 (0)