From 814367acffe9c02eb5ca545af9d4eee5782c07a7 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 25 May 2018 08:07:26 +0200 Subject: Got it running. --- Makefile | 8 +- src/ghdl2hastabel/Expressions.java | 430 ------------------------------ src/ghdl2hastabel/IDs.java | 53 +++- src/ghdl2hastabel/Strings.java | 56 ---- src/ghdl2hastabel/vhdl/.Node.java.swp | Bin 12288 -> 0 bytes src/ghdl2hastabel/vhdl/Architecture.java | 7 +- src/ghdl2hastabel/vhdl/CSNode.java | 8 +- src/ghdl2hastabel/vhdl/Component.java | 7 +- src/ghdl2hastabel/vhdl/Entity.java | 7 +- src/ghdl2hastabel/vhdl/Expressions.java | 431 +++++++++++++++++++++++++++++++ src/ghdl2hastabel/vhdl/File.java | 3 +- src/ghdl2hastabel/vhdl/Generic.java | 7 +- src/ghdl2hastabel/vhdl/ISNode.java | 7 +- src/ghdl2hastabel/vhdl/Node.java | 10 +- src/ghdl2hastabel/vhdl/Port.java | 9 +- src/ghdl2hastabel/vhdl/Process.java | 9 +- src/ghdl2hastabel/vhdl/SSASNode.java | 7 +- src/ghdl2hastabel/vhdl/Signal.java | 9 +- src/ghdl2hastabel/vhdl/WNode.java | 7 +- 19 files changed, 518 insertions(+), 557 deletions(-) delete mode 100644 src/ghdl2hastabel/Expressions.java delete mode 100644 src/ghdl2hastabel/Strings.java delete mode 100644 src/ghdl2hastabel/vhdl/.Node.java.swp create mode 100644 src/ghdl2hastabel/vhdl/Expressions.java diff --git a/Makefile b/Makefile index 49f6b10..db10a58 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ BIN_DIR ?= ${CURDIR}/bin/ LIB_DIR ?= ${CURDIR}/lib/ TARGET ?= ghdl2hastabel.jar +RUN_SCRIPT ?= ghdl2hastabel.sh INSTALL_DIR ?= $(LIB_DIR) #### Where to get the missing Jar files. @@ -41,7 +42,7 @@ JAVA_SOURCES = \ CLASSES = $(patsubst $(SRC_DIR)/%,$(BIN_DIR)/%, $(JAVA_SOURCES:.java=.class)) ## Makefile Rules ############################################################## -$(TARGET): $(JAVA_SOURCES) $(CLASSES) +$(TARGET): $(RUN_SCRIPT) $(JAVA_SOURCES) $(CLASSES) $(MAKE) $(LIB_DIR) rm -f $(TARGET) $(INSTALL_DIR)/$@ $(JAR) cf $@ -C $(BIN_DIR) . @@ -59,6 +60,11 @@ $(CLASSES): $(BIN_DIR)/%.class: $(SRC_DIR)/%.java $(BIN_DIR) echo "Attempting to download missing jar '$@'..." cd $(LIB_DIR); $(DOWNLOADER) "$(JAR_SOURCE)/$(notdir $@)" +$(RUN_SCRIPT): Makefile + echo "#!/bin/sh" > $@ + echo "$(JAVA) -cp \"$(CLASSPATH)\" ghdl2hastabel.Main \$$*" >> $@ + chmod +x $@ + $(LIB_DIR): mkdir -p $@ diff --git a/src/ghdl2hastabel/Expressions.java b/src/ghdl2hastabel/Expressions.java deleted file mode 100644 index 3c8f547..0000000 --- a/src/ghdl2hastabel/Expressions.java +++ /dev/null @@ -1,430 +0,0 @@ -package ghdl2hastabel; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; - -public class Expressions -{ - private static final XPathExpression XPE_GET_LEFT_SIDE; - private static final XPathExpression XPE_GET_RIGHT_SIDE; - private static final XPathExpression XPE_GET_OPERAND; - private static final XPathExpression XPE_GET_FUN_PARAMETERS; - private static final XPathExpression XPE_GET_INDEX_LIST; - private static final XPathExpression XPE_GET_NAMED_ENTITY; - private static final XPathExpression XPE_GET_PREFIX_NAMED_ENTITY; - private static final XPathExpression XPE_GET_PREFIX; - - static - { - XPE_GET_LEFT_SIDE = XMLManager.compile_or_die("./left"); - XPE_GET_RIGHT_SIDE = XMLManager.compile_or_die("./right"); - XPE_GET_OPERAND = XMLManager.compile_or_die("./operand"); - - XPE_GET_FUN_PARAMETERS = - XMLManager.compile_or_die - ( - "./parameter_association_chain/el/actual" - ); - - XPE_GET_INDEX_LIST = XMLManager.compile_or_die("./index_list/el"); - - XPE_GET_NAMED_ENTITY = XMLManager.compile_or_die("./named_entity"); - XPE_GET_PREFIX_NAMED_ENTITY = - XMLManager.compile_or_die - ( - "./prefix/named_entity" - ); - - XPE_GET_PREFIX = XMLManager.compile_or_die("./prefix"); - } - - 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", "abs", false), - - NOT("not_operator", "not", false), - - CONDITION("condition_operator", "???", true), /* FIXME: what's this? */ - - /* Flattens vectors using an operator. */ - REDUCTION_AND("reduction_and_operator", "and", false), - REDUCTION_OR("reduction_or_operator", "or", false), - REDUCTION_NAND("reduction_nand_operator", "nand", false), - REDUCTION_NOR("reduction_nor_operator", "nor", false), - REDUCTION_XOR("reduction_xor_operator", "xor", false), - REDUCTION_XNOR("reduction_xnor_operator", "xnor", false), - - AND("and_operator", "and", true), - OR("or_operator", "or", true), - NAND("nand_operator", "nand", true), - NOR("nor_operator", "nor", true), - XOR("xor_operator", "xor", true), - XNOR("xnor_operator", "xnor", 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", "sll", true), - SLA("sla_operator", "sla", true), - SRL("srl_operator", "srl", true), - SRA("sra_operator", "sra", true), - ROL("rol_operator", "rol", true), - ROR("ror_operator", "ror", true), - - ADDITION("addition_operator", "+", true), - SUBSTRACTION("substraction_operator", "-", true), - CONCATENATION("concatenation_operator", "&", true), - MULTIPLICATION("multiplication_operator", "*", true), - DIVISION("division_operator", "/", true), - MODULUS("modulus_operator", "mod", true), - REMAINDER("remainder_operator", "rem", true), - EXPONENTIATION("exponentiation_operator", "**", true); - - /** Static **************************************************************/ - private static final Map FROM_TAG; - - static - { - final Operator operators[]; - - FROM_TAG = new HashMap(); - - 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 String symbol; - private final boolean is_binary; - - private Operator - ( - final String tag, - final String symbol, - final boolean is_binary - ) - { - this.tag = tag; - this.symbol = symbol; - this.is_binary = is_binary; - } - } - - public static void process - ( - final List elements, - final StringBuilder structure, - final Node current_node - ) - throws XPathExpressionException - { - final String kind; - final Operator op; - - kind = XMLManager.get_attribute(current_node, "kind"); - - op = Operator.FROM_TAG.get(kind); - - if (op == null) - { - process_non_operator(elements, structure, current_node, kind); - } - else if (op.is_binary) - { - structure.append("(?"); - elements.add - ( - Strings.get_id_from_string - ( - op.symbol - ) - ); - - process - ( - elements, - structure, - (Node) XPE_GET_LEFT_SIDE.evaluate - ( - current_node, - XPathConstants.NODE - ) - ); - - process - ( - elements, - structure, - (Node) XPE_GET_RIGHT_SIDE.evaluate - ( - current_node, - XPathConstants.NODE - ) - ); - - structure.append(")"); - } - else - { - structure.append("(?"); - elements.add - ( - Strings.get_id_from_string - ( - op.symbol - ) - ); - - process - ( - elements, - structure, - (Node) XPE_GET_OPERAND.evaluate - ( - current_node, - XPathConstants.NODE - ) - ); - - structure.append(")"); - } - } - - public static void process_non_operator - ( - final List elements, - final StringBuilder structure, - final Node current_node, - final String kind - ) - throws XPathExpressionException - { - if (kind.equals("simple_name")) - { - final Node named_entity; - - named_entity = - (Node) XPE_GET_NAMED_ENTITY.evaluate - ( - current_node, - XPathConstants.NODE - ); - - structure.append("?"); - - elements.add - ( - Waveforms.get_associated_waveform_id - ( - IDs.get_id_from_xml_id - ( - XMLManager.get_attribute(named_entity, "ref"), - null - ) - ) - ); - } - else if (kind.equals("function_call")) - { - final Node named_entity; - final NodeList params; - final int params_length; - - named_entity = - (Node) XPE_GET_PREFIX/*_NAMED_ENTITY*/.evaluate - ( - current_node, - XPathConstants.NODE - ); - - structure.append("(?"); - - /* - * TODO: Handle functions better, like: - elements.add - ( - IDs.get_id_from_xml_id - ( - XMLManager.get_attribute(named_entity, "ref"), - null - ) - ); - * But for now, we'll just use the function's name as string: - */ - elements.add - ( - Strings.get_id_from_string - ( - XMLManager.get_attribute(named_entity, "identifier") - ) - ); - - - params = - (NodeList) XPE_GET_FUN_PARAMETERS.evaluate - ( - current_node, - XPathConstants.NODESET - ); - - params_length = params.getLength(); - - for (int i = 0; i < params_length; ++i) - { - process - ( - elements, - structure, - params.item(i) - ); - } - - structure.append(")"); - } - else if (kind.equals("indexed_name")) /* vector */ - { - final Node named_entity; - final NodeList params; - final int params_length; - - named_entity = - (Node) XPE_GET_PREFIX_NAMED_ENTITY.evaluate - ( - current_node, - XPathConstants.NODE - ); - - structure.append("(?"); - - elements.add - ( - Waveforms.get_associated_waveform_id - ( - IDs.get_id_from_xml_id - ( - XMLManager.get_attribute(named_entity, "ref"), - null - ) - ) - ); - - params = - (NodeList) XPE_GET_INDEX_LIST.evaluate - ( - current_node, - XPathConstants.NODESET - ); - - params_length = params.getLength(); - - for (int i = 0; i < params_length; ++i) - { - process - ( - elements, - structure, - params.item(i) - ); - } - - structure.append(")"); - } - else if (kind.contains("literal")) - { - /* - grep "Kind.*Literal" ./src/vhdl/nodes_meta.adb | sort | uniq -u - points to: - "character_literal"; - "enumeration_literal"; - "floating_point_literal"; - "integer_literal"; - "null_literal"; - "overflow_literal"; - "physical_fp_literal"; - "physical_int_literal"; - "physical_literal"; (unsure if it can happen) - "string_literal8"; - - They don't all use the same structure, so we're going to handle them - later. - TODO - */ - - structure.append("?"); - elements.add - ( - Strings.get_id_from_string - ( - "l" - ) - ); - - } - else if (kind.contains("attribute")) - { - structure.append("(?"); - - elements.add - ( - Strings.get_id_from_string - ( - /* FIXME: Kind of a hacky */ - kind.replace("_attribute", "") - ) - ); - - process - ( - elements, - structure, - (Node) XPE_GET_PREFIX.evaluate - ( - current_node, - XPathConstants.NODE - ) - ); - - structure.append(")"); - } - } -} diff --git a/src/ghdl2hastabel/IDs.java b/src/ghdl2hastabel/IDs.java index 23bdafb..9bcc05c 100644 --- a/src/ghdl2hastabel/IDs.java +++ b/src/ghdl2hastabel/IDs.java @@ -37,6 +37,21 @@ public class IDs ); } + public static IDs get_id_from_string + ( + String string + ) + { + if (string == null) + { + string = ""; + } + + string = "\"" + string.toLowerCase() + "\""; + + return new IDs(string, true); + } + public static IDs get_id_from_xml_id ( final OutputFile output, @@ -54,11 +69,10 @@ public class IDs FROM_XML.put(xml_id, result); - XML_MAP_OUTPUT.write("(xml->instr "); + XML_MAP_OUTPUT.write("xml->instr "); XML_MAP_OUTPUT.write(xml_id); - XML_MAP_OUTPUT.write(" "); - XML_MAP_OUTPUT.write(Integer.toString(result.get_value())); - XML_MAP_OUTPUT.write(")"); + XML_MAP_OUTPUT.write("->"); + XML_MAP_OUTPUT.write(result.get_value()); XML_MAP_OUTPUT.insert_newline(); } @@ -89,7 +103,7 @@ public class IDs { final IDs result; - result = new IDs(type); + result = new IDs(type, false); if (type != null) { @@ -100,16 +114,24 @@ public class IDs } /** Non-Static *************************************************************/ - private final int value; + private final String value; private String type; - private IDs (final String type) + private IDs (final String type_or_val, boolean is_string) { - this.type = type; + if (is_string) + { + type = "string"; + value = type_or_val; + } + else + { + type = type_or_val; - value = IDs.next_id; + value = Integer.toString(IDs.next_id); - IDs.next_id += 1; + IDs.next_id += 1; + } } public String get_type () @@ -117,18 +139,21 @@ public class IDs return type; } - public int get_value () + public String get_value () { return value; } private void add_to_output (final OutputFile output) { - output.write("(add_element "); + if (type.equals("string")) + { + return; + } + output.write(type); output.write(" "); - output.write(Integer.toString(value)); - output.write(")"); + output.write(value); output.insert_newline(); } } diff --git a/src/ghdl2hastabel/Strings.java b/src/ghdl2hastabel/Strings.java deleted file mode 100644 index 68e17e9..0000000 --- a/src/ghdl2hastabel/Strings.java +++ /dev/null @@ -1,56 +0,0 @@ -package ghdl2hastabel; - -import java.util.Map; -import java.util.HashMap; - -public class Strings -{ - private static final Map TO_ID; - private static final OutputFile STRING_MAP_OUTPUT; - - static - { - TO_ID = new HashMap(); - - /* TODO: filename as a param? */ - STRING_MAP_OUTPUT = OutputFile.new_output_file("string_to_instr.map"); - } - - private Strings () {} /* Utility class. */ - - public static IDs get_id_from_string - ( - final String string - ) - { - return get_id_from_string(Main.get_main_output(), string); - } - - public static IDs get_id_from_string - ( - final OutputFile output, - String string - ) - { - IDs result; - - string = string.toLowerCase(); - result = TO_ID.get(string); - - if (result == null) - { - result = IDs.generate_new_id(output, "string"); - - TO_ID.put(string, result); - - STRING_MAP_OUTPUT.write("(string->instr \""); - STRING_MAP_OUTPUT.write(string); - STRING_MAP_OUTPUT.write("\" "); - STRING_MAP_OUTPUT.write(Integer.toString(result.get_value())); - STRING_MAP_OUTPUT.write(")"); - STRING_MAP_OUTPUT.insert_newline(); - } - - return result; - } -} diff --git a/src/ghdl2hastabel/vhdl/.Node.java.swp b/src/ghdl2hastabel/vhdl/.Node.java.swp deleted file mode 100644 index 942ae52..0000000 Binary files a/src/ghdl2hastabel/vhdl/.Node.java.swp and /dev/null differ diff --git a/src/ghdl2hastabel/vhdl/Architecture.java b/src/ghdl2hastabel/vhdl/Architecture.java index 36a6819..3b4f42c 100644 --- a/src/ghdl2hastabel/vhdl/Architecture.java +++ b/src/ghdl2hastabel/vhdl/Architecture.java @@ -2,7 +2,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; -import ghdl2hastabel.Strings; import ghdl2hastabel.ParsableXML; import ghdl2hastabel.XMLManager; import ghdl2hastabel.IDs; @@ -160,7 +159,7 @@ public class Architecture extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -176,7 +175,7 @@ public class Architecture extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -192,7 +191,7 @@ public class Architecture extends ParsableXML ( "identifier", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "identifier") ) diff --git a/src/ghdl2hastabel/vhdl/CSNode.java b/src/ghdl2hastabel/vhdl/CSNode.java index bb36824..b359b41 100644 --- a/src/ghdl2hastabel/vhdl/CSNode.java +++ b/src/ghdl2hastabel/vhdl/CSNode.java @@ -2,7 +2,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Depths; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; import ghdl2hastabel.ParsableXML; @@ -109,9 +108,8 @@ public class CSNode extends ghdl2hastabel.vhdl.Node output, "label", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( - output, XMLManager.get_attribute(xml_node, "label") ) ); @@ -127,7 +125,7 @@ public class CSNode extends ghdl2hastabel.vhdl.Node output, "kind", local_id, - Strings.get_id_from_string("case") + IDs.get_id_from_string("case") ); } @@ -160,7 +158,7 @@ public class CSNode extends ghdl2hastabel.vhdl.Node output, "has_option", local_id, - Strings.get_id_from_string(s) + IDs.get_id_from_string(s) ); } } diff --git a/src/ghdl2hastabel/vhdl/Component.java b/src/ghdl2hastabel/vhdl/Component.java index 8c2d4fe..92dc785 100644 --- a/src/ghdl2hastabel/vhdl/Component.java +++ b/src/ghdl2hastabel/vhdl/Component.java @@ -1,7 +1,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Main; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -286,7 +285,7 @@ public class Component extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -302,7 +301,7 @@ public class Component extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -318,7 +317,7 @@ public class Component extends ParsableXML ( "label", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "label") ) diff --git a/src/ghdl2hastabel/vhdl/Entity.java b/src/ghdl2hastabel/vhdl/Entity.java index 607a0d9..c347c2c 100644 --- a/src/ghdl2hastabel/vhdl/Entity.java +++ b/src/ghdl2hastabel/vhdl/Entity.java @@ -1,6 +1,5 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Strings; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; import ghdl2hastabel.ParsableXML; @@ -103,7 +102,7 @@ public class Entity extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -119,7 +118,7 @@ public class Entity extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -135,7 +134,7 @@ public class Entity extends ParsableXML ( "identifier", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) diff --git a/src/ghdl2hastabel/vhdl/Expressions.java b/src/ghdl2hastabel/vhdl/Expressions.java new file mode 100644 index 0000000..88b5d0e --- /dev/null +++ b/src/ghdl2hastabel/vhdl/Expressions.java @@ -0,0 +1,431 @@ +package ghdl2hastabel.vhdl; + +import ghdl2hastabel.IDs; +import ghdl2hastabel.XMLManager; +import ghdl2hastabel.Waveforms; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +public class Expressions +{ + private static final XPathExpression XPE_GET_LEFT_SIDE; + private static final XPathExpression XPE_GET_RIGHT_SIDE; + private static final XPathExpression XPE_GET_OPERAND; + private static final XPathExpression XPE_GET_FUN_PARAMETERS; + private static final XPathExpression XPE_GET_INDEX_LIST; + private static final XPathExpression XPE_GET_NAMED_ENTITY; + private static final XPathExpression XPE_GET_PREFIX_NAMED_ENTITY; + private static final XPathExpression XPE_GET_PREFIX; + + static + { + XPE_GET_LEFT_SIDE = XMLManager.compile_or_die("./left"); + XPE_GET_RIGHT_SIDE = XMLManager.compile_or_die("./right"); + XPE_GET_OPERAND = XMLManager.compile_or_die("./operand"); + + XPE_GET_FUN_PARAMETERS = + XMLManager.compile_or_die + ( + "./parameter_association_chain/el/actual" + ); + + XPE_GET_INDEX_LIST = XMLManager.compile_or_die("./index_list/el"); + + XPE_GET_NAMED_ENTITY = XMLManager.compile_or_die("./named_entity"); + XPE_GET_PREFIX_NAMED_ENTITY = + XMLManager.compile_or_die + ( + "./prefix/named_entity" + ); + + XPE_GET_PREFIX = XMLManager.compile_or_die("./prefix"); + } + + 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", "abs", false), + + NOT("not_operator", "not", false), + + CONDITION("condition_operator", "???", true), /* FIXME: what's this? */ + + /* Flattens vectors using an operator. */ + REDUCTION_AND("reduction_and_operator", "and", false), + REDUCTION_OR("reduction_or_operator", "or", false), + REDUCTION_NAND("reduction_nand_operator", "nand", false), + REDUCTION_NOR("reduction_nor_operator", "nor", false), + REDUCTION_XOR("reduction_xor_operator", "xor", false), + REDUCTION_XNOR("reduction_xnor_operator", "xnor", false), + + AND("and_operator", "and", true), + OR("or_operator", "or", true), + NAND("nand_operator", "nand", true), + NOR("nor_operator", "nor", true), + XOR("xor_operator", "xor", true), + XNOR("xnor_operator", "xnor", 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", "sll", true), + SLA("sla_operator", "sla", true), + SRL("srl_operator", "srl", true), + SRA("sra_operator", "sra", true), + ROL("rol_operator", "rol", true), + ROR("ror_operator", "ror", true), + + ADDITION("addition_operator", "+", true), + SUBSTRACTION("substraction_operator", "-", true), + CONCATENATION("concatenation_operator", "&", true), + MULTIPLICATION("multiplication_operator", "*", true), + DIVISION("division_operator", "/", true), + MODULUS("modulus_operator", "mod", true), + REMAINDER("remainder_operator", "rem", true), + EXPONENTIATION("exponentiation_operator", "**", true); + + /** Static **************************************************************/ + private static final Map FROM_TAG; + + static + { + final Operator operators[]; + + FROM_TAG = new HashMap(); + + 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 String symbol; + private final boolean is_binary; + + private Operator + ( + final String tag, + final String symbol, + final boolean is_binary + ) + { + this.tag = tag; + this.symbol = symbol; + this.is_binary = is_binary; + } + } + + public static void process + ( + final List elements, + final StringBuilder structure, + final Node current_node + ) + throws XPathExpressionException + { + final String kind; + final Operator op; + + kind = XMLManager.get_attribute(current_node, "kind"); + + op = Operator.FROM_TAG.get(kind); + + if (op == null) + { + process_non_operator(elements, structure, current_node, kind); + } + else if (op.is_binary) + { + structure.append("(?"); + elements.add + ( + IDs.get_id_from_string + ( + op.symbol + ) + ); + + process + ( + elements, + structure, + (Node) XPE_GET_LEFT_SIDE.evaluate + ( + current_node, + XPathConstants.NODE + ) + ); + + process + ( + elements, + structure, + (Node) XPE_GET_RIGHT_SIDE.evaluate + ( + current_node, + XPathConstants.NODE + ) + ); + + structure.append(")"); + } + else + { + structure.append("(?"); + elements.add + ( + IDs.get_id_from_string + ( + op.symbol + ) + ); + + process + ( + elements, + structure, + (Node) XPE_GET_OPERAND.evaluate + ( + current_node, + XPathConstants.NODE + ) + ); + + structure.append(")"); + } + } + + public static void process_non_operator + ( + final List elements, + final StringBuilder structure, + final Node current_node, + final String kind + ) + throws XPathExpressionException + { + if (kind.equals("simple_name")) + { + final Node named_entity; + + named_entity = + (Node) XPE_GET_NAMED_ENTITY.evaluate + ( + current_node, + XPathConstants.NODE + ); + + structure.append("?"); + + elements.add + ( + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id + ( + XMLManager.get_attribute(named_entity, "ref"), + null + ) + ) + ); + } + else if (kind.equals("function_call")) + { + final Node named_entity; + final NodeList params; + final int params_length; + + named_entity = + (Node) XPE_GET_PREFIX/*_NAMED_ENTITY*/.evaluate + ( + current_node, + XPathConstants.NODE + ); + + structure.append("(?"); + + /* + * TODO: Handle functions better, like: + elements.add + ( + IDs.get_id_from_xml_id + ( + XMLManager.get_attribute(named_entity, "ref"), + null + ) + ); + * But for now, we'll just use the function's name as string: + */ + elements.add + ( + IDs.get_id_from_string + ( + XMLManager.get_attribute(named_entity, "identifier") + ) + ); + + + params = + (NodeList) XPE_GET_FUN_PARAMETERS.evaluate + ( + current_node, + XPathConstants.NODESET + ); + + params_length = params.getLength(); + + for (int i = 0; i < params_length; ++i) + { + process + ( + elements, + structure, + params.item(i) + ); + } + + structure.append(")"); + } + else if (kind.equals("indexed_name")) /* vector */ + { + final Node named_entity; + final NodeList params; + final int params_length; + + named_entity = + (Node) XPE_GET_PREFIX_NAMED_ENTITY.evaluate + ( + current_node, + XPathConstants.NODE + ); + + structure.append("(?"); + + elements.add + ( + Waveforms.get_associated_waveform_id + ( + IDs.get_id_from_xml_id + ( + XMLManager.get_attribute(named_entity, "ref"), + null + ) + ) + ); + + params = + (NodeList) XPE_GET_INDEX_LIST.evaluate + ( + current_node, + XPathConstants.NODESET + ); + + params_length = params.getLength(); + + for (int i = 0; i < params_length; ++i) + { + process + ( + elements, + structure, + params.item(i) + ); + } + + structure.append(")"); + } + else if (kind.contains("literal")) + { + /* + grep "Kind.*Literal" ./src/vhdl/nodes_meta.adb | sort | uniq -u + points to: + "character_literal"; + "enumeration_literal"; + "floating_point_literal"; + "integer_literal"; + "null_literal"; + "overflow_literal"; + "physical_fp_literal"; + "physical_int_literal"; + "physical_literal"; (unsure if it can happen) + "string_literal8"; + + They don't all use the same structure, so we're going to handle them + later. + TODO + */ + + structure.append("?"); + elements.add + ( + IDs.get_id_from_string("l") + ); + + } + else if (kind.contains("attribute")) + { + structure.append("(?"); + + elements.add + ( + IDs.get_id_from_string + ( + /* FIXME: Kind of a hacky */ + kind.replace("_attribute", "") + ) + ); + + process + ( + elements, + structure, + (Node) XPE_GET_PREFIX.evaluate + ( + current_node, + XPathConstants.NODE + ) + ); + + structure.append(")"); + } + } +} diff --git a/src/ghdl2hastabel/vhdl/File.java b/src/ghdl2hastabel/vhdl/File.java index c321eb2..8f38ba2 100644 --- a/src/ghdl2hastabel/vhdl/File.java +++ b/src/ghdl2hastabel/vhdl/File.java @@ -1,6 +1,5 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Strings; import ghdl2hastabel.Functions; import ghdl2hastabel.ParsableXML; import ghdl2hastabel.XMLManager; @@ -80,7 +79,7 @@ public class File extends ParsableXML ( "filename", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "file") ) diff --git a/src/ghdl2hastabel/vhdl/Generic.java b/src/ghdl2hastabel/vhdl/Generic.java index 3b86585..4710118 100644 --- a/src/ghdl2hastabel/vhdl/Generic.java +++ b/src/ghdl2hastabel/vhdl/Generic.java @@ -1,6 +1,5 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -86,7 +85,7 @@ public class Generic extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -102,7 +101,7 @@ public class Generic extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -118,7 +117,7 @@ public class Generic extends ParsableXML ( "identifier", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "identifier") ) diff --git a/src/ghdl2hastabel/vhdl/ISNode.java b/src/ghdl2hastabel/vhdl/ISNode.java index d09a815..9aa3c61 100644 --- a/src/ghdl2hastabel/vhdl/ISNode.java +++ b/src/ghdl2hastabel/vhdl/ISNode.java @@ -2,7 +2,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Depths; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; import ghdl2hastabel.ParsableXML; @@ -108,7 +107,7 @@ public class ISNode extends ghdl2hastabel.vhdl.Node output, "label", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "label") ) @@ -125,7 +124,7 @@ public class ISNode extends ghdl2hastabel.vhdl.Node output, "kind", local_id, - Strings.get_id_from_string("if") + IDs.get_id_from_string("if") ); } @@ -158,7 +157,7 @@ public class ISNode extends ghdl2hastabel.vhdl.Node output, "has_option", local_id, - Strings.get_id_from_string(s) + IDs.get_id_from_string(s) ); } } diff --git a/src/ghdl2hastabel/vhdl/Node.java b/src/ghdl2hastabel/vhdl/Node.java index 3469277..88c545c 100644 --- a/src/ghdl2hastabel/vhdl/Node.java +++ b/src/ghdl2hastabel/vhdl/Node.java @@ -1,8 +1,6 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Expressions; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Predicates; import ghdl2hastabel.ParsableXML; import ghdl2hastabel.IDs; @@ -58,7 +56,7 @@ public abstract class Node extends ParsableXML output, "is_read_structure", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( structure.toString() ) @@ -73,7 +71,7 @@ public abstract class Node extends ParsableXML output, "is_read_element", local_id, - Strings.get_id_from_string(Integer.toString(i)), + IDs.get_id_from_string(Integer.toString(i)), elements.get(i) ); @@ -107,7 +105,7 @@ public abstract class Node extends ParsableXML output, "is_written_structure", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( structure.toString() ) @@ -122,7 +120,7 @@ public abstract class Node extends ParsableXML output, "is_written_element", local_id, - Strings.get_id_from_string(Integer.toString(i)), + IDs.get_id_from_string(Integer.toString(i)), elements.get(i) ); diff --git a/src/ghdl2hastabel/vhdl/Port.java b/src/ghdl2hastabel/vhdl/Port.java index f1a30e6..9dd2e1a 100644 --- a/src/ghdl2hastabel/vhdl/Port.java +++ b/src/ghdl2hastabel/vhdl/Port.java @@ -1,6 +1,5 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -92,7 +91,7 @@ public class Port extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -108,7 +107,7 @@ public class Port extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -124,7 +123,7 @@ public class Port extends ParsableXML ( "identifier", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "identifier") ) @@ -332,7 +331,7 @@ public class Port extends ParsableXML ( "has_mode", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute ( diff --git a/src/ghdl2hastabel/vhdl/Process.java b/src/ghdl2hastabel/vhdl/Process.java index 9f1a5f4..b821885 100644 --- a/src/ghdl2hastabel/vhdl/Process.java +++ b/src/ghdl2hastabel/vhdl/Process.java @@ -1,7 +1,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -112,7 +111,7 @@ public class Process extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -128,7 +127,7 @@ public class Process extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -144,7 +143,7 @@ public class Process extends ParsableXML ( "label", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "label") ) @@ -436,7 +435,7 @@ public class Process extends ParsableXML OutputFile.new_output_file ( "cfg_" /* TODO: Prefix as parameter? */ - + Integer.toString(local_id.get_value()) + + local_id.get_value() + ".mod" /* TODO: Suffix as parameter? */ ), local_id, diff --git a/src/ghdl2hastabel/vhdl/SSASNode.java b/src/ghdl2hastabel/vhdl/SSASNode.java index f5571a8..f7db666 100644 --- a/src/ghdl2hastabel/vhdl/SSASNode.java +++ b/src/ghdl2hastabel/vhdl/SSASNode.java @@ -3,7 +3,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Depths; import ghdl2hastabel.Main; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -104,7 +103,7 @@ public class SSASNode extends ghdl2hastabel.vhdl.Node output, "label", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "label") ) @@ -121,7 +120,7 @@ public class SSASNode extends ghdl2hastabel.vhdl.Node output, "kind", local_id, - Strings.get_id_from_string("signal_assignement") + IDs.get_id_from_string("signal_assignement") ); } @@ -154,7 +153,7 @@ public class SSASNode extends ghdl2hastabel.vhdl.Node output, "has_option", local_id, - Strings.get_id_from_string(s) + IDs.get_id_from_string(s) ); } } diff --git a/src/ghdl2hastabel/vhdl/Signal.java b/src/ghdl2hastabel/vhdl/Signal.java index 6812529..f09c998 100644 --- a/src/ghdl2hastabel/vhdl/Signal.java +++ b/src/ghdl2hastabel/vhdl/Signal.java @@ -1,6 +1,5 @@ package ghdl2hastabel.vhdl; -import ghdl2hastabel.Strings; import ghdl2hastabel.Waveforms; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; @@ -90,7 +89,7 @@ public class Signal extends ParsableXML ( "line", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "line") ) @@ -106,7 +105,7 @@ public class Signal extends ParsableXML ( "column", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "col") ) @@ -122,7 +121,7 @@ public class Signal extends ParsableXML ( "identifier", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute(xml_node, "identifier") ) @@ -285,7 +284,7 @@ public class Signal extends ParsableXML ( "is_of_kind", local_id, - Strings.get_id_from_string + IDs.get_id_from_string ( XMLManager.get_attribute ( diff --git a/src/ghdl2hastabel/vhdl/WNode.java b/src/ghdl2hastabel/vhdl/WNode.java index cc3864a..03bb0d5 100644 --- a/src/ghdl2hastabel/vhdl/WNode.java +++ b/src/ghdl2hastabel/vhdl/WNode.java @@ -2,7 +2,6 @@ package ghdl2hastabel.vhdl; import ghdl2hastabel.Depths; import ghdl2hastabel.OutputFile; -import ghdl2hastabel.Strings; import ghdl2hastabel.Functions; import ghdl2hastabel.Predicates; import ghdl2hastabel.ParsableXML; @@ -100,7 +99,7 @@ public class WNode extends ghdl2hastabel.vhdl.Node output, "label", local_id, - Strings.get_id_from_string("") + IDs.get_id_from_string("") ); } @@ -114,7 +113,7 @@ public class WNode extends ghdl2hastabel.vhdl.Node output, "kind", local_id, - Strings.get_id_from_string("when") + IDs.get_id_from_string("when") ); } @@ -147,7 +146,7 @@ public class WNode extends ghdl2hastabel.vhdl.Node output, "has_option", local_id, - Strings.get_id_from_string(s) + IDs.get_id_from_string(s) ); } } -- cgit v1.2.3-70-g09d2