From 878705688b42837b615067f0a479f31614910f38 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 21 Jul 2017 11:06:12 +0200 Subject: Optimization pass. --- ast-to-instr/src/Main.java | 44 +++++++++++++++++++++----- ast-to-instr/src/ParsableXML.java | 10 +++--- ast-to-instr/src/VHDLArchitecture.java | 55 ++++++++++++-------------------- ast-to-instr/src/VHDLCSNode.java | 41 +++++++++--------------- ast-to-instr/src/VHDLComponent.java | 28 +++++++++++------ ast-to-instr/src/VHDLEntity.java | 41 +++++++++--------------- ast-to-instr/src/VHDLFile.java | 44 +++++++++++--------------- ast-to-instr/src/VHDLGeneric.java | 13 +++----- ast-to-instr/src/VHDLISNode.java | 57 +++++++++++++++------------------- ast-to-instr/src/VHDLPort.java | 13 +++----- ast-to-instr/src/VHDLProcess.java | 27 ++++++---------- ast-to-instr/src/VHDLSSASNode.java | 11 +++---- ast-to-instr/src/VHDLSSCNode.java | 17 +++++----- ast-to-instr/src/VHDLSignal.java | 13 +++----- ast-to-instr/src/VHDLWNode.java | 42 ++++++++++++------------- 15 files changed, 212 insertions(+), 244 deletions(-) diff --git a/ast-to-instr/src/Main.java b/ast-to-instr/src/Main.java index 104c4f7..e0bc301 100644 --- a/ast-to-instr/src/Main.java +++ b/ast-to-instr/src/Main.java @@ -101,7 +101,7 @@ public class Main try { System.out.println("Parsing XML..."); - children = waiting_list.pop().parse(); + waiting_list.pop().parse(waiting_list); } catch (final XPathExpressionException xpee) { @@ -114,17 +114,47 @@ public class Main return; } - - for (final ParsableXML c: children) - { - waiting_list.push(c); - } } } public static boolean node_is_function_or_literal (final String xml_id) + throws XPathExpressionException { - /* TODO */ + final XPathExpression xpe_find_el_from_id; + final Node n; + final String kind; + + xpe_find_el_from_id = + XMLManager.compile_or_die + ( + ".//el[@id=\"" + + xml_id + + "\"]" + ); + + n = + (Node) xpe_find_el_from_id.evaluate + ( + root, + XPathConstants.NODE + ); + + if (n == (Node) null) + { + return true; + } + + kind = XMLManager.get_attribute(n, "kind"); + + if (kind.equals("function_declaration")) + { + return true; + } + else if (kind.equals("enumeration_literal")) + { + return true; + } + return false; } diff --git a/ast-to-instr/src/ParsableXML.java b/ast-to-instr/src/ParsableXML.java index b190b48..5f8a57b 100644 --- a/ast-to-instr/src/ParsableXML.java +++ b/ast-to-instr/src/ParsableXML.java @@ -1,7 +1,6 @@ import org.w3c.dom.Node; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; import javax.xml.xpath.XPathExpressionException; @@ -20,9 +19,12 @@ public abstract class ParsableXML this.xml_node = xml_node; } - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - return new ArrayList(); + } } diff --git a/ast-to-instr/src/VHDLArchitecture.java b/ast-to-instr/src/VHDLArchitecture.java index 5b5f033..c6014a8 100644 --- a/ast-to-instr/src/VHDLArchitecture.java +++ b/ast-to-instr/src/VHDLArchitecture.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLArchitecture extends ParsableXML { @@ -45,15 +44,15 @@ public class VHDLArchitecture extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "architecture"); @@ -75,11 +74,9 @@ public class VHDLArchitecture extends ParsableXML handle_predicate_end_has_identifier(local_id); /** Children ************************************************************/ - result.addAll(handle_child_signals(local_id)); - result.addAll(handle_child_processes(local_id)); - result.addAll(handle_child_components(local_id)); - - return result; + handle_child_signals(local_id, waiting_list); + handle_child_processes(local_id, waiting_list); + handle_child_components(local_id, waiting_list); } /***************************************************************************/ @@ -228,18 +225,16 @@ public class VHDLArchitecture extends ParsableXML /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection handle_child_signals + private void handle_child_signals ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList signals; final int children_count; - result = new ArrayList(); - signals = (NodeList) XPE_FIND_SIGNALS.evaluate ( @@ -251,24 +246,20 @@ public class VHDLArchitecture extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLSignal(local_id, signals.item(i))); + waiting_list.push(new VHDLSignal(local_id, signals.item(i))); } - - return result; } - private Collection handle_child_processes + private void handle_child_processes ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList processes; final int children_count; - result = new ArrayList(); - processes = (NodeList) XPE_FIND_PROCESSES.evaluate ( @@ -280,24 +271,20 @@ public class VHDLArchitecture extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLProcess(local_id, processes.item(i))); + waiting_list.push(new VHDLProcess(local_id, processes.item(i))); } - - return result; } - private Collection handle_child_components + private void handle_child_components ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList components; final int children_count; - result = new ArrayList(); - components = (NodeList) XPE_FIND_COMPONENTS.evaluate ( @@ -309,9 +296,7 @@ public class VHDLArchitecture extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLComponent(local_id, components.item(i))); + waiting_list.push(new VHDLComponent(local_id, components.item(i))); } - - return result; } } diff --git a/ast-to-instr/src/VHDLCSNode.java b/ast-to-instr/src/VHDLCSNode.java index 7ed0ff5..05a7450 100644 --- a/ast-to-instr/src/VHDLCSNode.java +++ b/ast-to-instr/src/VHDLCSNode.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; /* Case Statement Node */ public class VHDLCSNode extends VHDLNode @@ -57,15 +56,15 @@ public class VHDLCSNode extends VHDLNode } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "node"); @@ -81,10 +80,8 @@ public class VHDLCSNode extends VHDLNode handle_predicate_expr_reads(local_id); /** Children ************************************************************/ - result.addAll(handle_when_branches(local_id)); - result.addAll(handle_others_branch(local_id)); - - return result; + handle_when_branches(local_id, waiting_list); + handle_others_branch(local_id, waiting_list); } /***************************************************************************/ @@ -204,18 +201,16 @@ public class VHDLCSNode extends VHDLNode /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection handle_when_branches + private void handle_when_branches ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList when_branches; final int when_branches_length; - result = new ArrayList(); - when_branches = (NodeList) XPE_FIND_WHEN_BRANCHES.evaluate ( @@ -228,7 +223,7 @@ public class VHDLCSNode extends VHDLNode for (int i = 0; i < when_branches_length; ++i) { - result.add + waiting_list.add ( new VHDLWNode ( @@ -240,21 +235,17 @@ public class VHDLCSNode extends VHDLNode ) ); } - - return result; } - private Collection handle_others_branch + private void handle_others_branch ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final Node others_branch; - result = new ArrayList(); - others_branch = (Node) XPE_FIND_OTHERS_BRANCH.evaluate ( @@ -284,7 +275,7 @@ public class VHDLCSNode extends VHDLNode } else { - result.add + waiting_list.push ( new VHDLWNode ( @@ -296,7 +287,5 @@ public class VHDLCSNode extends VHDLNode ) ); } - - return result; } } diff --git a/ast-to-instr/src/VHDLComponent.java b/ast-to-instr/src/VHDLComponent.java index 116b0b8..37a03a0 100644 --- a/ast-to-instr/src/VHDLComponent.java +++ b/ast-to-instr/src/VHDLComponent.java @@ -5,17 +5,29 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLComponent extends ParsableXML { private static final XPathExpression XPE_FIND_PORT_MAPS; + private static final XPathExpression XPE_FIND_REAL_PORTS; private static final XPathExpression XPE_FIND_GENERIC_MAPS; static { - XPE_FIND_PORT_MAPS = null; /* TODO */ + XPE_FIND_PORT_MAPS = + XMLManager.compile_or_die + ( + "./el[@kind=\"association_element_by_expression\"]" + ); + + XPE_FIND_REAL_PORTS = + XMLManager.compile_or_die + ( + "./port_chain/el[@kind=\"interface_signal_declaration\"]" + ); + + /* TODO */ XPE_FIND_GENERIC_MAPS = null; /* TODO */ } @@ -29,15 +41,15 @@ public class VHDLComponent extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "component"); @@ -54,8 +66,6 @@ public class VHDLComponent extends ParsableXML /** Predicates **********************************************************/ handle_predicate_port_maps(local_id); handle_predicate_generic_maps(local_id); - - return result; } /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLEntity.java b/ast-to-instr/src/VHDLEntity.java index 9ece7e0..81e1338 100644 --- a/ast-to-instr/src/VHDLEntity.java +++ b/ast-to-instr/src/VHDLEntity.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLEntity extends ParsableXML { @@ -38,15 +37,15 @@ public class VHDLEntity extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "entity"); @@ -67,10 +66,8 @@ public class VHDLEntity extends ParsableXML handle_predicate_end_has_identifier(local_id); /** Children ************************************************************/ - result.addAll(handle_child_ports(local_id)); - result.addAll(handle_child_generics(local_id)); - - return result; + handle_child_ports(local_id, waiting_list); + handle_child_generics(local_id, waiting_list); } /***************************************************************************/ @@ -232,18 +229,16 @@ public class VHDLEntity extends ParsableXML /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection handle_child_ports + private void handle_child_ports ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList ports; final int children_count; - result = new ArrayList(); - ports = (NodeList) XPE_FIND_PORTS.evaluate ( @@ -255,24 +250,20 @@ public class VHDLEntity extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLPort(local_id, ports.item(i))); + waiting_list.push(new VHDLPort(local_id, ports.item(i))); } - - return result; } - private Collection handle_child_generics + private void handle_child_generics ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList generics; final int children_count; - result = new ArrayList(); - generics = (NodeList) XPE_FIND_GENERICS.evaluate ( @@ -284,9 +275,7 @@ public class VHDLEntity extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLGeneric(local_id, generics.item(i))); + waiting_list.push(new VHDLGeneric(local_id, generics.item(i))); } - - return result; } } diff --git a/ast-to-instr/src/VHDLFile.java b/ast-to-instr/src/VHDLFile.java index c619a1b..50b6099 100644 --- a/ast-to-instr/src/VHDLFile.java +++ b/ast-to-instr/src/VHDLFile.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLFile extends ParsableXML { @@ -38,15 +37,15 @@ public class VHDLFile extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "file"); @@ -57,10 +56,8 @@ public class VHDLFile extends ParsableXML /** Predicates **********************************************************/ /** Children ************************************************************/ - result.addAll(handle_child_entities(local_id)); - result.addAll(handle_child_architectures(local_id)); - - return result; + handle_child_entities(local_id, waiting_list); + handle_child_architectures(local_id, waiting_list); } /***************************************************************************/ @@ -85,18 +82,16 @@ public class VHDLFile extends ParsableXML /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection handle_child_entities + private void handle_child_entities ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList entities; final int children_count; - result = new ArrayList(); - entities = (NodeList) XPE_FIND_ENTITIES.evaluate ( @@ -108,24 +103,20 @@ public class VHDLFile extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLEntity(local_id, entities.item(i))); + waiting_list.push(new VHDLEntity(local_id, entities.item(i))); } - - return result; } - private Collection handle_child_architectures + private void handle_child_architectures ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final NodeList architectures; final int children_count; - result = new ArrayList(); - architectures = (NodeList) XPE_FIND_ARCHITECTURES.evaluate ( @@ -137,9 +128,10 @@ public class VHDLFile extends ParsableXML for (int i = 0; i < children_count; ++i) { - result.add(new VHDLArchitecture(local_id, architectures.item(i))); + waiting_list.push + ( + new VHDLArchitecture(local_id, architectures.item(i)) + ); } - - return result; } } diff --git a/ast-to-instr/src/VHDLGeneric.java b/ast-to-instr/src/VHDLGeneric.java index 866ae95..89cb42f 100644 --- a/ast-to-instr/src/VHDLGeneric.java +++ b/ast-to-instr/src/VHDLGeneric.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLGeneric extends ParsableXML { @@ -20,15 +19,15 @@ public class VHDLGeneric extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "generic"); @@ -51,8 +50,6 @@ public class VHDLGeneric extends ParsableXML /** Children ************************************************************/ handle_child_waveform(local_id); - - return result; } /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLISNode.java b/ast-to-instr/src/VHDLISNode.java index f38dcf3..bb16e1b 100644 --- a/ast-to-instr/src/VHDLISNode.java +++ b/ast-to-instr/src/VHDLISNode.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; /* If Statement Node */ public class VHDLISNode extends VHDLNode @@ -56,15 +55,15 @@ public class VHDLISNode extends VHDLNode } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "node"); @@ -80,10 +79,8 @@ public class VHDLISNode extends VHDLNode handle_predicate_expr_reads(local_id); /** Children ************************************************************/ - result.add(handle_true_branch(local_id)); - result.addAll(handle_else_branch(local_id)); - - return result; + handle_true_branch(local_id, waiting_list); + handle_else_branch(local_id, waiting_list); } /***************************************************************************/ @@ -203,9 +200,10 @@ public class VHDLISNode extends VHDLNode /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private ParsableXML handle_true_branch + private void handle_true_branch ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { @@ -218,32 +216,29 @@ public class VHDLISNode extends VHDLNode XPathConstants.NODE ); - return + waiting_list.push + ( + new VHDLSSCNode ( - new VHDLSSCNode - ( - parent_id, - true_branch, - local_id, - next_node, - (depth + 1), - new String[] {"COND_WAS_TRUE"} - ) - ); - + parent_id, + true_branch, + local_id, + next_node, + (depth + 1), + new String[] {"COND_WAS_TRUE"} + ) + ); } - private Collection handle_else_branch + private void handle_else_branch ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { - final Collection result; final Node else_branch; - result = new ArrayList(); - else_branch = (Node) XPE_FIND_ELSE_BRANCH.evaluate ( @@ -273,7 +268,7 @@ public class VHDLISNode extends VHDLNode } else { - result.add + waiting_list.push ( new VHDLSSCNode ( @@ -286,7 +281,5 @@ public class VHDLISNode extends VHDLNode ) ); } - - return result; } } diff --git a/ast-to-instr/src/VHDLPort.java b/ast-to-instr/src/VHDLPort.java index 3670605..9bb4d2c 100644 --- a/ast-to-instr/src/VHDLPort.java +++ b/ast-to-instr/src/VHDLPort.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLPort extends ParsableXML { @@ -20,15 +19,15 @@ public class VHDLPort extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "port"); @@ -57,8 +56,6 @@ public class VHDLPort extends ParsableXML /** Children ************************************************************/ handle_child_waveform(local_id); - - return result; } /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLProcess.java b/ast-to-instr/src/VHDLProcess.java index 4f4ef73..0e26cce 100644 --- a/ast-to-instr/src/VHDLProcess.java +++ b/ast-to-instr/src/VHDLProcess.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLProcess extends ParsableXML { @@ -45,15 +44,15 @@ public class VHDLProcess extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "process"); @@ -84,9 +83,7 @@ public class VHDLProcess extends ParsableXML handle_predicate_is_accessed_by(local_id); /** Children ************************************************************/ - result.addAll(handle_child_node(local_id)); - - return result; + handle_child_node(local_id, waiting_list); } /***************************************************************************/ @@ -461,14 +458,14 @@ public class VHDLProcess extends ParsableXML /***************************************************************************/ /** Children ***************************************************************/ /***************************************************************************/ - private Collection handle_child_node + private void handle_child_node ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { final Node start_node; - final Collection result; start_node = (Node) XPE_FIND_START_NODE.evaluate @@ -477,9 +474,7 @@ public class VHDLProcess extends ParsableXML XPathConstants.NODE ); - result = new ArrayList(); - - result.add + waiting_list.push ( new VHDLSSCNode ( @@ -491,7 +486,5 @@ public class VHDLProcess extends ParsableXML new String[0] /* No attributes. */ ) ); - - return result; } } diff --git a/ast-to-instr/src/VHDLSSASNode.java b/ast-to-instr/src/VHDLSSASNode.java index 8c84e96..6cff44d 100644 --- a/ast-to-instr/src/VHDLSSASNode.java +++ b/ast-to-instr/src/VHDLSSASNode.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; /* Simple Signal Assignment Statement Node */ public class VHDLSSASNode extends VHDLNode @@ -50,10 +49,12 @@ public class VHDLSSASNode extends VHDLNode } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final String xml_id; final IDs local_id; @@ -74,8 +75,6 @@ public class VHDLSSASNode extends VHDLNode /** Children ************************************************************/ handle_next_node(local_id); - - return (new ArrayList()); } /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLSSCNode.java b/ast-to-instr/src/VHDLSSCNode.java index 95ddfbb..8fb620b 100644 --- a/ast-to-instr/src/VHDLSSCNode.java +++ b/ast-to-instr/src/VHDLSSCNode.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; /* Sequential Statement Chain Node */ /* Not actually a node in the resulting model, though. */ @@ -43,16 +42,16 @@ public class VHDLSSCNode extends VHDLNode } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final NodeList sub_nodes; final int intermediary_nodes_count; int i; - result = new ArrayList(); - sub_nodes = (NodeList) XPE_FIND_SUB_NODES.evaluate ( @@ -77,14 +76,12 @@ public class VHDLSSCNode extends VHDLNode "node" ); - result.add(get_vhdl_node(sub_nodes.item(i), next_node, i)); + waiting_list.push(get_vhdl_node(sub_nodes.item(i), next_node, i)); } - result.add(get_vhdl_node(sub_nodes.item(i), next_node, i)); + waiting_list.push(get_vhdl_node(sub_nodes.item(i), next_node, i)); handle_backward_connection(sub_nodes.item(0)); - - return result; } private ParsableXML get_vhdl_node diff --git a/ast-to-instr/src/VHDLSignal.java b/ast-to-instr/src/VHDLSignal.java index e171576..c7edaf9 100644 --- a/ast-to-instr/src/VHDLSignal.java +++ b/ast-to-instr/src/VHDLSignal.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; public class VHDLSignal extends ParsableXML { @@ -20,15 +19,15 @@ public class VHDLSignal extends ParsableXML } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "signal"); @@ -55,8 +54,6 @@ public class VHDLSignal extends ParsableXML /** Children ************************************************************/ handle_child_waveform(local_id); - - return result; } /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLWNode.java b/ast-to-instr/src/VHDLWNode.java index 4c2b2ee..b32d2a4 100644 --- a/ast-to-instr/src/VHDLWNode.java +++ b/ast-to-instr/src/VHDLWNode.java @@ -5,8 +5,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Stack; /* When Node */ public class VHDLWNode extends VHDLNode @@ -49,15 +48,15 @@ public class VHDLWNode extends VHDLNode } @Override - public Collection parse () + public void parse + ( + final Stack waiting_list + ) throws XPathExpressionException { - final Collection result; final String xml_id; final IDs local_id; - result = new ArrayList(); - xml_id = XMLManager.get_attribute(xml_node, "id"); local_id = IDs.get_id_from_xml_id(xml_id, "node"); @@ -73,9 +72,7 @@ public class VHDLWNode extends VHDLNode handle_predicate_expr_reads(local_id); /** Children ************************************************************/ - result.add(handle_body(local_id)); - - return result; + handle_body(local_id, waiting_list); } /***************************************************************************/ @@ -193,9 +190,10 @@ public class VHDLWNode extends VHDLNode /** Children ***************************************************************/ /***************************************************************************/ - private ParsableXML handle_body + private void handle_body ( - final IDs local_id + final IDs local_id, + final Stack waiting_list ) throws XPathExpressionException { @@ -208,17 +206,17 @@ public class VHDLWNode extends VHDLNode XPathConstants.NODE ); - return + waiting_list.push + ( + new VHDLSSCNode ( - new VHDLSSCNode - ( - parent_id, - body, - local_id, - next_node, - (depth + 1), - new String[] {"COND_WAS_TRUE"} - ) - ); + parent_id, + body, + local_id, + next_node, + (depth + 1), + new String[] {"COND_WAS_TRUE"} + ) + ); } } -- cgit v1.2.3-70-g09d2