| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | ast-to-instr/Makefile | 2 | ||||
| -rw-r--r-- | ast-to-instr/src/Expressions.java | 107 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLCSNode.java | 34 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLISNode.java | 38 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLNode.java | 59 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLSSASNode.java | 16 | ||||
| -rw-r--r-- | ast-to-instr/src/VHDLWNode.java | 38 | 
7 files changed, 172 insertions, 122 deletions
| diff --git a/ast-to-instr/Makefile b/ast-to-instr/Makefile index f09cae1..4a19d4f 100644 --- a/ast-to-instr/Makefile +++ b/ast-to-instr/Makefile @@ -1,4 +1,4 @@ -INPUT_FILE = ../data/ast/*.xml +INPUT_FILE = ../data/ast/best_chronometer_ever.xml  ## Executables #################################################################  JAVAC = javac diff --git a/ast-to-instr/src/Expressions.java b/ast-to-instr/src/Expressions.java new file mode 100644 index 0000000..a4c4bbf --- /dev/null +++ b/ast-to-instr/src/Expressions.java @@ -0,0 +1,107 @@ +import java.util.Map; +import java.util.HashMap; + +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +public class Expressions +{ +   private static final XPathExpression XPE_GET_LEFT, XPE_GET_RIGHT; + +   static +   { +      XPE_GET_LEFT = XMLManager.compile_or_die("./left"); +      XPE_GET_RIGHT = XMLManager.compile_or_die("./right"); +   } + +   private static enum Operator +   { +      /* From GHDL's ./src/vhdl/nodes_meta.adb */ +      IDENTITY("identity_operator", false), /* assuming it means "+ number" */ +      NEGATION("negation_operator", false), /* assuming it means "- number" */ +      ABSOLUTE("absolute_operator", false), + +      NOT("not_operator", false), + +      CONDITION("condition_operator", true), /* FIXME: what's this? */ + +      /* Flattens vectors using an operator. */ +      REDUCTION_AND("reduction_and_operator", false), +      REDUCTION_OR("reduction_or_operator", false), +      REDUCTION_NAND("reduction_nand_operator", false), +      REDUCTION_NOR("reduction_nor_operator", false), +      REDUCTION_XOR("reduction_xor_operator", false), +      REDUCTION_XNOR("reduction_xnor_operator", false), + +      AND("and_operator", true), +      OR("or_operator", true), +      NAND("nand_operator", true), +      NOR("nor_operator", true), +      XOR("xor_operator", true), +      XNOR("xnor_operator", true), + +      EQUALITY("equality_operator", true), +      INEQUALITY("inequality_operator", true), +      LESS_THAN("less_than_operator", true), +      LESS_THAN_OR_EQUAL("less_than_or_equal_operator", true), +      GREATER_THAN("greater_than_operator", true), +      GREATER_THAN_OR_EQUAL("greater_than_or_equal_operator", true), + +      /* FIXME: What are those? */ +      MATCH_EQUALITY("match_equality_operator", true), +      MATCH_INEQUALITY("match_inequality_operator", true), +      MATCH_LESS_THAN("match_less_than_operator", true), +      MATCH_LESS_THAN_OR_EQUAL("match_less_than_or_equal_operator", true), +      MATCH_GREATER_THAN("match_greater_than_operator", true), +      MATCH_GREATER_THAN_OR_EQUAL("match_greater_than_or_equal_operator", true), + +      /* Called using "logical array OP integer", apparently. */ +      SLL("sll_operator", true), +      SLA("sla_operator", true), +      SRL("srl_operator", true), +      SRA("sra_operator", true), +      ROL("rol_operator", true), +      ROR("ror_operator", true), + +      ADDITION("addition_operator", true), +      SUBSTRACTION("substraction_operator", true), +      CONCATENATION("concatenation_operator", true), +      MULTIPLICATION("multiplication_operator", true), +      DIVISION("division_operator", true), +      MODULUS("modulus_operator", true), +      REMAINDER("remainder_operator", true), +      EXPONENTIATION("exponentiation_operator", true); + +      /** Static **************************************************************/ +      private static final Map<String, Operator> FROM_TAG; + +      static +      { +         final Operator operators[]; + +         FROM_TAG = new HashMap<String, Operator>(); + +         operators = Operator.class.getEnumConstants(); /* We Java now... */ + +         for (final Operator op: operators) +         { +            FROM_TAG.put(op.tag, op); +         } +      } + +      /** Non-Static **********************************************************/ +      private final String tag; +      private final boolean is_binary; + +      private Operator +      ( +         final String tag, +         final boolean is_binary +      ) +      { +         this.tag = tag; +         this.is_binary = is_binary; +      } +   } +   /***************************************************************************/ +} diff --git a/ast-to-instr/src/VHDLCSNode.java b/ast-to-instr/src/VHDLCSNode.java index ebc1b52..7989c67 100644 --- a/ast-to-instr/src/VHDLCSNode.java +++ b/ast-to-instr/src/VHDLCSNode.java @@ -19,7 +19,7 @@ public class VHDLCSNode extends VHDLNode        XPE_FIND_SOURCES =           XMLManager.compile_or_die           ( -            "./expression//named_entity" +            "./expression"/*//named_entity"*/           );        XPE_FIND_OTHERS_BRANCH = @@ -172,38 +172,16 @@ public class VHDLCSNode extends VHDLNode     )     throws XPathExpressionException     { -      final NodeList named_entities; -      final int named_entities_count; +      final Node sources; -      named_entities = -         (NodeList) XPE_FIND_SOURCES.evaluate +      sources = +         (Node) XPE_FIND_SOURCES.evaluate           (              xml_node, -            XPathConstants.NODESET +            XPathConstants.NODE           ); -      named_entities_count = named_entities.getLength(); - -      for (int i = 0; i < named_entities_count; ++i) -      { -         final String ref; - -         ref = XMLManager.get_attribute(named_entities.item(0), "ref"); - -         if (!Main.node_is_function_or_literal(ref)) -         { -            Predicates.add_entry -            ( -               output, -               "expr_reads", -               local_id, -               Waveforms.get_associated_waveform_id -               ( -                  IDs.get_id_from_xml_id(ref, (String) null) -               ) -            ); -         } -      } +      handle_expression(local_id, sources);     }     /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLISNode.java b/ast-to-instr/src/VHDLISNode.java index f9f8eb3..6f70aa8 100644 --- a/ast-to-instr/src/VHDLISNode.java +++ b/ast-to-instr/src/VHDLISNode.java @@ -10,16 +10,16 @@ import java.util.Stack;  /* If Statement Node */  public class VHDLISNode extends VHDLNode  { -   private static final XPathExpression XPE_FIND_NAMED_ENTITIES; +   private static final XPathExpression XPE_FIND_SOURCES;     private static final XPathExpression XPE_FIND_TRUE_BRANCH;     private static final XPathExpression XPE_FIND_ELSE_BRANCH;     static     { -      XPE_FIND_NAMED_ENTITIES = +      XPE_FIND_SOURCES =           XMLManager.compile_or_die           ( -            "./condition//named_entity" +            "./condition" /* //named_entity" */           );        XPE_FIND_TRUE_BRANCH = @@ -170,38 +170,16 @@ public class VHDLISNode extends VHDLNode     )     throws XPathExpressionException     { -      final NodeList named_entities; -      final int named_entities_count; +      final Node sources; -      named_entities = -         (NodeList) XPE_FIND_NAMED_ENTITIES.evaluate +      sources = +         (Node) XPE_FIND_SOURCES.evaluate           (              xml_node, -            XPathConstants.NODESET +            XPathConstants.NODE           ); -      named_entities_count = named_entities.getLength(); - -      for (int i = 0; i < named_entities_count; ++i) -      { -         final String ref; - -         ref = XMLManager.get_attribute(named_entities.item(0), "ref"); - -         if (!Main.node_is_function_or_literal(ref)) -         { -            Predicates.add_entry -            ( -               output, -               "expr_reads", -               local_id, -               Waveforms.get_associated_waveform_id -               ( -                  IDs.get_id_from_xml_id(ref, (String) null) -               ) -            ); -         } -      } +      handle_expression(local_id, sources);     }     /***************************************************************************/ diff --git a/ast-to-instr/src/VHDLNode.java b/ast-to-instr/src/VHDLNode.java index 6c49cdf..970be9a 100644 --- a/ast-to-instr/src/VHDLNode.java +++ b/ast-to-instr/src/VHDLNode.java @@ -1,49 +1,39 @@  import org.w3c.dom.Node;  import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathExpression;  public abstract class VHDLNode extends ParsableXML  { -   protected final IDs next_node; -   protected final int depth; -   protected final String[] attributes; -   protected final OutputFile output; +   /** Static *****************************************************************/ +   private static XPathExpression XPE_FIND_EXPR_NAMED_ENTITIES; -   public VHDLNode -   ( -      final OutputFile output, -      final IDs parent_id, -      final Node xml_node, -      final IDs next_node, -      final int depth, -      final String[] attributes -   ) +   static     { -      super(parent_id, xml_node); - -      this.output = output; -      this.next_node = next_node; -      this.depth = depth; -      this.attributes = attributes; +      XPE_FIND_EXPR_NAMED_ENTITIES = +         XMLManager.compile_or_die +         ( +            ".//named_entity" +         );     }     protected void handle_expression     (        final IDs local_id, -      final Node expression_ref +      final Node expression_start     )     throws XPathExpressionException     {        final String ref; -      ref = XMLManager.get_attribute(expression_ref, "ref"); +      ref = XMLManager.get_attribute(expression_start, "ref");        if (!Main.node_is_function_or_literal(ref))        {           Predicates.add_entry           (              output, -            predicate, +            "expr_reads",              local_id,              Waveforms.get_associated_waveform_id              ( @@ -52,4 +42,29 @@ public abstract class VHDLNode extends ParsableXML           );        }     } + +   /** Non-Static *************************************************************/ +   protected final IDs next_node; +   protected final int depth; +   protected final String[] attributes; +   protected final OutputFile output; + +   public VHDLNode +   ( +      final OutputFile output, +      final IDs parent_id, +      final Node xml_node, +      final IDs next_node, +      final int depth, +      final String[] attributes +   ) +   { +      super(parent_id, xml_node); + +      this.output = output; +      this.next_node = next_node; +      this.depth = depth; +      this.attributes = attributes; +   } +  } diff --git a/ast-to-instr/src/VHDLSSASNode.java b/ast-to-instr/src/VHDLSSASNode.java index c67c3f2..05d8af0 100644 --- a/ast-to-instr/src/VHDLSSASNode.java +++ b/ast-to-instr/src/VHDLSSASNode.java @@ -22,7 +22,7 @@ public class VHDLSSASNode extends VHDLNode        XPE_FIND_SOURCES =           XMLManager.compile_or_die           ( -            "./waveform_chain//named_entity" +            "./waveform_chain"/* //named_entity" */           );        XPE_FIND_PREFIXED_NE = XMLManager.compile_or_die("./prefix/named_entity"); @@ -164,22 +164,16 @@ public class VHDLSSASNode extends VHDLNode     )     throws XPathExpressionException     { -      final NodeList sources; -      final int sources_count; +      final Node sources;        sources = -         (NodeList) XPE_FIND_SOURCES.evaluate +         (Node) XPE_FIND_SOURCES.evaluate           (              xml_node, -            XPathConstants.NODESET +            XPathConstants.NODE           ); -      sources_count = sources.getLength(); - -      for (int i = 0; i < sources_count; ++i) -      { -         handle_expression("expr_reads", local_id, sources.item(0)); -      } +      handle_expression(local_id, sources);     }     private void handle_predicate_expr_writes diff --git a/ast-to-instr/src/VHDLWNode.java b/ast-to-instr/src/VHDLWNode.java index 06a903c..66d0c00 100644 --- a/ast-to-instr/src/VHDLWNode.java +++ b/ast-to-instr/src/VHDLWNode.java @@ -10,15 +10,15 @@ import java.util.Stack;  /* When Node */  public class VHDLWNode extends VHDLNode  { -   private static final XPathExpression XPE_FIND_NAMED_ENTITIES; +   private static final XPathExpression XPE_FIND_SOURCES;     private static final XPathExpression XPE_FIND_BODY;     static     { -      XPE_FIND_NAMED_ENTITIES = +      XPE_FIND_SOURCES =           XMLManager.compile_or_die           ( -            "./choice_expression//named_entity" +            "./choice_expression" /* //named_entity" */           );        XPE_FIND_BODY = @@ -159,38 +159,16 @@ public class VHDLWNode extends VHDLNode     )     throws XPathExpressionException     { -      final NodeList named_entities; -      final int named_entities_count; +      final Node sources; -      named_entities = -         (NodeList) XPE_FIND_NAMED_ENTITIES.evaluate +      sources = +         (Node) XPE_FIND_SOURCES.evaluate           (              xml_node, -            XPathConstants.NODESET +            XPathConstants.NODE           ); -      named_entities_count = named_entities.getLength(); - -      for (int i = 0; i < named_entities_count; ++i) -      { -         final String ref; - -         ref = XMLManager.get_attribute(named_entities.item(0), "ref"); - -         if (!Main.node_is_function_or_literal(ref)) -         { -            Predicates.add_entry -            ( -               output, -               "expr_reads", -               local_id, -               Waveforms.get_associated_waveform_id -               ( -                  IDs.get_id_from_xml_id(ref, (String) null) -               ) -            ); -         } -      } +      handle_expression(local_id, sources);     }     /***************************************************************************/ | 


