| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | ast-to-instr/src/IDs.java | 8 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLCSNode.java | 47 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLGeneric.java | 8 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLISNode.java | 47 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLNode.java | 25 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLPort.java | 8 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLProcess.java | 131 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLSSASNode.java | 47 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLSSCNode.java | 176 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLSignal.java | 8 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLWNode.java | 47 | ||||
| -rw-r--r-- | ast-to-instr/src/XMLManager.java | 2 |
12 files changed, 519 insertions, 35 deletions
diff --git a/ast-to-instr/src/IDs.java b/ast-to-instr/src/IDs.java index e3b9db4..00c0f49 100644 --- a/ast-to-instr/src/IDs.java +++ b/ast-to-instr/src/IDs.java @@ -35,6 +35,12 @@ public class IDs FROM_XML.put(xml_id, result); } + else if ((result.type == null) && (type != null)) + { + /* This allows us to get an ID from a simple reference. */ + /* TODO: Don't forget to report any (type == null) at the end. */ + result.type = type; + } return result; } @@ -54,8 +60,8 @@ public class IDs } /** Non-Static *************************************************************/ - private final String type; private final int value; + private String type; private IDs (final String type) { diff --git a/ast-to-instr/src/VHDLCSNode.java b/ast-to-instr/src/VHDLCSNode.java new file mode 100644 index 0000000..de11c7b --- /dev/null +++ b/ast-to-instr/src/VHDLCSNode.java @@ -0,0 +1,47 @@ +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; + +/* If Statement Node */ +public class VHDLISNode extends VHDLNode +{ + private static final XPathExpression XPE_FIND_SUB_NODES; + + static + { + XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el"); + } + + public VHDLISNode + ( + final IDs parent_id, + final Node xml_node, + final IDs next_node, + final int depth, + final String[] attributes + ) + { + super + ( + parent_id, + xml_node, + next_node, + depth, + attributes + ); + } + + @Override + public Collection<ParsableXML> parse () + throws XPathExpressionException + { + /* TODO */ + return null; + } +} diff --git a/ast-to-instr/src/VHDLGeneric.java b/ast-to-instr/src/VHDLGeneric.java index 7184f61..e080841 100644 --- a/ast-to-instr/src/VHDLGeneric.java +++ b/ast-to-instr/src/VHDLGeneric.java @@ -10,14 +10,6 @@ import java.util.Collection; public class VHDLGeneric extends ParsableXML { - private static final XPathExpression GET_ENTITIES; - - static - { - /* TODO */ - GET_ENTITIES = null; - } - public VHDLGeneric ( final IDs parent_id, diff --git a/ast-to-instr/src/VHDLISNode.java b/ast-to-instr/src/VHDLISNode.java new file mode 100644 index 0000000..de11c7b --- /dev/null +++ b/ast-to-instr/src/VHDLISNode.java @@ -0,0 +1,47 @@ +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; + +/* If Statement Node */ +public class VHDLISNode extends VHDLNode +{ + private static final XPathExpression XPE_FIND_SUB_NODES; + + static + { + XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el"); + } + + public VHDLISNode + ( + final IDs parent_id, + final Node xml_node, + final IDs next_node, + final int depth, + final String[] attributes + ) + { + super + ( + parent_id, + xml_node, + next_node, + depth, + attributes + ); + } + + @Override + public Collection<ParsableXML> parse () + throws XPathExpressionException + { + /* TODO */ + return null; + } +} diff --git a/ast-to-instr/src/VHDLNode.java b/ast-to-instr/src/VHDLNode.java new file mode 100644 index 0000000..1774672 --- /dev/null +++ b/ast-to-instr/src/VHDLNode.java @@ -0,0 +1,25 @@ +import org.w3c.dom.Node; + +public abstract class VHDLNode extends ParsableXML +{ + protected final IDs next_node; + protected final int depth; + protected final String[] attributes; + + public VHDLNode + ( + final IDs parent_id, + final Node xml_node, + final IDs next_node, + final int depth, + final String[] attributes + ) + { + super(parent_id, xml_node); + + this.next_node = next_node; + this.depth = depth; + this.attributes = attributes; + } + +} diff --git a/ast-to-instr/src/VHDLPort.java b/ast-to-instr/src/VHDLPort.java index 062159c..f343126 100644 --- a/ast-to-instr/src/VHDLPort.java +++ b/ast-to-instr/src/VHDLPort.java @@ -10,14 +10,6 @@ import java.util.Collection; public class VHDLPort extends ParsableXML { - private static final XPathExpression GET_ENTITIES; - - static - { - /* TODO */ - GET_ENTITIES = null; - } - public VHDLPort ( final IDs parent_id, diff --git a/ast-to-instr/src/VHDLProcess.java b/ast-to-instr/src/VHDLProcess.java index a51816c..5d49b40 100644 --- a/ast-to-instr/src/VHDLProcess.java +++ b/ast-to-instr/src/VHDLProcess.java @@ -10,12 +10,29 @@ import java.util.Collection; public class VHDLProcess extends ParsableXML { - private static final XPathExpression GET_ENTITIES; + private static final XPathExpression XPE_FIND_SL_ELEMENTS; + private static final XPathExpression XPE_FIND_NE_IN_PROCESS; + private static final XPathExpression XPE_FIND_START_NODE; static { - /* TODO */ - GET_ENTITIES = null; + XPE_FIND_SL_ELEMENTS = + XMLManager.compile_or_die + ( + "(./sensitivity_list/el/named_entity | ./sensitivity_list/el[@ref])" + ); + + XPE_FIND_NE_IN_PROCESS = + XMLManager.compile_or_die + ( + ".//*[@kind=\"simple_name\"]/named_entity" + ); + + XPE_FIND_START_NODE = + XMLManager.compile_or_die + ( + "./sequential_statement_chain" + ); } public VHDLProcess @@ -67,7 +84,7 @@ public class VHDLProcess extends ParsableXML handle_predicate_is_accessed_by(local_id); /** Children ************************************************************/ - result.addAll(handle_child_nodes(local_id)); + result.addAll(handle_child_node(local_id)); return result; } @@ -357,27 +374,123 @@ public class VHDLProcess extends ParsableXML ( final IDs local_id ) + throws XPathExpressionException { - /* TODO */ + final NodeList items; + final int items_count; + + items = + (NodeList) XPE_FIND_SL_ELEMENTS.evaluate + ( + xml_node, + XPathConstants.NODESET + ); + + items_count = items.getLength(); + + for (int i = 0; i < items_count; ++i) + { + Predicates.add_entry + ( + "is_in_sensitivity_list", + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id + ( + XMLManager.get_attribute + ( + items.item(i), + "ref" + ), + null + ) + ), + local_id + ); + } } private void handle_predicate_is_accessed_by ( final IDs local_id ) + throws XPathExpressionException { - /* TODO */ + final NodeList items; + final int items_count; + + items = + (NodeList) XPE_FIND_SL_ELEMENTS.evaluate + ( + xml_node, + XPathConstants.NODESET + ); + + items_count = items.getLength(); + + for (int i = 0; i < items_count; ++i) + { + final String xml_id; + + xml_id = + XMLManager.get_attribute + ( + items.item(i), + "ref" + ); + + if (!Main.node_is_function_or_literal(ref)) + { + Predicates.add_entry + ( + "is_accessed_by", + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id + ( + xml_id, + null + ) + ), + local_id + ); + } + } } /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection<ParsableXML> handle_child_nodes + private Collection<ParsableXML> handle_child_node ( final IDs local_id ) { - /* TODO */ - return null; + final Node start_node; + final Collection<ParsableXML> result; + + start_node = + (Node) XPE_FIND_START_NODE.evaluate + ( + xml_node, + XPathConstants.NODE + ); + + result = new ArrayList<ParsableXML>(); + + result.add + ( + new VHDLSSCNode + ( + local_id, + start_node, + null, /* There is nothing before this sequence. */ + null, /* There is nothing after this sequence. */ + 0, /* Depth starts at zero. */ + new String[0] /* No attributes. */ + ) + ); + + return result; } } diff --git a/ast-to-instr/src/VHDLSSASNode.java b/ast-to-instr/src/VHDLSSASNode.java new file mode 100644 index 0000000..de11c7b --- /dev/null +++ b/ast-to-instr/src/VHDLSSASNode.java @@ -0,0 +1,47 @@ +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; + +/* If Statement Node */ +public class VHDLISNode extends VHDLNode +{ + private static final XPathExpression XPE_FIND_SUB_NODES; + + static + { + XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el"); + } + + public VHDLISNode + ( + final IDs parent_id, + final Node xml_node, + final IDs next_node, + final int depth, + final String[] attributes + ) + { + super + ( + parent_id, + xml_node, + next_node, + depth, + attributes + ); + } + + @Override + public Collection<ParsableXML> parse () + throws XPathExpressionException + { + /* TODO */ + return null; + } +} 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 + ); + } + } +} diff --git a/ast-to-instr/src/VHDLSignal.java b/ast-to-instr/src/VHDLSignal.java index 1ea12d6..72a95ee 100644 --- a/ast-to-instr/src/VHDLSignal.java +++ b/ast-to-instr/src/VHDLSignal.java @@ -10,14 +10,6 @@ import java.util.Collection; public class VHDLSignal extends ParsableXML { - private static final XPathExpression GET_ENTITIES; - - static - { - /* TODO */ - GET_ENTITIES = null; - } - public VHDLSignal ( final IDs parent_id, diff --git a/ast-to-instr/src/VHDLWNode.java b/ast-to-instr/src/VHDLWNode.java new file mode 100644 index 0000000..de11c7b --- /dev/null +++ b/ast-to-instr/src/VHDLWNode.java @@ -0,0 +1,47 @@ +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; + +/* If Statement Node */ +public class VHDLISNode extends VHDLNode +{ + private static final XPathExpression XPE_FIND_SUB_NODES; + + static + { + XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el"); + } + + public VHDLISNode + ( + final IDs parent_id, + final Node xml_node, + final IDs next_node, + final int depth, + final String[] attributes + ) + { + super + ( + parent_id, + xml_node, + next_node, + depth, + attributes + ); + } + + @Override + public Collection<ParsableXML> parse () + throws XPathExpressionException + { + /* TODO */ + return null; + } +} diff --git a/ast-to-instr/src/XMLManager.java b/ast-to-instr/src/XMLManager.java index dc3eef1..a203bf0 100644 --- a/ast-to-instr/src/XMLManager.java +++ b/ast-to-instr/src/XMLManager.java @@ -71,7 +71,7 @@ public class XMLManager { final File file; - file = new File(filename, "r"); + file = new File(filename); return DOC_BUILDER.parse(file); } |


