X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fcell%2FCellVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fcell%2FCellVisitor.java;h=43c609d9898482234a552021f5475212508c5907;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/cell/CellVisitor.java b/dol/src/dol/visitor/cell/CellVisitor.java new file mode 100644 index 0000000..43c609d --- /dev/null +++ b/dol/src/dol/visitor/cell/CellVisitor.java @@ -0,0 +1,179 @@ +package dol.visitor.cell; + +import java.io.File; +import java.util.HashMap; +import java.util.Vector; + +import dol.datamodel.pn.Port; +import dol.datamodel.pn.Process; +import dol.datamodel.pn.ProcessNetwork; +import dol.main.UserInterface; +import dol.visitor.PNVisitor; +import dol.util.Copier; + +/** + * This class is a class for a visitor that is used to generate + * a CELL package. + */ +public class CellVisitor extends PNVisitor { + + /** + * Constructor. + * + * @param packageName name of the Cell directory + */ + public CellVisitor(String packageName) { + _packageName = packageName; + _ui = UserInterface.getInstance(); + } + + /** + * Visit process network. + * + * @param pn process network that needs to be rendered. + */ + public void visitComponent(ProcessNetwork pn) { + try { + File dir = new File(_packageName); + dir.mkdirs(); + + // Create the library + File lib = new File(_packageName + _delimiter + "lib"); + lib.mkdirs(); + + //copy library files + File source = new File(_ui.getMySystemCLib(). + replaceAll("systemC", "cell").replace("%20", " ")); + new Copier().copy(source, lib); + + // Create the template + File template = new File(_packageName + _delimiter + "template"); + template.mkdirs(); + + //copy the templates + source = new File(_ui.getMySystemCLib().replaceAll("systemC", "cell").replace("lib", "template").replace("%20", " ")); + new Copier().copy(source, template); + + // Some library files must be copied to the main directory + (new File(lib.getPath() + _delimiter + "ppu_main.h")).renameTo(new File (dir.getPath() + _delimiter + "ppu_main.h")); + + //copy process source code + source = new File(_srcDirName.replace("%20", " ")); + new Copier().copy(source, dir); + + createPortMap(pn); + + // Create the mapping for this process network on the cell + CellMapping mapping = new CellMapping(pn, "predefined", true, MAX_SPUS); + + pn.accept(new CellMakefileVisitor(_packageName, mapping)); + pn.accept(new CellProcessVisitor(_packageName, _portMap, mapping)); + pn.accept(new CellModuleVisitor(_packageName, _portMap, mapping)); + pn.accept(new CellConstantVisitor(_packageName, mapping)); + pn.accept(new CellSPEVisitor(_packageName, mapping)); + pn.accept(new CellPPEVisitor(_packageName, mapping)); + } + catch (Exception e) { + System.out.println("CellVisitor: exception occured: " + + e.getMessage()); + e.printStackTrace(); + } + } + + /** + * Create a hashmap which maps each port of the given process network + * to an integer. For each process, ports are numbered with integers + * starting from 0. + * + * @param pn process network for which the map should be generated + */ + protected void createPortMap(ProcessNetwork pn) { + _portMap = new HashMap(); + + for (Process process : pn.getProcessList()) { + int portCount = 0; + Vector portList = process.getPortList(); + Vector portNameList = new Vector(); + portNameList.clear(); + HashMap portMap = + new HashMap(); + portMap.clear(); + + for (int i = 0; i < portList.size(); i++) { + //treat single ports differently than iterated ports + String portName = portList.elementAt(i).getName(); + String baseName = portList.elementAt(i).getBasename(); + + if (portName.equals(baseName)) { + portNameList.add(portName); + portMap.put(portName, portCount++); + } else { + String range_indices = portList.elementAt(i).getRange(); + Vector range_indices_values = getIndex(range_indices, ";"); + + String port_indices = portName; + port_indices.replaceAll(baseName, ""); + Vector port_indices_values = getIndex(port_indices, "_"); + + if (!portNameList.contains(baseName)) { + portNameList.add(baseName); + portMap.put(baseName, portCount); + + int size = 1; + for (int j = 0; j < range_indices_values.size(); j++) { + size *= range_indices_values.elementAt(j); + } + portCount += size; + } + + int portId = portMap.get(baseName); + for (int j = 0; j < port_indices_values.size(); j++) { + int weight = 1; + for (int k = j + 1; k < range_indices_values.size(); k++) { + weight *= range_indices_values.elementAt(k); + } + portId += port_indices_values.elementAt(j) * weight; + } + portMap.put(portName, portId); + } + } + + for (int i = 0; i < portList.size(); i++) { + _portMap.put(portList.elementAt(i), + portMap.get(portList.elementAt(i).getName())); + } + } + } + + /** + * Gets vector of indices of a string, where the index must be + * separated by the specified separator. + * examples: + * getIndex("name_1_2", "_", 0) will return 1. + * getIndex("name_1_2", "_", 1) will return 2. + * + * @param range string to parse + * @param separator delimiter of indices + * @return vector of indices + */ + protected Vector getIndex(String range, String separator) { + Vector indices = new Vector(); + String[] subranges = range.split(separator); + for (int i = 0; i < subranges.length; i++) { + try { + int value = Integer.valueOf(subranges[i]); + indices.add(value); + } catch (Exception e) { + continue; + } + } + return indices; + } + + public final static int MAX_SPUS = 6; + protected HashMap _portMap; + protected String _packageName = null; + + protected String _srcDir = ""; + protected static String _srcDirName = "src"; +}