-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimulationPanel.cs
265 lines (231 loc) · 10.5 KB
/
SimulationPanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ajkControls.Primitive;
namespace pluginVivado
{
public partial class SimulationPanel : UserControl
{
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern uint GetShortPathName([System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.LPTStr)]
string lpszLongPath,
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] System.Text.StringBuilder lpszShortPath,
uint cchBuffer);
public string getShortPath(string path)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
uint ret = GetShortPathName(path, sb, (uint)sb.Capacity);
if (ret == 0) return path;
return sb.ToString();
}
public SimulationPanel(pluginVerilog.Data.VerilogFile topFile)
{
InitializeComponent();
Disposed += disposed;
thread = new System.Threading.Thread(run);
thread.Start();
}
public Action<IconImage,IconImage.ColorStyle> RequestTabIconChange;
private void receiveLineString(string lineString)
{
if (lineString == "xSimVerilogShell>")
{
logView.AppendLogLine(lineString, System.Drawing.Color.ForestGreen);
}else if (lineString != null && lineString.StartsWith("ERROR"))
{
logView.AppendLogLine(lineString, System.Drawing.Color.OrangeRed);
}
else
{
logView.AppendLogLine(lineString);
}
moveTabIcon(IconImage.ColorStyle.White);
}
private int iconCount = 0;
private void moveTabIcon(IconImage.ColorStyle color)
{
iconCount++;
if (iconCount > 5) iconCount = 0;
if (RequestTabIconChange != null)
{
switch (iconCount)
{
case 0:
RequestTabIconChange(codeEditor.Global.IconImages.Wave0, color);
break;
case 1:
RequestTabIconChange(codeEditor.Global.IconImages.Wave1, color);
break;
case 2:
RequestTabIconChange(codeEditor.Global.IconImages.Wave2, color);
break;
case 3:
RequestTabIconChange(codeEditor.Global.IconImages.Wave3, color);
break;
case 4:
RequestTabIconChange(codeEditor.Global.IconImages.Wave4, color);
break;
case 5:
RequestTabIconChange(codeEditor.Global.IconImages.Wave5, color);
break;
}
}
}
private void disposed(object sender, EventArgs e)
{
abort = true;
RequestTabIconChange = null;
shell.Dispose();
}
ajkControls.CommandShell shell = null;
System.Threading.Thread thread = null;
private volatile bool abort = false;
private void run()
{
codeEditor.NavigatePanel.NavigatePanelNode node;
codeEditor.Controller.NavigatePanel.GetSelectedNode(out node);
pluginVerilog.NavigatePanel.VerilogFileNode verilogFileNode = node as pluginVerilog.NavigatePanel.VerilogFileNode;
if (node == null) return;
pluginVerilog.Data.VerilogFile topFile = verilogFileNode.VerilogFile;
codeEditor.Data.Project project = topFile.Project;
if (topFile == null) return;
pluginVerilog.Verilog.ParsedDocument topParsedDocument = topFile.ParsedDocument as pluginVerilog.Verilog.ParsedDocument;
if (topParsedDocument == null) return;
if (topParsedDocument.Modules.Count == 0) return;
string simName = topFile.Name.Substring(0, topFile.Name.LastIndexOf('.'));
string simulationPath = Setup.SimulationPath + "\\" + simName;
if (!System.IO.Directory.Exists(simulationPath))
{
System.IO.Directory.CreateDirectory(simulationPath);
}
List<string> filePathList = new List<string>();
{
string absolutePath = project.GetAbsolutePath(topFile.RelativePath);
filePathList.Add(absolutePath);
}
List<string> includeFileList = new List<string>();
foreach (pluginVerilog.Verilog.Module module in topParsedDocument.Modules.Values)
{
appendFiles(filePathList, includeFileList, module, project);
}
pluginVerilog.Verilog.Module topModule = topParsedDocument.Modules.FirstOrDefault().Value;
if (topModule == null) return;
// create project file
// verilog<work_library> < file_names > ... [-d<macro>]...[-i<include_path>]...
// vhdl<work_library> <file_name>
// sv<work_library> <file_name>
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(simulationPath + "\\"+ simName+".prj"))
{
foreach (string absolutePath in filePathList)
{
sw.Write("verilog "+simName+" \"" + absolutePath+"\"");
if (includeFileList.Count != 0)
{
foreach (string includePath in includeFileList)
{
sw.Write(" -i \"" + getShortPath(includePath) + "\""); // path with space is not accepted
}
}
sw.Write("\r\n");
}
}
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(simulationPath + "\\command.bat"))
{
sw.Write("echo #compile\r\n");
//foreach (string absolutePath in filePathList)
//{
// sw.Write("call "+Setup.BinPath + "xvlog ^\r\n");
// if (includeFileList.Count != 0)
// {
// foreach (string includePath in includeFileList)
// {
// sw.Write("-i \"" + includePath + "\" ^\r\n"); // path with space is not accepted
// }
// }
// sw.Write("\""+absolutePath + "\"");
// sw.Write("\r\n");
//}
sw.Write("call " + Setup.BinPath + "xvlog -prj "+ simName + ".prj" + " ^\r\n");
//if (includeFileList.Count != 0)
//{
// foreach (string includePath in includeFileList)
// {
// sw.Write("-i \"" + includePath + "\" ^"); // path with space is not accepted
// }
//}
//foreach (string absolutePath in filePathList)
//{
// sw.Write(" ^\r\n \"" + absolutePath + "\"");
//}
sw.Write("\r\n");
sw.Write("\r\n");
sw.Write("echo #elaboration\r\n");
sw.Write("call " + Setup.BinPath + "xelab ^\r\n");
sw.Write("--debug all ^\r\n");
sw.Write("--notimingchecks ^\r\n");
sw.Write(topModule.Name + "\r\n");
sw.Write("\r\n");
sw.Write("\r\n");
sw.Write("echo #simulation\r\n");
sw.Write("call " + Setup.BinPath + "xsim " + topModule.Name + " -t xsim_run.tcl\r\n");
}
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(simulationPath + "\\xsim_run.tcl"))
{
sw.Write("run all\r\n");
}
if (abort) return;
shell = new ajkControls.CommandShell(new List<string> {
"prompt xSimVerilogShell$G$_",
"cd "+simulationPath
});
shell.LineReceived += receiveLineString;
shell.Start();
while (shell.GetLastLine() != "xSimVerilogShell>") {
if (abort) return;
System.Threading.Thread.Sleep(10);
}
shell.ClearLogs();
shell.StartLogging();
shell.Execute("command.bat");
while (shell.GetLastLine() != "%xsim") {
if (abort) return;
System.Threading.Thread.Sleep(10);
}
RequestTabIconChange(codeEditor.Global.IconImages.Wave0, IconImage.ColorStyle.Green);
List<string> logs = shell.GetLogs();
if (logs.Count != 3 || logs[1] != "")
{
return;
}
shell.EndLogging();
}
private void appendFiles(List<string> filePathList, List<string> includePathList, pluginVerilog.Verilog.Module module, codeEditor.Data.Project project)
{
string fileId = module.FileId;
pluginVerilog.Data.VerilogFile file = module.File as pluginVerilog.Data.VerilogFile;
if (file == null) return;
string absolutePath = project.GetAbsolutePath(file.RelativePath);
if (!filePathList.Contains(absolutePath)) filePathList.Add(absolutePath);
if (file.VerilogParsedDocument == null) return;
// includes
foreach (var include in file.VerilogParsedDocument.IncludeFiles.Values)
{
string includePath = project.GetAbsolutePath(include.RelativePath);
includePath = includePath.Substring(0, includePath.LastIndexOf('\\'));
if (!includePathList.Contains(includePath)) includePathList.Add(includePath);
}
foreach (pluginVerilog.Verilog.ModuleItems.ModuleInstantiation instance in module.ModuleInstantiations.Values)
{
pluginVerilog.Verilog.Module subModule = (project.ProjectProperties[pluginVerilog.Plugin.StaticID] as pluginVerilog.ProjectProperty).GetModule(instance.ModuleName);
if (subModule != null) appendFiles(filePathList, includePathList, subModule, project);
}
}
}
}