| summaryrefslogtreecommitdiff | 
path: root/instance-calculator
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 15:23:34 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 15:23:34 +0200 | 
| commit | 9a5e79dfd1c6829b052ab7cf0cb7a79afd25eb72 (patch) | |
| tree | dfa287746b7a714cd6c1af2c04d7e2fd4d189d08 /instance-calculator | |
| parent | 35e6857fb09b006da9f8cc3f59f239f078cc69a1 (diff) | |
Should now load the model.
Diffstat (limited to 'instance-calculator')
| -rw-r--r-- | instance-calculator/src/ModelFile.java | 91 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLArchitecture.java | 74 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLComponent.java | 51 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLEntity.java | 54 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLProcess.java | 47 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLWaveform.java | 36 | ||||
| -rw-r--r-- | instance-calculator/src/Waveforms.java | 10 | 
7 files changed, 292 insertions, 71 deletions
| diff --git a/instance-calculator/src/ModelFile.java b/instance-calculator/src/ModelFile.java index 691de1a..929c348 100644 --- a/instance-calculator/src/ModelFile.java +++ b/instance-calculator/src/ModelFile.java @@ -145,12 +145,28 @@ public class ModelFile        final String[] input     )     { +      final VHDLProcess ps; +      final VHDLWaveform wfm; +        if (input.length != 3)        {           return false;        } -      return VHDLProcess.handle_is_accessed_by(input[1], input[2]); +      ps = VHDLProcess.get_from_id(input[2]); +      wfm = VHDLWaveform.find(input[1]); + +      if (wfm != null) +      { +         /* +          * Assumes that otherwise it's a string, but that could also be due to +          * an inconsistent model. +          */ + +         ps.add_accessed_wfm(wfm); +      } + +      return true;     }     private static boolean handle_is_waveform_of @@ -178,7 +194,9 @@ public class ModelFile           return false;        } -      return VHDLEntity.handle_is_port_of(input[1], input[2]); +      VHDLEntity.get_from_id(input[2]).add_port(input[1]); + +      return true;     }     private static boolean handle_is_architecture_of @@ -186,12 +204,21 @@ public class ModelFile        final String[] input     )     { +      final VHDLEntity e; +      final VHDLArchitecture arch; +        if (input.length != 3)        {           return false;        } -      return VHDLArchitecture.handle_is_architecture_of(input[1], input[2]); +      e = VHDLEntity.get_from_id(input[2]); +      arch = VHDLArchitecture.get_from_id(input[1]); + +      e.set_architecture(arch); +      arch.set_entity(e); + +      return true;     }     private static boolean handle_belongs_to_architecture @@ -199,13 +226,52 @@ public class ModelFile        final String[] input     )     { +      final VHDLArchitecture arch; +      final VHDLProcess ps; +      final VHDLComponent cmp; +      final String wfm_id; +      final VHDLWaveform wfm; +        if (input.length != 3)        {           return false;        } -      return -         VHDLArchitecture.handle_belongs_to_architecture(input[1], input[2]); +      arch = VHDLArchitecture.get_from_id(input[2]); + +      ps = VHDLProcess.find(input[1]); + +      if (ps != null) +      { +         arch.add_process(ps); +         ps.set_architecture(arch); + +         return true; +      } + +      cmp = VHDLComponent.find(input[1]); + +      if (cmp != null) +      { +         arch.add_component(cmp); +         cmp.set_architecture(arch); + +         return true; +      } + +      wfm_id = Waveforms.find_waveform_id_from_id(input[1]); + +      if (wfm_id != null) +      { +         wfm = VHDLWaveform.get_from_id(wfm_id); + +         arch.add_waveform(wfm); +         wfm.set_architecture(arch); + +         return true; +      } + +      return true;     }     private static boolean handle_is_component_of @@ -218,7 +284,12 @@ public class ModelFile           return false;        } -      return VHDLComponent.handle_is_component_of(input[1], input[2]); +      VHDLComponent.get_from_id(input[1]).set_destination +      ( +         VHDLEntity.get_from_id(input[2]) +      ); + +      return true;     }     private static boolean handle_port_maps @@ -231,7 +302,13 @@ public class ModelFile           return false;        } -      return VHDLComponent.handle_port_maps(input[1], input[2], input[3]); +      VHDLComponent.get_from_id(input[1]).add_port_map +      ( +         input[2], +         input[3] +      ); + +      return true;     }     private ModelFile () {} /* Utility Class */ diff --git a/instance-calculator/src/VHDLArchitecture.java b/instance-calculator/src/VHDLArchitecture.java index 7f3be10..0a61a24 100644 --- a/instance-calculator/src/VHDLArchitecture.java +++ b/instance-calculator/src/VHDLArchitecture.java @@ -17,29 +17,37 @@ public class VHDLArchitecture        }     } -   public static boolean handle_belongs_to_architecture -   ( -      final String unknown_id, -      final String arch_id -   ) +   public static VHDLArchitecture get_from_id (final String id)     { -      /* TODO */ -      return false; +      final VHDLArchitecture result; + +      result = FROM_ID.get(id); + +      if (result == null) +      { +         System.err.println +         ( +            "[E] Element " +            + id +            + " is used like an architecture, but is not declared as such" +            + " before that use." +         ); + +         System.exit(-1); +      } + +      return result;     } -   public static boolean handle_is_architecture_of -   ( -      final String arch_id, -      final String e_id -   ) +   public static VHDLArchitecture find (final String id)     { -      /* TODO */ -      return false; +      return FROM_ID.get(id);     }  /******************************************************************************/ -   private final List<String> processes; -   private final List<String> components; +   private final Collection<VHDLProcess> processes; +   private final Collection<VHDLComponent> components; +   private final Collection<VHDLWaveform> waveforms;     private final String id;     private VHDLEntity entity; @@ -48,12 +56,42 @@ public class VHDLArchitecture     {        this.id = id; -      processes = new ArrayList<String>(); -      components = new ArrayList<String>(); +      processes = new ArrayList<VHDLProcess>(); +      components = new ArrayList<VHDLComponent>(); +      waveforms = new ArrayList<VHDLWaveform>();     }     public VHDLEntity get_entity ()     {        return entity;     } + +   public void set_entity (final VHDLEntity e) +   { +      entity = e; +   } + +   public void add_process (final VHDLProcess ps) +   { +      if (!processes.contains(ps)) +      { +         processes.add(ps); +      } +   } + +   public void add_component (final VHDLComponent cmp) +   { +      if (!components.contains(cmp)) +      { +         components.add(cmp); +      } +   } + +   public void add_waveform (final VHDLWaveform wfm) +   { +      if (!waveforms.contains(wfm)) +      { +         waveforms.add(wfm); +      } +   }  } diff --git a/instance-calculator/src/VHDLComponent.java b/instance-calculator/src/VHDLComponent.java index 5972173..b0f8de2 100644 --- a/instance-calculator/src/VHDLComponent.java +++ b/instance-calculator/src/VHDLComponent.java @@ -17,25 +17,31 @@ public class VHDLComponent        }     } -   public static boolean handle_is_component_of -   ( -      final String cmp_id, -      final String e_id -   ) +   public static VHDLComponent get_from_id (final String id)     { -      /* TODO */ -      return false; +      final VHDLComponent result; + +      result = FROM_ID.get(id); + +      if (result == null) +      { +         System.err.println +         ( +            "[E] Element " +            + id +            + " is used like a component instantiation, but is not declared as" +            + " such before that use." +         ); + +         System.exit(-1); +      } + +      return result;     } -   public static boolean handle_port_maps -   ( -      final String cmp_id, -      final String pt_id, -      final String wfm_id -   ) +   public static VHDLComponent find (final String id)     { -      /* TODO */ -      return false; +      return FROM_ID.get(id);     }  /******************************************************************************/ @@ -45,6 +51,21 @@ public class VHDLComponent     private VHDLEntity destination;     private VHDLArchitecture parent; +   public void set_destination (final VHDLEntity dest) +   { +      destination = dest; +   } + +   public void set_architecture (final VHDLArchitecture arch) +   { +      parent = arch; +   } + +   public void add_port_map (final String src, final String dest) +   { +      port_map.put(src, dest); +   } +     public void add_instance_content_to     (        final Collection<VHDLProcess.Instance> process_instances, diff --git a/instance-calculator/src/VHDLEntity.java b/instance-calculator/src/VHDLEntity.java index 8059566..e5ab4eb 100644 --- a/instance-calculator/src/VHDLEntity.java +++ b/instance-calculator/src/VHDLEntity.java @@ -17,44 +17,66 @@ public class VHDLEntity        }     } -   public static boolean handle_is_port_of -   ( -      final String pt_id, -      final String e_id -   ) +   public static VHDLEntity get_from_id (final String id)     { -      /* TODO */ -      return false; +      final VHDLEntity result; + +      result = FROM_ID.get(id); + +      if (result == null) +      { +         System.err.println +         ( +            "[E] Element " +            + id +            + " is used like an entity, but is not declared as such before that" +            + " use." +         ); + +         System.exit(-1); +      } + +      return result;     } -   public static boolean handle_is_architecture_of -   ( -      final String pt_id, -      final String e_id -   ) +   public static VHDLEntity find (final String id)     { -      /* TODO */ -      return false; +      return FROM_ID.get(id);     }  /******************************************************************************/     private final Collection<VHDLProcess.Instance> process_instances;     private final Collection<VHDLWaveform.Instance> waveform_instances; -   private final List<String> ports; +   private final Collection<String> ports;     private final String id; -   private String architecture; +   private VHDLArchitecture architecture;     private VHDLEntity (final String id)     {        this.id = id;        ports = new ArrayList<String>(); +      architecture = null; +        this.process_instances = new ArrayList<VHDLProcess.Instance>();        this.waveform_instances = new ArrayList<VHDLWaveform.Instance>();     } +   public void add_port (final String pt) +   { +      if (!ports.contains(pt)) +      { +         ports.add(pt); +      } +   } + +   public void set_architecture (final VHDLArchitecture arch) +   { +      architecture = arch; +   } +     public Collection<VHDLProcess.Instance> get_process_instances ()     {        return process_instances; diff --git a/instance-calculator/src/VHDLProcess.java b/instance-calculator/src/VHDLProcess.java index f85fe9a..5466dbb 100644 --- a/instance-calculator/src/VHDLProcess.java +++ b/instance-calculator/src/VHDLProcess.java @@ -17,14 +17,31 @@ public class VHDLProcess        }     } -   public static boolean handle_is_accessed_by -   ( -      final String wfm_id, -      final String ps_id -   ) +   public static VHDLProcess get_from_id (final String id)     { -      /* TODO */ -      return false; +      final VHDLProcess result; + +      result = FROM_ID.get(id); + +      if (result == null) +      { +         System.err.println +         ( +            "[E] Element " +            + id +            + " is used like a process, but is not declared as such before that" +            + " use." +         ); + +         System.exit(-1); +      } + +      return result; +   } + +   public static VHDLProcess find (final String id) +   { +      return FROM_ID.get(id);     }  /******************************************************************************/ @@ -33,12 +50,28 @@ public class VHDLProcess     private final String id;     private int instances_count; +   private VHDLArchitecture architecture; +     private VHDLProcess (final String id)     {        this.id = id;        accessed_wfm = new ArrayList<VHDLWaveform>();        instances = new ArrayList<VHDLProcess.Instance>();        instances_count = 0; +      architecture = null; +   } + +   public void add_accessed_wfm (final VHDLWaveform wfm) +   { +      if (!accessed_wfm.contains(wfm)) +      { +         accessed_wfm.add(wfm); +      } +   } + +   public void set_architecture (final VHDLArchitecture arch) +   { +      architecture = arch;     }     public static class Instance diff --git a/instance-calculator/src/VHDLWaveform.java b/instance-calculator/src/VHDLWaveform.java index 83b9626..1f29b99 100644 --- a/instance-calculator/src/VHDLWaveform.java +++ b/instance-calculator/src/VHDLWaveform.java @@ -19,17 +19,29 @@ public class VHDLWaveform     public static VHDLWaveform get_from_id (final String id)     { -      return FROM_ID.get(id); +      final VHDLWaveform result; + +      result = FROM_ID.get(id); + +      if (result == null) +      { +         System.err.println +         ( +            "[E] Element " +            + id +            + " is used like a waveform, but is not declared as such before" +            + " that use." +         ); + +         System.exit(-1); +      } + +      return result;     } -   public static boolean handle_is_accessed_by -   ( -      final String wfm_id, -      final String ps_id -   ) +   public static VHDLWaveform find (final String id)     { -      /* TODO */ -      return false; +      return FROM_ID.get(id);     }  /******************************************************************************/ @@ -38,12 +50,15 @@ public class VHDLWaveform     private final String id;     private int instances_count; +   private VHDLArchitecture architecture; +     private VHDLWaveform (final String id)     {        this.id = id;        accessed_wfm = new ArrayList<String>();        instances = new ArrayList<VHDLWaveform.Instance>();        instances_count = 0; +      architecture = null;     }     public VHDLWaveform.Instance add_instance @@ -73,6 +88,11 @@ public class VHDLWaveform        return id;     } +   public void set_architecture (final VHDLArchitecture arch) +   { +      architecture = arch; +   } +     public static class Instance     {        private final String id; diff --git a/instance-calculator/src/Waveforms.java b/instance-calculator/src/Waveforms.java index e7a4c8c..9492d16 100644 --- a/instance-calculator/src/Waveforms.java +++ b/instance-calculator/src/Waveforms.java @@ -61,4 +61,14 @@ public class Waveforms        return result;     } + +   public static String find_id_from_waveform_id (final String wfm_id) +   { +      return FROM_WAVEFORM.get(wfm_id); +   } + +   public static String find_waveform_id_from_id (final String src_id) +   { +      return TO_WAVEFORM.get(src_id); +   }  } | 


