| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'instr-to-kodkod/src')
| -rw-r--r-- | instr-to-kodkod/src/Main.java | 112 | ||||
| -rw-r--r-- | instr-to-kodkod/src/Parameters.java | 4 | ||||
| -rw-r--r-- | instr-to-kodkod/src/QuickParser.java | 6 | ||||
| -rw-r--r-- | instr-to-kodkod/src/VHDLModel.java | 25 | ||||
| -rw-r--r-- | instr-to-kodkod/src/VHDLType.java | 5 | 
5 files changed, 148 insertions, 4 deletions
| diff --git a/instr-to-kodkod/src/Main.java b/instr-to-kodkod/src/Main.java index 5b0e9b5..b835c28 100644 --- a/instr-to-kodkod/src/Main.java +++ b/instr-to-kodkod/src/Main.java @@ -8,6 +8,7 @@ import kodkod.engine.satlab.*;  import kodkod.instance.*;  import java.io.IOException; +import java.io.FileNotFoundException;  import java.util.Iterator;  public class Main @@ -15,6 +16,7 @@ public class Main     private static Parameters PARAMETERS;     private static VHDLModel MODEL;     private static VariableManager VARIABLE_MANAGER; +   private static StringManager STRING_MANAGER;     public static VHDLModel get_model ()     { @@ -26,6 +28,11 @@ public class Main        return VARIABLE_MANAGER;     } +   public static StringManager get_string_manager () +   { +      return STRING_MANAGER; +   } +     private static boolean load_levels ()     {        for (final String lvl: PARAMETERS.get_level_files()) @@ -113,6 +120,103 @@ public class Main        return true;     } +   private static boolean load_mapping_file (final String filename) +   throws FileNotFoundException +   { +      final QuickParser qp; +      String[] input; +      boolean success; + +      qp = new QuickParser(filename); + +      for (;;) +      { +         try +         { +            input = qp.parse_line(); + +            if (input == null) +            { +               qp.finalize(); + +               return false; +            } +            else if (input.length == 0) +            { +               qp.finalize(); + +               break; +            } +         } +         catch (final IOException e) +         { +            System.err.println +            ( +               "[E] IO error while parsing file \"" +               + filename +               + "\":" +               /* FIXME: can be null */ +               + e.getMessage() +            ); + +            return false; +         } + +         if +         ( +            (!STRING_MANAGER.handle_mapping_instruction(input)) +            /* && (!_____.handle_mapping_instruction(input)) */ +            /* Yeah, we don't handle those */ +            && (!input[0].equals("xml->instr")) +         ) +         { +            System.err.println +            ( +               "[E] An erroneous instruction was found in file \"" +               + filename +               + "\"." +            ); + +            try +            { +               qp.finalize(); +            } +            catch (final Exception e) +            { +               System.err.println("[E] Additionally:"); +               e.printStackTrace(); +            } + +            return false; +         } +      } + +      return true; +   } + +   private static boolean load_mappings () +   { +      try +      { +         for (final String file: PARAMETERS.get_mapping_files()) +         { +            if (!load_mapping_file(file)) +            { +               return false; +            } +         } +      } +      catch (final Exception e) +      { +         System.err.println("[F] Could not load mappings:"); +         e.printStackTrace(); + +         System.exit(-1); +      } + +      return true; +   } +     public static void main (final String... args)     {        /* @@ -147,6 +251,14 @@ public class Main           return;        } +      /* 2/ Load Mappings (to allow references in the property). */ +      STRING_MANAGER = new StringManager(); + +      if (!load_mappings()) +      { +         return; +      } +        /* 2/ Load Properties (will change 'is_used()' on predicates) */        /* FIXME? Currently only one property, due to the 'is_used' */        property = load_property(); diff --git a/instr-to-kodkod/src/Parameters.java b/instr-to-kodkod/src/Parameters.java index c3fcd51..d3bc0f1 100644 --- a/instr-to-kodkod/src/Parameters.java +++ b/instr-to-kodkod/src/Parameters.java @@ -128,9 +128,9 @@ public class Parameters        return model_files;     } -   public List<String> get_map_files () +   public List<String> get_mapping_files ()     { -      return model_files; +      return map_files;     }     public String get_property_file () diff --git a/instr-to-kodkod/src/QuickParser.java b/instr-to-kodkod/src/QuickParser.java index 47cea27..7a63c43 100644 --- a/instr-to-kodkod/src/QuickParser.java +++ b/instr-to-kodkod/src/QuickParser.java @@ -10,7 +10,11 @@ public class QuickParser     static     { -      instr_pattern = Pattern.compile("\\((?<list>[a-z_0-9 \"]+)\\)"); +      instr_pattern = +         Pattern.compile +         ( +            "\\(([a-z_0-9\\->]+ .*)\\)" +         );     }     public QuickParser (final String filename)     throws FileNotFoundException diff --git a/instr-to-kodkod/src/VHDLModel.java b/instr-to-kodkod/src/VHDLModel.java index 7a9671e..ea024b8 100644 --- a/instr-to-kodkod/src/VHDLModel.java +++ b/instr-to-kodkod/src/VHDLModel.java @@ -350,4 +350,29 @@ public class VHDLModel           return t.get_as_relation();        }     } + +   public Relation get_atom_as_relation +   ( +      final String type, +      final String id +   ) +   { +      final VHDLType t; + +      t = types.get(type); + +      if (t == null) +      { +         return null; +      } +      else +      { +         return t.get_member_as_relation(id); +      } +   } + +   public VHDLType get_string_type () +   { +      return types.get("string"); +   }  } diff --git a/instr-to-kodkod/src/VHDLType.java b/instr-to-kodkod/src/VHDLType.java index 58b0d1e..46d7cd9 100644 --- a/instr-to-kodkod/src/VHDLType.java +++ b/instr-to-kodkod/src/VHDLType.java @@ -25,7 +25,10 @@ public class VHDLType     public void add_member (final String id)     { -      members.put(id, Relation.unary(id)); +      if (!members.containsKey(id)) +      { +         members.put(id, Relation.unary(id)); +      }     }     public String get_name () | 


