summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-06-01 14:36:49 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-06-01 14:36:49 +0200
commitd628ee226cb6fc6408794bd9d7f09f86ed37112a (patch)
tree930991a83debf8d9207bc07afb7df1ab2ba82c6a
downloadhastabel-sol-printer-master.zip
hastabel-sol-printer-master.tar.bz2
Starting a Solution Printing tool for HaStABeL...HEADmaster
-rw-r--r--Makefile87
-rw-r--r--src/Manifest.txt2
-rw-r--r--src/hastabel_sol_printer/Main.java180
-rw-r--r--src/hastabel_sol_printer/Parameters.java108
4 files changed, 377 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..59a9825
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,87 @@
+## Parameters ##################################################################
+SRC_DIR ?= ${CURDIR}/src/
+BIN_DIR ?= ${CURDIR}/bin/
+LIB_DIR ?= ${CURDIR}/lib/
+TMP_DIR ?= /tmp/hastabel_sol_printer_standalone.jar.build/
+
+TARGET ?= hastabel_sol_printer.jar
+STANDALONE ?= hastabel_sol_printer_standalone.jar
+INSTALL_DIR ?= $(LIB_DIR)
+
+#### Where to get the missing Jar files.
+JAR_SOURCE ?= "https://noot-noot.org/tabellion/jar/"
+
+#### Binaries
+###### JAR binary
+JAR ?= jar
+
+###### JRE binary
+JAVA ?= java
+
+###### JDK binary
+JAVAC ?= javac
+
+###### HASTABEL
+HASTABEL_JAR ?= $(LIB_DIR)/hastabel_standalone.jar
+
+##### Downloader
+DOWNLOADER ?= wget
+
+## Parameters Sanity Check #####################################################
+ifeq ($(strip $(JAVA)),)
+$(error No Java executable defined as parameter.)
+endif
+
+ifeq ($(strip $(JAVAC)),)
+$(error No Java compiler defined as parameter.)
+endif
+
+ifeq ($(strip $(HASTABEL_JAR)),)
+$(error No HASTABEL_JAR defined as parameter.)
+endif
+
+## Java Config #################################################################
+CLASSPATH = "$(SRC_DIR):$(BIN_DIR):$(ANTLR_JAR):$(HASTABEL_JAR)"
+
+## Makefile Magic ##############################################################
+MANIFEST = $(SRC_DIR)/Manifest.txt
+
+JAVA_SOURCES = $(shell find $(SRC_DIR)/hastabel_sol_printer/ -name "*.java")
+CLASSES = $(patsubst $(SRC_DIR)/%,$(BIN_DIR)/%, $(JAVA_SOURCES:.java=.class))
+
+## Makefile Rules ##############################################################
+$(STANDALONE): $(TMP_DIR) $(TARGET) $(ANTLR_JAR)
+ unzip -d $(TMP_DIR) -uo $(TARGET)
+ unzip -d $(TMP_DIR) -uo $(HASTABEL_JAR)
+ jar -cvfm $@ $(MANIFEST) -C $(TMP_DIR) .
+
+$(TARGET): $(HASTABEL_JAR) $(JAVA_SOURCES) $(CLASSES) $(MANIFEST)
+ rm -f $(TARGET) $(INSTALL_DIR)/$@
+ $(JAR) cfm $@ $(MANIFEST) -C $(BIN_DIR) .
+ cp $@ $(INSTALL_DIR)/$@
+
+clean:
+ rm -rf $(BIN_DIR)/*
+ rm -f $(TARGET)
+
+$(CLASSES): $(BIN_DIR)/%.class: $(SRC_DIR)/%.java $(BIN_DIR)
+ $(JAVAC) -cp $(CLASSPATH) -d $(BIN_DIR) $<
+
+%.jar:
+ $(MAKE) $(LIB_DIR)
+ echo "Attempting to download missing jar '$@'..."
+ cd $(LIB_DIR); $(DOWNLOADER) "$(JAR_SOURCE)/$(notdir $@)"
+
+$(TMP_DIR):
+ mkdir -p $@
+
+$(LIB_DIR):
+ mkdir -p $@
+
+$(BIN_DIR):
+ mkdir -p $@
+
+##### For my private use...
+publish: $(TARGET) $(STANDALONE)
+ scp $^ dreamhost:~/noot-noot/tabellion/jar/
+
diff --git a/src/Manifest.txt b/src/Manifest.txt
new file mode 100644
index 0000000..8bd29f3
--- /dev/null
+++ b/src/Manifest.txt
@@ -0,0 +1,2 @@
+Main-Class: hastabel_sol_printer.Main
+
diff --git a/src/hastabel_sol_printer/Main.java b/src/hastabel_sol_printer/Main.java
new file mode 100644
index 0000000..6b0d906
--- /dev/null
+++ b/src/hastabel_sol_printer/Main.java
@@ -0,0 +1,180 @@
+package hastabel_sol_printer;
+
+import hastabel.World;
+import hastabel.lang.Formula;
+import hastabel.lang.Element;
+import hastabel.lang.Predicate;
+import hastabel.lang.Type;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import java.util.stream.Collectors;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class Main
+{
+
+ public static void main (final String... args)
+ {
+ final Map<String, Map<Element, Element>> str_funs;
+ final Map<Element, Element> waveforms;
+ final Parameters params;
+ final World world;
+
+ str_funs = new HashMap<String, Map<Element, Element>>();
+ waveforms = new HashMap<Element, Element>();
+
+ System.out.println("#### HaStABeL Solutions Pretty Printer ####");
+ System.out.println("# Parsing parameters...");
+
+ params = new Parameters(args);
+
+ if (!params.are_valid())
+ {
+ return;
+ }
+
+ world = new World();
+
+ System.out.println("# Loading model...");
+
+ load_model(world, params);
+
+ if (!world.is_valid())
+ {
+ System.out.println("# Failure.");
+
+ return;
+ }
+
+ /** FIXME: Waveforms are VHDL specific. **/
+ System.out.println("# Isolating waveforms & string functions.");
+ //isolate_waveforms(world, waveforms);
+ //string_functions(world, waveforms, str_funs);
+
+ /* I don't think this is needed */
+ //System.out.println("# Modeling graphs in first-order...");
+ //world.ensure_first_order();
+
+ for (final String pred_name: params.get_target_predicates())
+ {
+ final String pp_file;
+
+ pp_file = params.get_pretty_print_file_for(pred_name);
+
+ if (pp_file == null)
+ {
+ System.err.println
+ (
+ "[E] Could not find pretty print file for predicate \""
+ + pred_name
+ + "\"."
+ );
+ }
+ else
+ {
+ print_solutions_of(world, pred_name, pp_file);
+ }
+ }
+ }
+
+ private static void print_solutions_of
+ (
+ final World world,
+ final String pred_name,
+ final String pp_file
+ )
+ {
+ final List<String> naming;
+ final Predicate pred;
+ final String pp_template;
+
+ pred = world.get_predicates_manager().get(pred_name);
+ pp_template = null; //file_to_pp_template(pp_file);
+
+ if (pred == null)
+ {
+ System.err.println("[E] Could not find predicate \"" + pred + "\".");
+
+ return;
+ }
+
+ if (pp_template == null)
+ {
+ return;
+ }
+
+ naming = pred.get_naming();
+
+ for (final List<Element> member: pred.get_members())
+ {
+ for (int i = (member.size() - 1); i >= 0; i--)
+ {
+ }
+ }
+ }
+
+ private static void load_file (final World world, final String filename)
+ {
+ try
+ {
+ System.out.println("# Loading \"" + filename + "\"...");
+ world.load(filename);
+ }
+ catch (final IOException ioe)
+ {
+ System.err.println
+ (
+ "[E] IOException when loading \""
+ + filename
+ + "\":\n"
+ + ioe.getMessage()
+ );
+
+ world.invalidate();
+ }
+ }
+
+ private static void load_model
+ (
+ final World world,
+ final Parameters params
+ )
+ {
+ for (final String level_file: params.get_level_files())
+ {
+ load_file(world, level_file);
+
+ if (!world.is_valid())
+ {
+ return;
+ }
+ }
+
+ for (final String model_file: params.get_model_files())
+ {
+ load_file(world, model_file);
+
+ if (!world.is_valid())
+ {
+ return;
+ }
+ }
+ }
+
+ private static void isolate_waveforms
+ (
+ final World world,
+ final Map<Element, Element> waveforms
+ )
+ {
+ final Predicate is_waveform_of;
+
+ is_waveform_of = world.get_predicates_manager().get("is_waveform_of");
+ }
+}
diff --git a/src/hastabel_sol_printer/Parameters.java b/src/hastabel_sol_printer/Parameters.java
new file mode 100644
index 0000000..9b70d6e
--- /dev/null
+++ b/src/hastabel_sol_printer/Parameters.java
@@ -0,0 +1,108 @@
+package hastabel_sol_printer;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import java.io.File;
+
+public class Parameters
+{
+ private final List<String> level_files;
+ private final List<String> model_files;
+ private final Map<String, String> pretty_print_files;
+ private final List<String> target_predicates;
+ private final boolean are_valid;
+
+ public static void print_usage ()
+ {
+ System.out.println
+ (
+ "HaStABeL to IDP\n"
+ + "USAGE:\n"
+ + "\tjava -jar hastabel_sol_printer.jar <FILES>+\n"
+ + "PARAMETERS:\n"
+ + "\t- <FILES>\tList of files to be loaded.\n"
+ + "NOTES:\n"
+ + "\t- Property files have a \".pro\" extension.\n"
+ + "\t- Model files have a \".mod\" extension.\n"
+ + "\t- Level files have a \".lvl\" extension.\n"
+ + "\t- Pretty Printing template files have a \".pp\" extension.\n"
+ + "\t- The files may be given in any order."
+ + "\t- Only content relevant to what is in the \".sol.mod\" and "
+ + "\".sol.lvl\" files will be printer."
+ );
+ }
+
+ public Parameters (final String... args)
+ {
+ boolean has_error;
+
+ level_files = new ArrayList<String>();
+ model_files = new ArrayList<String>();
+ pretty_print_files = new HashMap<String, String>();
+ target_predicates = new ArrayList<String>();
+
+ has_error = false;
+
+ for (int i = 0; i < args.length; ++i)
+ {
+ if (args[i].endsWith(".sol.mod"))
+ {
+ target_predicates.add("???" /* TODO: get pred name from filename */);
+ model_files.add(args[i]);
+ }
+ else if (args[i].endsWith(".lvl"))
+ {
+ level_files.add(args[i]);
+ }
+ else if (args[i].endsWith(".mod"))
+ {
+ model_files.add(args[i]);
+ }
+ else if (args[i].endsWith(".pp"))
+ {
+ pretty_print_files.put("???", args[i]);
+ }
+ else
+ {
+ System.err.println
+ (
+ "[E] Unknown file type \""
+ + args[i]
+ + "\"."
+ );
+
+ has_error = true;
+ }
+ }
+
+ are_valid = !has_error;
+ }
+
+ public List<String> get_level_files ()
+ {
+ return level_files;
+ }
+
+ public String get_pretty_print_file_for (final String str)
+ {
+ return pretty_print_files.get(str);
+ }
+
+ public List<String> get_model_files ()
+ {
+ return model_files;
+ }
+
+ public List<String> get_target_predicates ()
+ {
+ return target_predicates;
+ }
+
+ public boolean are_valid ()
+ {
+ return are_valid;
+ }
+}