| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-20 15:43:38 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-20 15:43:38 +0200 |
| commit | 1ef39e828479f0d82753f3912b7c5d85e49d708c (patch) | |
| tree | 7d7e808ccb7911921560e97a9ef2b068725fda30 /ast-to-instr/src/VHDLSSCNode.java | |
| parent | b5c3459a9763107abcbbcd7fc1a42eee3a887c52 (diff) | |
Working on the "internal_process.py" translation.
I think I've found some not-too-ugly solution.
Diffstat (limited to 'ast-to-instr/src/VHDLSSCNode.java')
| -rw-r--r-- | ast-to-instr/src/VHDLSSCNode.java | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/ast-to-instr/src/VHDLSSCNode.java b/ast-to-instr/src/VHDLSSCNode.java new file mode 100644 index 0000000..95ddfbb --- /dev/null +++ b/ast-to-instr/src/VHDLSSCNode.java @@ -0,0 +1,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 + ); + } + } +} |


