dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / mapping / Mapping.java
diff --git a/dol/src/dol/datamodel/mapping/Mapping.java b/dol/src/dol/datamodel/mapping/Mapping.java
new file mode 100644 (file)
index 0000000..c0123a5
--- /dev/null
@@ -0,0 +1,274 @@
+package dol.datamodel.mapping;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import dol.datamodel.architecture.Architecture;
+import dol.datamodel.architecture.Processor;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.visitor.MapVisitor;
+
+    
+/**
+ * This class defines a mapping.
+ */    
+public class Mapping extends MapResource
+{
+    public Mapping(String name)
+    {
+        super(name);
+        _compBindList = new Vector<ComputationBinding>();
+        _commBindList = new Vector<CommunicationBinding>();
+        _scheduleList = new Vector<Schedule>();
+        _variableList = new Vector<Variable>();
+        /**
+         * For some code generation back end, traversing via architecture
+         * model rather than mapping model is more convenient, since the 
+         * mapping model is a flattened view of the binding where one can
+         * not access all the binded processes from a processor. Therefore
+         * we annotate the binding information back to processor.
+         */
+        _processList = new Vector<Process>();
+        _processorList = new Vector<Processor>();
+    }
+
+    /**
+     * Accept a visitor
+     *
+     * @param x visitor object
+     */
+    public void accept(MapVisitor x) {
+        x.visitComponent(this);
+    }
+    
+    
+    /**
+     * Clone this Mapping.
+     *
+     * @return new instance of the Mapping
+     */
+    @SuppressWarnings("unchecked")
+    public Object clone() {
+        Mapping newObj = (Mapping) super.clone();
+        newObj.setCompBindList((Vector<ComputationBinding>)_compBindList.clone());
+        newObj.setCommBindList((Vector<CommunicationBinding>)_commBindList.clone());
+        newObj.setScheduleList((Vector<Schedule>)_scheduleList.clone());
+        newObj.setVarList((Vector<Variable>)_variableList.clone());
+        newObj.setProcessorList((Vector<Processor>)_processorList.clone());
+        newObj.setProcessList((Vector<Process>)_processList.clone());
+        return (newObj);
+    }
+    
+    /** Get the process network. */
+    public ProcessNetwork getPN() { return _pn; }
+    
+    /** Store a reference to the process network. */
+    public void setPN(ProcessNetwork pn) { _pn = pn; }
+    
+    /** Get the architecture */
+    public Architecture getArch() { return _arch; }
+    
+    /** Store a reference to the architecture. */
+    public void setArch(Architecture arch) { _arch = arch; }
+    
+    /**
+     * Get a list of computation bindings in this Mapping.
+     *
+     * @return the binding list
+     */
+    public Vector<ComputationBinding> getCompBindList() {
+        return _compBindList;
+    }
+
+    /**
+     * Get a list of processes in this Mapping.
+     *
+     * @return the process list
+     */
+    public Vector<Process> getProcessList() {
+        return _processList;
+    }
+
+    /**
+     * Return a process which has a specific name. Return null if
+     * process cannot be found.
+     *
+     * @param name the name of the process to search for.
+     * @return the process with the specific name or null if not found.
+     */    
+    public Process getProcess(String name)
+    {
+        for (Process process : _processList) {
+            if (process.getName().equals(name)) {
+                return process;
+            }
+        }
+        return null;
+    }
+    /**
+     * Set the computation binding list of this mapping.
+     *
+     * @param compBindList The new list
+     */
+    public void setCompBindList( Vector<ComputationBinding> compBindList ) {
+        _compBindList = compBindList;
+    }
+    
+    /**
+     * Get a list of communication bindings in this Mapping.
+     *
+     * @return the binding list
+     */
+    public Vector<CommunicationBinding> getCommBindList() {
+        return _commBindList;
+    }
+
+    /**
+     * Set the communication binding list of this mapping.
+     *
+     * @param commBindList The new list
+     */
+    public void setCommBindList( Vector<CommunicationBinding> commBindList ) {
+        _commBindList = commBindList;
+    }
+
+    /**
+     * Set the process list of this mapping.
+     *
+     * @param processList The new list
+     */
+    public void setProcessList( Vector<Process> processList ) {
+        _processList = processList;
+    }
+
+    /**
+     * Get the a list of processors in this Mapping.
+     *
+     * @return the processor list
+     */
+    public Vector<Processor> getProcessorList() {
+        return _processorList;
+    }
+
+    /**
+     * Set the processor list of this mapping.
+     *
+     * @param processorList The new list
+     */
+    public void setProcessorList( Vector<Processor> processorList ) {
+        _processorList = processorList;
+    }
+    
+    /**
+     * Return a processor which has a specific name. Return null if
+     * processor cannot be found.
+     *
+     * @param name the name of the processor to search for.
+     * @return the processor with the specific name or null if not found.
+     */    
+    public Processor getProcessor(String name)
+    {
+        Iterator<Processor> i;
+        i = _processorList.iterator();
+        while (i.hasNext()) {
+            Processor processor = i.next();
+            if (processor.getName().equals(name)) {
+                return processor;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Get the a list of schedules in this Mapping.
+     *
+     * @return the schedule list
+     */
+    public Vector<Schedule> getScheduleList() {
+        return _scheduleList;
+    }
+
+    /**
+     * Set the schedule list of this mapping.
+     *
+     * @param scheduleList The new list
+     */
+    public void setScheduleList( Vector<Schedule> scheduleList ) {
+        _scheduleList = scheduleList;
+    }
+    
+    /**
+     * Return the schedule for a resource that has a specific name. 
+     * Return null if schedule cannot be found.
+     *
+     * @param  name the name of the resource for which we are looking for the schedule.
+     * @return the schedule for the resource with the specified name.
+     */
+    public Schedule getScheduleByResource(String name) {
+        for(Schedule schedule : _scheduleList) {
+            if (schedule.getResource().getName().equals(name)) {
+                return schedule;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Return the communication binding for a channel that has a specific name. 
+     * Return null if binding cannot be found.
+     *
+     * @param  name the name of the channel for which we are looking for the binding.
+     * @return the binding for the channel with the specified name.
+     */
+    public CommunicationBinding getCommBindingByChannel(String name) {
+        for(CommunicationBinding b : _commBindList) {
+            if (b.getChannel().getName().equals(name)) {
+                return b;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Get the variable list of a Mapping.
+     *
+     * @return the variable list
+     */
+    public Vector<Variable> getVarList() {
+        return _variableList;
+    }
+
+    /**
+     * Set the variable list of a mapping.
+     *
+     * @param variableList The new list
+     */
+    public void setVarList( Vector<Variable> variableList ) {
+        _variableList = variableList;
+    }
+  
+    /** ProcessNetwork Reference **/
+    protected ProcessNetwork _pn = null;
+    
+    /** Architecture Reference **/
+    protected Architecture _arch = null;
+
+    /** List of processes in the mapping **/
+    protected Vector<Process> _processList = null;
+    
+    /** List of processors actually used in the mapping **/
+    protected Vector<Processor> _processorList = null;
+    
+    /** List of computations bindings in the mapping **/
+    protected Vector<ComputationBinding> _compBindList = null;
+    
+    /** List of communication bindings in the mapping **/
+    protected Vector<CommunicationBinding> _commBindList = null;
+    
+    /** List of schedules in the mapping **/
+    protected Vector<Schedule> _scheduleList = null;
+    
+    /** List of variables in the mapping **/
+    protected Vector<Variable> _variableList = null;
+}