| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-20 17:34:51 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-20 17:34:51 +0200 |
| commit | 72b3069a20b8573ceff73b27936a76213aacc344 (patch) | |
| tree | eeb1842e43be53a372d09b723a51a85bcc098f3d | |
| parent | 44d19480a10924eac2191308d8842a4df1657167 (diff) | |
Adds Simple Signal Assignment Statement Node.
| -rw-r--r-- | ast-to-instr/src/Main.java | 7 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLISNode.java | 99 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLProcess.java | 2 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLSSASNode.java | 255 |
4 files changed, 342 insertions, 21 deletions
diff --git a/ast-to-instr/src/Main.java b/ast-to-instr/src/Main.java index 8f0b766..6455e19 100644 --- a/ast-to-instr/src/Main.java +++ b/ast-to-instr/src/Main.java @@ -13,6 +13,7 @@ public class Main { private static final XPathExpression XPE_FIND_ALL_VHDL_FILES; private static Parameters PARAMETERS; + private static Document root; static { @@ -25,7 +26,6 @@ public class Main public static void main (final String... args) { - final Document root; final Collection<Node> vhdl_files; PARAMETERS = new Parameters(args); @@ -122,4 +122,9 @@ public class Main /* TODO */ return false; } + + public static Document get_xml_root () + { + return root; + } } diff --git a/ast-to-instr/src/VHDLISNode.java b/ast-to-instr/src/VHDLISNode.java index 5dedabf..66eb52a 100644 --- a/ast-to-instr/src/VHDLISNode.java +++ b/ast-to-instr/src/VHDLISNode.java @@ -74,11 +74,10 @@ public class VHDLISNode extends VHDLNode /** Predicates **********************************************************/ handle_predicate_has_option(local_id); handle_predicate_expr_reads(local_id); - handle_predicate_is_final(local_id); /** Children ************************************************************/ - result.add(handle_true_branch(local_id)); - result.add(handle_else_branch(local_id)); + result.addAll(handle_true_branch(local_id)); + result.addAll(handle_else_branch(local_id)); return result; } @@ -190,33 +189,105 @@ public class VHDLISNode extends VHDLNode local_id, Waveforms.get_associated_waveform_id ( - IDs.get_id_from_xml_id(ref, null) + IDs.get_id_from_xml_id(ref, (String) null) ) ); } } } - private void handle_predicate_is_final + /***************************************************************************/ + /** Children ***************************************************************/ + /***************************************************************************/ + private Collection<ParsableXML> handle_true_branch ( final IDs local_id ) + throws XPathExpressionException { - /* TODO */ - /* ((next_node == null) && !(has_else)) => is_final */ + final Collection<ParsableXML> result; + final Node true_branch; + + result = new ArrayList<ParsableXML>(); + + true_branch = + (Node) XPE_FIND_TRUE_BRANCH.evaluate + ( + xml_node, + XPathConstants.NODE + ); + + + result.add + ( + new VHDLSSCNode + ( + parent_id, + true_branch, + local_id, + next_node, + (depth + 1), + new String[] {"COND_WAS_TRUE"} + ) + ); + + return result; } - /***************************************************************************/ - /** Children ***************************************************************/ - /***************************************************************************/ - private Collection<ParsableXML> handle_true_branch + private Collection<ParsableXML> handle_else_branch ( final IDs local_id ) + throws XPathExpressionException { - /* TODO */ + final Collection<ParsableXML> result; + final Node else_branch; - return null; - } + result = new ArrayList<ParsableXML>(); + + else_branch = + (Node) XPE_FIND_TRUE_BRANCH.evaluate + ( + xml_node, + XPathConstants.NODE + ); + + if (else_branch == (Node) null) + { + if (next_node == (IDs) null) + { + Predicates.add_entry + ( + "is_final", + local_id + ); + } + else + { + Predicates.add_entry + ( + "node_connect", + local_id, + next_node + ); + } + } + else + { + result.add + ( + new VHDLSSCNode + ( + parent_id, + else_branch, + local_id, + next_node, + (depth + 1), + new String[] {"COND_WAS_FALSE"} + ) + ); + } + return result; + } } diff --git a/ast-to-instr/src/VHDLProcess.java b/ast-to-instr/src/VHDLProcess.java index 5d49b40..36634fe 100644 --- a/ast-to-instr/src/VHDLProcess.java +++ b/ast-to-instr/src/VHDLProcess.java @@ -439,7 +439,7 @@ public class VHDLProcess extends ParsableXML "ref" ); - if (!Main.node_is_function_or_literal(ref)) + if (!Main.node_is_function_or_literal(xml_id)) { Predicates.add_entry ( diff --git a/ast-to-instr/src/VHDLSSASNode.java b/ast-to-instr/src/VHDLSSASNode.java index de11c7b..3e61396 100644 --- a/ast-to-instr/src/VHDLSSASNode.java +++ b/ast-to-instr/src/VHDLSSASNode.java @@ -9,16 +9,27 @@ import java.util.ArrayList; import java.util.Collection; /* If Statement Node */ -public class VHDLISNode extends VHDLNode +public class VHDLSSASNode extends VHDLNode { - private static final XPathExpression XPE_FIND_SUB_NODES; + private static final XPathExpression XPE_FIND_TARGET; + private static final XPathExpression XPE_FIND_SOURCES; + private static final XPathExpression XPE_FIND_PREFIXED_NE; + private static final XPathExpression XPE_FIND_NE; static { - XPE_FIND_SUB_NODES = XMLManager.compile_or_die("./el"); + XPE_FIND_TARGET = XMLManager.compile_or_die("./target"); + + XPE_FIND_SOURCES = XMLManager.compile_or_die + ( + "./waveform_chain//named_entity" + ); + + XPE_FIND_PREFIXED_NE = XMLManager.compile_or_die("./prefix/named_entity"); + XPE_FIND_NE = XMLManager.compile_or_die("./named_entity"); } - public VHDLISNode + public VHDLSSASNode ( final IDs parent_id, final Node xml_node, @@ -41,7 +52,241 @@ public class VHDLISNode extends VHDLNode public Collection<ParsableXML> parse () throws XPathExpressionException { + + final String xml_id; + final IDs local_id; + + xml_id = XMLManager.get_attribute(xml_node, "id"); + + local_id = IDs.get_id_from_xml_id(xml_id, "node"); + + /** Functions ***********************************************************/ + handle_function_label(local_id); + handle_function_kind(local_id); + handle_function_depth(local_id); + handle_function_expression(local_id); + + /** Predicates **********************************************************/ + handle_predicate_has_option(local_id); + handle_predicate_expr_reads(local_id); + handle_predicate_expr_writes(local_id); + + /** Children ************************************************************/ + handle_next_node(local_id); + + return (new ArrayList<ParsableXML>()); + } + + /***************************************************************************/ + /** Functions **************************************************************/ + /***************************************************************************/ + private void handle_function_label + ( + final IDs local_id + ) + { + Functions.add_entry + ( + "label", + local_id, + Strings.get_id_from_string + ( + XMLManager.get_attribute(xml_node, "label") + ) + ); + } + + private void handle_function_kind + ( + final IDs local_id + ) + { + Functions.add_entry + ( + "kind", + local_id, + Strings.get_id_from_string("if") + ); + } + + private void handle_function_depth + ( + final IDs local_id + ) + { + Functions.add_entry + ( + "kind", + local_id, + Strings.get_id_from_string + ( + Integer.toString(depth) + ) + ); + } + + private void handle_function_expression + ( + final IDs local_id + ) + { /* TODO */ - return null; + } + + /***************************************************************************/ + /** Predicates *************************************************************/ + /***************************************************************************/ + private void handle_predicate_has_option + ( + final IDs local_id + ) + { + for (final String s: attributes) + { + Predicates.add_entry + ( + "has_option", + local_id, + Strings.get_id_from_string(s) + ); + } + } + + private void handle_predicate_expr_reads + ( + final IDs local_id + ) + throws XPathExpressionException + { + final NodeList sources; + final int sources_count; + + sources = + (NodeList) XPE_FIND_SOURCES.evaluate + ( + xml_node, + XPathConstants.NODESET + ); + + sources_count = sources.getLength(); + + for (int i = 0; i < sources_count; ++i) + { + final String ref; + + ref = XMLManager.get_attribute(sources.item(0), "ref"); + + if (!Main.node_is_function_or_literal(ref)) + { + Predicates.add_entry + ( + "expr_reads", + local_id, + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id(ref, (String) null) + ) + ); + } + } + } + + private void handle_predicate_expr_writes + ( + final IDs local_id + ) + throws XPathExpressionException + { + Node target; + + target = + (Node) XPE_FIND_TARGET.evaluate + ( + xml_node, + XPathConstants.NODE + ); + + /* Oddly enough, we can get a target as a ref... */ + /* Let's get the real source! */ + while (target.getNodeName().equals("target")) + { + final XPathExpression xpe_find_source; + + if (XMLManager.get_attribute(target, "kind").equals("indexed_name")) + { + target = + (Node) XPE_FIND_PREFIXED_NE.evaluate + ( + target, + XPathConstants.NODE + ); + } + else + { + target = + (Node) XPE_FIND_NE.evaluate + ( + target, + XPathConstants.NODE + ); + } + + /* XXX "or_die" might be a bit abusive here. */ + xpe_find_source = + XMLManager.compile_or_die + ( + ".//*[@id=\"" + + XMLManager.get_attribute(target, "ref") + + "\"]" + ); + + target = + (Node) xpe_find_source.evaluate + ( + Main.get_xml_root(), + XPathConstants.NODE + ); + } + + Predicates.add_entry + ( + "expr_writes", + local_id, + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id + ( + XMLManager.get_attribute(target, "id"), + (String) null + ) + ) + ); + } + + /***************************************************************************/ + /** Children ***************************************************************/ + /***************************************************************************/ + public void handle_next_node + ( + final IDs local_id + ) + { + if (next_node == (IDs) null) + { + Predicates.add_entry + ( + "is_final", + local_id + ); + } + else + { + Predicates.add_entry + ( + "node_connect", + local_id, + next_node + ); + } } } |


