Math2mat
|
00001 00020 package m2m.backend.verifpga; 00021 00022 import java.io.BufferedReader; 00023 import java.io.BufferedWriter; 00024 import java.io.DataInputStream; 00025 import java.io.File; 00026 import java.io.FileInputStream; 00027 import java.io.FileReader; 00028 import java.io.FileWriter; 00029 import java.io.InputStreamReader; 00030 import java.io.Writer; 00031 import java.util.LinkedList; 00032 00033 import m2m.backend.project.ExternalToolsProperties; 00034 import m2m.backend.project.M2MProject; 00035 import m2m.backend.utils.FileUtils; 00036 00037 00038 public class ISETCLGenerator { 00039 00040 public final static String PROJECT_PATH_TCL = "<PROJECTPATH>"; 00041 00042 private String projectPath; 00043 private String templatesPath; 00044 private String ubiduleSourcePath; 00045 private String isePath; 00046 private String vhdlPath; 00047 00051 public ISETCLGenerator() { 00052 } 00053 00054 00059 public boolean generateTCLISE(M2MProject project) { 00060 //put out a 'heartbeat' - so we know something's happening 00061 System.out.println("Generation ise tcl script..."); 00062 00063 project.checkFolders(); 00064 00065 templatesPath = M2MProject.getLibPath()+"/ubidule/templates/"; 00066 ubiduleSourcePath = M2MProject.getLibPath()+"/ubidule/"; 00067 projectPath=project.getProperties().getProjectPath(); 00068 isePath=project.getProperties().getProjectPath()+M2MProject.getUbiduleDirName()+"/"; 00069 vhdlPath=project.getVHDLPath()+"/"; 00070 00071 FileUtils.copyFile(ubiduleSourcePath+"M2M_Test", project.getVHDLPath()+"/M2M_Test",".svn"); 00072 00073 processTemplate("script_gen_xsvf",""); 00074 FileUtils.copyFile(templatesPath+"part1.tcl",isePath+"part1.tcl"); 00075 processTemplate("part2",".tcl"); 00076 generateTCL("part3"); 00077 FileUtils.copyFile(templatesPath+"part4.tcl",isePath+"part4.tcl"); 00078 processTemplate("part5",".tcl"); 00079 FileUtils.copyFile(templatesPath+"part6.tcl",isePath+"part6.tcl"); 00080 concatenateTCLParts(); 00081 00082 FileUtils.copyFile(ubiduleSourcePath+"M2M_Test.ucf",isePath+"M2M_Test.ucf"); 00083 FileUtils.copyFile(ubiduleSourcePath+"PROM2_xcf32p.mcs",isePath+"PROM2_xcf32p.mcs"); 00084 FileUtils.copyFile(ubiduleSourcePath+"batch_test.cmd",isePath+"batch_test.cmd"); 00085 return true; 00086 00087 } 00088 00095 private void processTemplate(String tclName, String outputExtension) { 00096 System.out.println("processTemplate" + templatesPath + tclName); 00097 String newline = System.getProperty("line.separator"); 00098 String strLine; 00099 LinkedList<String> list = new LinkedList<String>(); 00100 00101 // read template, line by line in a linked list 00102 try{ 00103 00104 FileInputStream fstream = new FileInputStream(templatesPath + tclName); 00105 00106 DataInputStream in = new DataInputStream(fstream); 00107 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 00108 00109 while ((strLine = br.readLine()) != null) 00110 list.add(strLine); 00111 00112 in.close(); 00113 00114 }catch (Exception e){ 00115 System.err.println("Error: " + e.getMessage()); 00116 } 00117 00118 // Replace particular sequence (PROJECT_PATH_TCL) in the each line of the linked list. 00119 // Write then the processed line in the new file 00120 try{ 00121 00122 Writer output = new BufferedWriter(new FileWriter(isePath + tclName + outputExtension)); 00123 00124 for (String line: list) { 00125 //System.out.println("before: " + line); 00126 line = line.replace(PROJECT_PATH_TCL, projectPath); 00127 line = line.replace("<XILINXDIR>", ExternalToolsProperties.getReference().getIsePath()); 00128 line = line.replace("<UBIDULEDIRNAME>", M2MProject.getUbiduleDirName()); 00129 line = line.replace("<XILINXLICENSE>", ExternalToolsProperties.getReference().getXilinxLicense()); 00130 output.write(line + newline); 00131 System.out.println("after: " + line); 00132 } 00133 output.close(); 00134 }catch (Exception e){ 00135 System.err.println("Error: " + e.getMessage() ); 00136 } 00137 } 00138 00139 00140 private void populateVHDL(String dirName,LinkedList<String> list) { 00141 00142 File dir = new File(dirName); 00143 String[] children = dir.list(); 00144 if (children == null) { 00145 // Either dir does not exist or is not a directory 00146 } else { 00147 for (int i=0; i<children.length; i++) { 00148 // Get filename of file or directory 00149 String filename = children[i]; 00150 if (filename.contains(".vhd")) { 00151 //System.out.println(filename); 00152 list.add(dirName+filename); 00153 } 00154 File subdir=new File(dirName+filename); 00155 if (subdir.isDirectory()) 00156 populateVHDL(dirName+filename+"/",list); 00157 } 00158 } 00159 00160 } 00161 00168 private void generateTCL(String tclName) { 00169 LinkedList<String> listVHDLFiles = new LinkedList<String>(); 00170 String newline = System.getProperty("line.separator"); 00171 00172 populateVHDL(vhdlPath,listVHDLFiles); 00173 00174 try{ 00175 00176 Writer output = new BufferedWriter(new FileWriter(isePath + tclName + ".tcl")); 00177 00178 // add a line for each VHDL file 00179 for (String line: listVHDLFiles) { 00180 output.write(" xfile add \"" + line + "\"" + newline); 00181 } 00182 output.close(); 00183 }catch (Exception e){ 00184 System.err.println("Error: " + e.getMessage() ); 00185 } 00186 } 00187 00192 private void concatenateTCLParts() { 00193 //System.out.println(templatesPath); 00194 LinkedList<String> partsList = new LinkedList<String>(); 00195 partsList.add(isePath + "part1.tcl"); 00196 partsList.add(isePath + "part2.tcl"); 00197 partsList.add(isePath + "part3.tcl"); 00198 partsList.add(isePath + "part4.tcl"); 00199 partsList.add(isePath + "part5.tcl"); 00200 partsList.add(isePath + "part6.tcl"); 00201 00202 concatenateTCLParts(partsList); 00203 } 00204 00209 private void concatenateTCLParts(LinkedList<String> list) { 00210 //System.out.println(tclPath); 00211 String strLine; 00212 String newline = System.getProperty("line.separator"); 00213 try{ 00214 00215 Writer output = new BufferedWriter(new FileWriter(isePath + "M2M_Test.tcl")); 00216 //System.out.println("lalfsw: "+projectPath + "ise/" + "M2M_Test.tcl"); 00217 00218 // for all tcl parts (1 to 6), concatenate theirs contents to M2M_Test.tcl 00219 for (String line: list) { 00220 BufferedReader reader = new BufferedReader(new FileReader(line)); 00221 00222 while ((strLine = reader.readLine()) != null) { 00223 output.write(strLine + newline); 00224 } 00225 } 00226 00227 output.close(); 00228 }catch (Exception e){ 00229 System.err.println("Error: " + e.getMessage() ); 00230 } 00231 } 00232 00233 }