1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import java.util.ArrayList;
import java.util.Collection;
/* Sequential Statement Chain Node */
/* Not actually a node in the resulting model, though. */
public class VHDLSSCNode extends VHDLNode
{
private static final XPathExpression XPE_FIND_SUB_NODES;
private final IDs prev_node;
static
{
XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el");
}
public VHDLSSCNode
(
final IDs parent_id,
final Node xml_node,
final IDs prev_node, /* can't simply forward ref to SSC */
final IDs next_node,
final int depth,
final String[] attributes
)
{
super
(
parent_id,
xml_node,
next_node,
depth,
attributes
);
this.prev_node = prev_node;
}
@Override
public Collection<ParsableXML> parse ()
throws XPathExpressionException
{
final Collection<ParsableXML> result;
final NodeList sub_nodes;
final int intermediary_nodes_count;
int i;
result = new ArrayList<ParsableXML>();
sub_nodes =
(NodeList) XPE_FIND_SUB_NODES.evaluate
(
xml_node,
XPathConstants.NODESET
);
intermediary_nodes_count = (sub_nodes.getLength() - 1);
for (i = 0; i < intermediary_nodes_count; ++i)
{
final IDs next_node;
next_node =
IDs.get_id_from_xml_id
(
XMLManager.get_attribute
(
sub_nodes.item(i + 1),
"id"
),
"node"
);
result.add(get_vhdl_node(sub_nodes.item(i), next_node, i));
}
result.add(get_vhdl_node(sub_nodes.item(i), next_node, i));
handle_backward_connection(sub_nodes.item(0));
return result;
}
private ParsableXML get_vhdl_node
(
final Node node,
final IDs next_node,
final int i
)
{
final String node_kind;
final String[] attributes;
node_kind = XMLManager.get_attribute(node, "kind");
if (i == 0)
{
/* Attributes are only inherited by the first node */
attributes = this.attributes;
}
else
{
attributes = new String[0];
}
if (node_kind.equals("if_statement"))
{
return new VHDLISNode(parent_id, node, next_node, depth, attributes);
}
else if (node_kind.equals("simple_signal_assignment_statement"))
{
return new VHDLSSASNode(parent_id, node, next_node, depth, attributes);
}
else if (node_kind.equals("case_statement"))
{
return new VHDLCSNode(parent_id, node, next_node, depth, attributes);
}
System.err.println
(
"[E] Unimplemented instruction kind \""
+ node_kind
+ "\" found in Sequential Statement Chain."
);
System.exit(-1);
return null;
}
private void handle_backward_connection
(
final Node first_node
)
{
final IDs first_node_id;
first_node_id =
IDs.get_id_from_xml_id
(
XMLManager.get_attribute
(
first_node,
"id"
),
"node"
);
if (prev_node == null)
{
/* First node of the process */
Predicates.add_entry
(
"is_start_node",
first_node_id,
parent_id
);
}
else
{
/* First node of the process */
Predicates.add_entry
(
"connect_to",
prev_node,
first_node_id
);
}
}
}
|