diff --git a/src/main/java/syscamstranslator/SysCAMSSpecification.java b/src/main/java/syscamstranslator/SysCAMSSpecification.java index f6d04675b8998798e797ec0c4bc40faddfd466e0..41ea6420f37be16a138c5fc3b0ba1b4755c00466 100644 --- a/src/main/java/syscamstranslator/SysCAMSSpecification.java +++ b/src/main/java/syscamstranslator/SysCAMSSpecification.java @@ -47,26 +47,26 @@ import java.util.List; * Creation: 14/05/2018 * @version 1.0 14/05/2018 * @author Irina Kit Yan LEE -*/ + */ public class SysCAMSSpecification{ - private List<SysCAMSTComponent> components; - private List<SysCAMSTConnector> connectors; - - public SysCAMSSpecification(List<SysCAMSTComponent> _components, List<SysCAMSTConnector> _connectors){ + private List<SysCAMSTComponent> components; + private List<SysCAMSTConnector> connectors; + + public SysCAMSSpecification(List<SysCAMSTComponent> _components, List<SysCAMSTConnector> _connectors){ components = _components ; connectors = _connectors ; } - - public List<SysCAMSTComponent> getComponents(){ - return components; - } - public List<SysCAMSTConnector> getConnectors(){ - return connectors; - } + public List<SysCAMSTComponent> getComponents(){ + return components; + } + + public List<SysCAMSTConnector> getConnectors(){ + return connectors; + } - public LinkedList<SysCAMSTBlockTDF> getAllBlockTDF(){ + public LinkedList<SysCAMSTBlockTDF> getAllBlockTDF(){ LinkedList<SysCAMSTBlockTDF> blocksTDF = new LinkedList<SysCAMSTBlockTDF>(); for (SysCAMSTComponent blockTDF : components) { if (blockTDF instanceof SysCAMSTBlockTDF) { @@ -74,121 +74,116 @@ public class SysCAMSSpecification{ } } return blocksTDF; - } - - public LinkedList<SysCAMSTBlockDE> getAllBlockDE(){ - LinkedList<SysCAMSTBlockDE> blocksDE = new LinkedList<SysCAMSTBlockDE>(); - for (SysCAMSTComponent blockDE : components) { - if (blockDE instanceof SysCAMSTBlockDE) { - blocksDE.add((SysCAMSTBlockDE) blockDE); - } - } - return blocksDE; - } - - public LinkedList<SysCAMSTBlockGPIO2VCI> getAllBlockGPIO2VCI(){ - LinkedList<SysCAMSTBlockGPIO2VCI> blocksGPIO2VCI = new LinkedList<SysCAMSTBlockGPIO2VCI>(); - for (SysCAMSTComponent blockGPIO2VCI : components) { - if (blockGPIO2VCI instanceof SysCAMSTBlockGPIO2VCI) { - blocksGPIO2VCI.add((SysCAMSTBlockGPIO2VCI) blockGPIO2VCI); - } - } - return blocksGPIO2VCI; - } - - public LinkedList<SysCAMSTCluster> getAllCluster(){ - LinkedList<SysCAMSTCluster> clusters = new LinkedList<SysCAMSTCluster>(); - for (SysCAMSTComponent cluster : components) { - if (cluster instanceof SysCAMSTCluster) { - clusters.add((SysCAMSTCluster) cluster); - } - } - return clusters; - } - - public LinkedList<SysCAMSTPortConverter> getAllPortConverter(){ - LinkedList<SysCAMSTPortConverter> portsConv = new LinkedList<SysCAMSTPortConverter>(); - for (SysCAMSTComponent portConv : components) { - if (portConv instanceof SysCAMSTPortConverter) { - portsConv.add((SysCAMSTPortConverter) portConv); - } - } - return portsConv; - } - - public LinkedList<SysCAMSTPortTDF> getAllPortTDF(){ - LinkedList<SysCAMSTPortTDF> portsTDF = new LinkedList<SysCAMSTPortTDF>(); - for (SysCAMSTComponent portTDF : components) { - if (portTDF instanceof SysCAMSTPortTDF) { - portsTDF.add((SysCAMSTPortTDF) portTDF); - } - } - return portsTDF; - } - - public LinkedList<SysCAMSTPortDE> getAllPortDE(){ - LinkedList<SysCAMSTPortDE> portsDE = new LinkedList<SysCAMSTPortDE>(); - for (SysCAMSTComponent portDE : components) { - if (portDE instanceof SysCAMSTPortDE) { - portsDE.add((SysCAMSTPortDE) portDE); - } - } - return portsDE; - } - - public LinkedList<SysCAMSTConnector> getAllConnectorCluster(){ - LinkedList<SysCAMSTConnector> cons = new LinkedList<SysCAMSTConnector>(); - for (SysCAMSTConnector con : connectors) { - if (con instanceof SysCAMSTConnector) { - if (con.get_p1().getComponent() instanceof SysCAMSTPortTDF && con.get_p2().getComponent() instanceof SysCAMSTPortTDF) { - cons.add(con); - } else if (con.get_p1().getComponent() instanceof SysCAMSTPortConverter && con.get_p2().getComponent() instanceof SysCAMSTPortDE) { - if (((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE() != null) { - if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { - cons.add(con); - } - } - } else if (con.get_p2().getComponent() instanceof SysCAMSTPortConverter && con.get_p1().getComponent() instanceof SysCAMSTPortDE) { - if (((SysCAMSTPortDE) con.get_p1().getComponent()).getBlockDE() != null) { - if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { - cons.add(con); - } - } - } - } - } - return cons; - } - - public int getNbBlockTDF(){ - return (getAllBlockTDF()).size(); - } - - public int getNbBlockDE(){ - return (getAllBlockDE()).size(); - } - - public int getNbBlockGPIO2VCI(){ - return (getAllBlockGPIO2VCI()).size(); - } - - public int getNbCluster(){ - return (getAllCluster()).size(); - } - - public int getNbPortConverter(){ - return (getAllPortConverter()).size(); - } - - public int getNbPortTDF(){ - return (getAllPortTDF()).size(); - } - - public int getNbPortDE(){ - return (getAllPortDE()).size(); - } - - public int getNbConnectorCluster(){ - return (getAllConnectorCluster()).size(); - } + } + + public LinkedList<SysCAMSTBlockDE> getAllBlockDE(){ + LinkedList<SysCAMSTBlockDE> blocksDE = new LinkedList<SysCAMSTBlockDE>(); + for (SysCAMSTComponent blockDE : components) { + if (blockDE instanceof SysCAMSTBlockDE) { + blocksDE.add((SysCAMSTBlockDE) blockDE); + } + } + return blocksDE; + } + + public LinkedList<SysCAMSTBlockGPIO2VCI> getAllBlockGPIO2VCI(){ + LinkedList<SysCAMSTBlockGPIO2VCI> blocksGPIO2VCI = new LinkedList<SysCAMSTBlockGPIO2VCI>(); + for (SysCAMSTComponent blockGPIO2VCI : components) { + if (blockGPIO2VCI instanceof SysCAMSTBlockGPIO2VCI) { + blocksGPIO2VCI.add((SysCAMSTBlockGPIO2VCI) blockGPIO2VCI); + } + } + return blocksGPIO2VCI; + } + + public SysCAMSTCluster getCluster(){ + for (SysCAMSTComponent comp : components) { + if (comp instanceof SysCAMSTCluster) { + return (SysCAMSTCluster) comp; + } + } + return null; + } + + public LinkedList<SysCAMSTPortConverter> getAllPortConverter(){ + LinkedList<SysCAMSTPortConverter> portsConv = new LinkedList<SysCAMSTPortConverter>(); + for (SysCAMSTComponent portConv : components) { + if (portConv instanceof SysCAMSTPortConverter) { + portsConv.add((SysCAMSTPortConverter) portConv); + } + } + return portsConv; + } + + public LinkedList<SysCAMSTPortTDF> getAllPortTDF(){ + LinkedList<SysCAMSTPortTDF> portsTDF = new LinkedList<SysCAMSTPortTDF>(); + for (SysCAMSTComponent portTDF : components) { + if (portTDF instanceof SysCAMSTPortTDF) { + portsTDF.add((SysCAMSTPortTDF) portTDF); + } + } + return portsTDF; + } + + public LinkedList<SysCAMSTPortDE> getAllPortDE(){ + LinkedList<SysCAMSTPortDE> portsDE = new LinkedList<SysCAMSTPortDE>(); + for (SysCAMSTComponent portDE : components) { + if (portDE instanceof SysCAMSTPortDE) { + portsDE.add((SysCAMSTPortDE) portDE); + } + } + return portsDE; + } + + public LinkedList<SysCAMSTConnector> getAllConnectorCluster(){ + LinkedList<SysCAMSTConnector> cons = new LinkedList<SysCAMSTConnector>(); + for (SysCAMSTConnector con : connectors) { + if (con instanceof SysCAMSTConnector) { + if (con.get_p1().getComponent() instanceof SysCAMSTPortTDF && con.get_p2().getComponent() instanceof SysCAMSTPortTDF) { + cons.add(con); + } else if (con.get_p1().getComponent() instanceof SysCAMSTPortConverter && con.get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE() != null) { + if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { + cons.add(con); + } + } + } else if (con.get_p2().getComponent() instanceof SysCAMSTPortConverter && con.get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) con.get_p1().getComponent()).getBlockDE() != null) { + if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { + cons.add(con); + } + } + } + } + } + return cons; + } + + public int getNbBlockTDF(){ + return (getAllBlockTDF()).size(); + } + + public int getNbBlockDE(){ + return (getAllBlockDE()).size(); + } + + public int getNbBlockGPIO2VCI(){ + return (getAllBlockGPIO2VCI()).size(); + } + + public int getNbPortConverter(){ + return (getAllPortConverter()).size(); + } + + public int getNbPortTDF(){ + return (getAllPortTDF()).size(); + } + + public int getNbPortDE(){ + return (getAllPortDE()).size(); + } + + public int getNbConnectorCluster(){ + return (getAllConnectorCluster()).size(); + } } \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java index 0f5dd750dda66fbc965b8639a373074f424e039e..6080c5e4dd30844b5e12be61e623727f1f168627 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java @@ -50,46 +50,64 @@ import java.util.LinkedList; import syscamstranslator.*; /** - * Class MakefileCode - * Principal code of a makefile - * Creation: 02/06/2018 + * Class MakefileCode Principal code of a makefile Creation: 02/06/2018 + * * @version 1.0 02/06/2018 * @author Irina Kit Yan LEE -*/ + */ public class MakefileCode { static private String corpsMakefile; private final static String CR = "\n"; private final static String CR2 = "\n\n"; - MakefileCode() {} + MakefileCode() { + } - public static String getMakefileCode(SysCAMSTCluster cluster) { - if (cluster != null) { - LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); - LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); - - corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR + public static String getMakefileCode(LinkedList<SysCAMSTCluster> clusters) { + if (clusters != null) { + corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR + "LDFLAGS = $(SYSTEMC_LIBRARY_DIRS)" + CR2 + "# List of all ecutables to be compiled" + CR - + "EXECUTABLES = " + cluster.getClusterName() + "_tb" + CR2 + "# .PHONY targets don't generate files" + CR - + ".PHONY: all clean" + CR2 + "# Default targets" + CR + "all: $(EXECUTABLES)" + CR2; - - corpsMakefile = corpsMakefile + cluster.getClusterName() + "_tb: " + cluster.getClusterName() + "_tb.cpp"; - - for (SysCAMSTBlockTDF t : tdf) { - corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + + "EXECUTABLES = "; + + for (int i = 0; i < clusters.size(); i++) { + if (i == 0) { + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb"; + } + if (i > 0) { + corpsMakefile = corpsMakefile + " " + clusters.get(i).getClusterName() + "_tb"; + } + if (i == clusters.size() - 1) { + corpsMakefile = corpsMakefile + CR2; + } } - - for (SysCAMSTBlockDE t : de) { - corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + + corpsMakefile = corpsMakefile + "# .PHONY targets don't generate files" + CR + ".PHONY: all clean" + CR2 + + "# Default targets" + CR + "all: $(EXECUTABLES)" + CR2; + + for (int i = 0; i < clusters.size(); i++) { + LinkedList<SysCAMSTBlockTDF> tdf = clusters.get(i).getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = clusters.get(i).getBlockDE(); + + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb: " + + clusters.get(i).getClusterName() + "_tb.cpp"; + + for (SysCAMSTBlockTDF t : tdf) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + + for (SysCAMSTBlockDE t : de) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + corpsMakefile = corpsMakefile + CR + + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" + CR2; } - - corpsMakefile = corpsMakefile + CR + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" - + CR2 + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR - + "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR; + + corpsMakefile = corpsMakefile + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR + + "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR; } else { corpsMakefile = ""; } return corpsMakefile; } -} +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java index 0c3dc7e3da0277dd6bee0c57814163f8bf458175..bdd086cb14809db39231753ad3e2768ddb88af3c 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java +++ b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java @@ -47,7 +47,6 @@ package syscamstranslator.toSysCAMS; import syscamstranslator.*; - import java.io.*; import java.util.LinkedList; @@ -70,7 +69,7 @@ public class TopCellGenerator { } public String generateTopCell(SysCAMSTCluster c, LinkedList<SysCAMSTConnector> connectors) { - if (TopCellGenerator.syscams.getNbCluster() == 0) { + if (c == null) { System.out.println("***Warning: require at least one cluster***"); } if (TopCellGenerator.syscams.getNbBlockTDF() == 0) { @@ -96,35 +95,23 @@ public class TopCellGenerator { } public void saveFile(String path) { - LinkedList<SysCAMSTCluster> clusters = TopCellGenerator.syscams.getAllCluster(); + SysCAMSTCluster cluster = TopCellGenerator.syscams.getCluster(); LinkedList<SysCAMSTConnector> connectors = TopCellGenerator.syscams.getAllConnectorCluster(); - - String top, makefile; - - for (SysCAMSTCluster c : clusters) { - try { - // Save file .cpp - System.err.println(path + GENERATED_PATH1 + c.getClusterName() + ".cpp"); - FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + c.getClusterName() + "_tb.cpp"); - top = generateTopCell(c, connectors); - fw.write(top); - fw.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - // Save Makefile - System.err.println(path + "Makefile"); - FileWriter fw = new FileWriter(path + "/" + "Makefile"); - makefile = MakefileCode.getMakefileCode(c); - fw.write(makefile); - fw.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - // Save files .h - saveFileBlock(path, c); + + String top; + + try { + // Save file .cpp + System.err.println(path + GENERATED_PATH1 + cluster.getClusterName() + ".cpp"); + FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + cluster.getClusterName() + "_tb.cpp"); + top = generateTopCell(cluster, connectors); + fw.write(top); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); } + // Save files .h + saveFileBlock(path, cluster); } public void saveFileBlock(String path, SysCAMSTCluster c) { diff --git a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java index 6862364c58719d61949698a885125a1eccb87204..903c9bae7b63f52f39dd4cc2df6eef4952996c50 100644 --- a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java @@ -38,11 +38,13 @@ package ui.window; +import syscamstranslator.toSysCAMS.MakefileCode; import syscamstranslator.toSysCAMS.TopCellGenerator; import launcher.LauncherException; import launcher.RshClient; import myutil.*; import syscamstranslator.SysCAMSSpecification; +import syscamstranslator.SysCAMSTCluster; import ui.util.IconManager; import ui.MainGUI; import ui.SysCAMSPanelTranslator; @@ -52,8 +54,10 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.FileWriter; import java.io.StringWriter; import java.io.Writer; +import java.util.LinkedList; import java.util.Vector; /** @@ -502,6 +506,12 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i jta.append("Generating executable code (SystemC-AMS version)\n"); Vector<SysCAMSComponentTaskDiagramPanel> syscamsDiagramPanels = mgui.getListSysCAMSPanel(); + LinkedList<SysCAMSTCluster> clusters = new LinkedList<SysCAMSTCluster>(); + for (SysCAMSComponentTaskDiagramPanel syscamsDiagramPanel : syscamsDiagramPanels) { + SysCAMSPanelTranslator syscamspaneltranslator = new SysCAMSPanelTranslator(syscamsDiagramPanel); + SysCAMSSpecification syscalsspec = syscamspaneltranslator.getSysCAMSSpecification(); + clusters.add(syscalsspec.getCluster()); + } for (SysCAMSComponentTaskDiagramPanel syscamsDiagramPanel : syscamsDiagramPanels) { SysCAMSPanelTranslator syscamspaneltranslator = new SysCAMSPanelTranslator(syscamsDiagramPanel); SysCAMSSpecification syscalsspec = syscamspaneltranslator.getSysCAMSSpecification(); @@ -531,9 +541,19 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i e.printStackTrace(); } } - testGo(); } + try { + String makefile; + System.err.println(pathCode + "Makefile"); + FileWriter fw = new FileWriter(pathCode + "/" + "Makefile"); + makefile = MakefileCode.getMakefileCode(clusters); + fw.write(makefile); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + testGo(); } // if (removeCFiles.isSelected()) { //