| summaryrefslogtreecommitdiff | 
path: root/sol_pretty_printer
diff options
Diffstat (limited to 'sol_pretty_printer')
| -rw-r--r-- | sol_pretty_printer/src/Main.java | 14 | ||||
| -rw-r--r-- | sol_pretty_printer/src/Parameters.java | 125 | ||||
| -rw-r--r-- | sol_pretty_printer/src/QuickParser.java | 58 | ||||
| -rw-r--r-- | sol_pretty_printer/src/SolutionItem.java | 56 | ||||
| -rw-r--r-- | sol_pretty_printer/src/Waveforms.java | 40 | 
5 files changed, 293 insertions, 0 deletions
| diff --git a/sol_pretty_printer/src/Main.java b/sol_pretty_printer/src/Main.java new file mode 100644 index 0000000..21aebcb --- /dev/null +++ b/sol_pretty_printer/src/Main.java @@ -0,0 +1,14 @@ +public class Main +{ +   private static Parameters PARAMETERS; + +   public static void main (final String... args) +   { +      PARAMETERS = new Parameters(args); + +      if (!PARAMETERS.are_valid()) +      { +         return; +      } +   } +} diff --git a/sol_pretty_printer/src/Parameters.java b/sol_pretty_printer/src/Parameters.java new file mode 100644 index 0000000..6d64e27 --- /dev/null +++ b/sol_pretty_printer/src/Parameters.java @@ -0,0 +1,125 @@ +import java.util.List; +import java.util.ArrayList; + +public class Parameters +{ +   private final List<String> sol_files; +   private final List<String> pp_files; +   private final List<String> model_files; + +   private final boolean are_valid; + +   public static void print_usage () +   { +      System.out.println +      ( +         "Sol-Pretty-Printer\n" +         + "USAGE:\n" +         + "\tjava Main <MODEL_FILE>+ <SOL_AND_PP_FILES>+\n" +         + "PARAMETERS:\n" +         + "\t- <MODEL_FILE>\tInstr. model files.\n" +         + "\t- <SOL_AND_PP_FILES>\tOne solution file, followed by one pretty" +         + " print file." +         + "NOTES:\n" +         + "\t- Model files have a \".mod\" extension.\n" +         + "\t- Solution files have a \".sol\" extension.\n" +         + "\t- Pretty-print files have a \".pp\" extension.\n" +         + "\t- Solution files may contain any number of solutions.\n" +      ); +   } + +   public Parameters (final String... args) +   { +      boolean has_error, prev_was_a_sol; + +      model_files = new ArrayList<String>(); +      sol_files = new ArrayList<String>(); +      pp_files = new ArrayList<String>(); + +      if (args.length < 2) +      { +         print_usage(); + +         are_valid = false; + +         return; +      } + +      has_error = false; +      prev_was_a_sol = false; + +      for (int i = 1; i < args.length; ++i) +      { +         if (args[i].endsWith(".mod")) +         { +            model_files.add(args[i]); +         } +         else if (args[i].endsWith(".sol")) +         { +            sol_files.add(args[i]); + +            if (prev_was_a_sol) +            { +               System.err.println +               ( +                  "[F] Two solution files followed one another. You must give" +                  + "<SOLUTION_FILE> <PRETTY_PRINT_FILE> pairs as parameters." +               ); + +               System.exit(-1); +            } + +            prev_was_a_sol = true; +         } +         else if (args[i].endsWith(".pp")) +         { +            if (!prev_was_a_sol) +            { +               System.err.println +               ( +                  "[F] Two pretty print files followed one another. You must" +                  + " give <SOLUTION_FILE> <PRETTY_PRINT_FILE> pairs as" +                  + " parameters." +               ); + +               System.exit(-1); +            } + +            prev_was_a_sol = false; +         } +         else +         { +            System.err.println +            ( +               "[E] Unknown file type \"" +               + args[i] +               + "\"." +            ); + +            has_error = true; +         } +      } + +      are_valid = !has_error; +   } + +   public List<String> get_model_files () +   { +      return model_files; +   } + +   public List<String> get_solution_files () +   { +      return sol_files; +   } + +   public List<String> get_pretty_print_files () +   { +      return pp_files; +   } + +   public boolean are_valid () +   { +      return are_valid; +   } +} diff --git a/sol_pretty_printer/src/QuickParser.java b/sol_pretty_printer/src/QuickParser.java new file mode 100644 index 0000000..47cea27 --- /dev/null +++ b/sol_pretty_printer/src/QuickParser.java @@ -0,0 +1,58 @@ +/* FIXME: Finer imports */ +import java.io.*; +import java.util.regex.*; +import java.util.*; + +public class QuickParser +{ +   private static final Pattern instr_pattern; +   private final BufferedReader buffered_reader; + +   static +   { +      instr_pattern = Pattern.compile("\\((?<list>[a-z_0-9 \"]+)\\)"); +   } +   public QuickParser (final String filename) +   throws FileNotFoundException +   { +      buffered_reader = new BufferedReader(new FileReader(filename)); +   } + +   public void finalize () +   throws IOException +   { +      buffered_reader.close(); +   } + +   public String[] parse_line () +   throws IOException +   { +      final List<String> result; +      final Matcher matcher; +      String line; + +      do +      { +         line = buffered_reader.readLine(); + +         if (line == null) +         { +            return new String[0]; +         } + +         line = line.replaceAll("\\s+"," "); +      } +      while (line.length() < 3 || line.startsWith(";")); + +      matcher = instr_pattern.matcher(line); + +      if (!matcher.find()) +      { +         System.err.println("[E] Invalid instruction \"" + line + "\""); + +         return null; +      } + +      return matcher.group(1).split(" |\t"); +   } +} diff --git a/sol_pretty_printer/src/SolutionItem.java b/sol_pretty_printer/src/SolutionItem.java new file mode 100644 index 0000000..122dd04 --- /dev/null +++ b/sol_pretty_printer/src/SolutionItem.java @@ -0,0 +1,56 @@ +import java.util.Map; +import java.util.HashMap; + +public class SolutionItem +{ +   private static final Map<String, SolutionItem> FROM_ID; + +   static +   { +      FROM_ID = new HashMap<String, SolutionItem>(); +   } + + +   public static void handle_unary_set_function +   ( +      final String function, +      final String id, +      final String value +   ) +   { +      SolutionItem si; + +      si = FROM_ID.get(id); + +      if (id == null) +      { +         si = new SolutionItem(id); + +         FROM_ID.put(id, si); +      } + +      si.function_values.put(function.toLowerCase(), value); +   } + +   public static SolutionItem get_item_from_id (final String id) +   { +      return FROM_ID.get(id); +   } + +   /** Non-Static *************************************************************/ +   private final Map<String, String> function_values; + +   private SolutionItem +   ( +      final String id +   ) +   { +      function_values = new HashMap<String, String>(); +      function_values.put("id", id); +   } + +   public String get_function_value (final String fun) +   { +      return function_values.get(fun); +   } +} diff --git a/sol_pretty_printer/src/Waveforms.java b/sol_pretty_printer/src/Waveforms.java new file mode 100644 index 0000000..3a40869 --- /dev/null +++ b/sol_pretty_printer/src/Waveforms.java @@ -0,0 +1,40 @@ +import java.util.Map; +import java.util.HashMap; + +public class Waveforms +{ +   private static final Map<String, String> FROM_WAVEFORM; + +   static +   { +      FROM_WAVEFORM = new HashMap<String, String>(); +   } + +   private Waveforms () {} /* Utility class. */ + +   public static void register_map (final String wfm_id, final String elem_id) +   { +      FROM_WAVEFORM.put(wfm_id, elem_id); +   } + +   public static String get_id_from_waveform_id (final String wfm_id) +   { +      final String result; + +      result = FROM_WAVEFORM.get(wfm_id); + +      if (result == null) +      { +         System.err.println +         ( +            "[F] There is no element associated with waveform \"" +            + wfm_id +            + "\". Is the model complete?" +         ); + +         System.exit(-1); +      } + +      return result; +   } +} | 


