-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
485 lines (444 loc) · 13 KB
/
index.html
File metadata and controls
485 lines (444 loc) · 13 KB
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" media="screen">
<style type="text/css">
</style>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!--
Author: Zhizhou Li <lzz@meteroi.com>
Copyright 2015 Meteroi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<title>Editor</title>
</head>
<body>
<div class="input-group" id="io">
</div>
<div class="tree well" id="module">
</div>
<a href="#savedialog" role="button" class="btn" data-toggle="modal" title="save the program">Save</a>
<span onclick="build()" class="btn btn-success" title="run the fpga file">
Build
</span>
<span onclick="download()" class="btn btn-warning" title="download the fpga file">
Download
</span>
<span onclick="install()" class="btn btn-info" title="install the fpga file">
install
</span>
<span id="file_state" class="label label-success"></span>
</div>
<div class="panel panel-default">
<span onclick="clean_error()" class="btn btn-warning" title="clear the error log">
Clear error
</span>
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#error">
<div class="alert alert-error" role="alert"><b>Error</b>
</div>
</a>
</div>
<div id="error" class="panel-collapse collapse in">
</div>
</div>
</div>
<div>
<div class="panel panel-default">
<span onclick="clean_console()" class="btn btn-warning" title="clear the console log">
Clear console
</span>
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#console">
<div class="alert alert-info" role="alert"><b>Console</b>
</div>
</a>
</div>
<div id="console" class="panel-collapse collapse in">
</div>
</div>
</div>
<div>
<!-- Save file dialog -->
<div class="modal hide fade" id="savedialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Save the program</h3>
</div>
<div class="modal-body">
<div class="input-group">
<input id="dialog_filename" type="text" class="form-control" placeholder="filename">
<span class="input-group-addon">.v</span>
</div>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">close</a>
<a href="#" data-dismiss="modal" class="btn btn-primary" onclick="save()" >save</a>
</div>
</div>
<!-- pop dialog -->
<div class="modal hide fade" id="popdialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Are you sure to delete?</h3>
</div>
<div class="modal-body">
<div class="input-group">
<p id="pop_message"></p>
</div>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">No</a>
<a href="#" data-dismiss="modal" class="btn btn-primary" onclick="do_delete_example()" >Yes</a>
</div>
</div>
<script>
var debug = true;
function debuginf(string) {
if (debug == true) {
console.log(string);
}
}
function url_isExist(url) {
var xhr = new XMLHttpRequest();
var post;
xhr.open("HEAD",url,false);
xhr.send();
debuginf(xhr.status);
return (xhr.status == 200)
}
function ajax_rest_post(url, arg1, arg2) {
var xhr = new XMLHttpRequest();
var post;
xhr.open("post",url,false);
xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded")
if (arg1 != undefined)
post = encodeURIComponent("arg1") + "=" + encodeURIComponent(arg1) + "&";
else
post = null;
if (arg2 != undefined)
post += encodeURIComponent("arg2") + "=" + encodeURIComponent(arg2) + "&";
xhr.send(post);
debuginf(xhr.status);
}
function download() {
window.location.pathname="grid.tar.gz"
}
function install() {
ajax_rest_post("install");
}
function load_example_list() {
var xhr = new XMLHttpRequest();
xhr.open("get","load_example",false);
xhr.send();
var examplelist = xhr.responseText;
var list = examplelist.split(',');
var html_list = "";
debuginf(list);
for (var index in list) {
debuginf(list[index]);
var name = list[index].split('.')[0];
var ext = list[index].split('.')[1];
if (ext == 'c') {
html_list += "<span id=" + name + " onmousedown='mousedown(event)' onmouseup='mouseup(event)' class='btn btn-info'>" + name + "</span>";
}
}
document.getElementById("Ex").innerHTML = html_list;
}
function is_io_part_start(str)
{
var re = new RegExp("<io_part>");
return str.match(re);
}
function is_io_part_end(str)
{
var re = new RegExp("</io_part>");
return str.match(re);
}
function is_module_part_start(str)
{
var re = new RegExp("<module_part>");
return str.match(re);
}
function is_module_part_end(str)
{
var re = new RegExp("</module_part>");
return str.match(re);
}
function is_connect(str)
{
var re = new RegExp("\\.(.*)\\(.*\\)");
return str.match(re);
}
function is_module(str)
{
var re = new RegExp("//\\s+([^\\s]+)\\.");
return str.match(re);
}
function is_io(str)
{
var re = new RegExp("(.*),");
//var re = new RegExp(".*//(.*)");
return str.match(re);
}
function get_module_type_name(str)
{
return str.substring(0,str.length-2);
}
function mach_module_type_name(str,type)
{
var re = new RegExp(type);
return str.match(re);
}
var module_tree = new Array();
var connect_pin_name_list = new Array();
var connect_module_name_list = new Array();
var module_tree_list = new Array();
var io_pin_name_list = new Array();
var template;
function load_template() {
var xhr = new XMLHttpRequest();
xhr.open("get","grid.v",false);
xhr.send();
template = xhr.responseText;
debuginf(template);
var template_lines = template.split('\n');
debuginf(template_lines);
var connect_line = new Array();
var io_line = new Array();
var i=0, start = false;
for (line in template_lines) {
if(is_module_part_start(template_lines[line])) {
start = true;
} else if (is_module_part_end(template_lines[line])) {
break;
} else if (start) {
connect_line[i] = template_lines[line];
i++;
}
}
debuginf(connect_line);
var connect, module;
var type = new Object();
for (line in connect_line) {
if (match = is_module(connect_line[line])) {
name = get_module_type_name(match[1])
if (name != type.name) {
if (type.name != undefined)
module_tree.push(type);
type = new Object();
type.name = name;
type.module = new Array();
}
module = new Object();
module.name = match[1];
module.connect = new Array();
connect_module_name_list.push((match[1]));
type.module.push(module);
}
if (match = is_connect(connect_line[line])) {
type.module[type.module.length-1].connect.push(match[1]);
connect_pin_name_list.push((match[1]));
}
}
module_tree.push(type); // the last node
debuginf(module_tree);
start = false;
for (line in template_lines) {
if(is_io_part_start(template_lines[line])) {
start = true;
} else if (is_io_part_end(template_lines[line])) {
break;
} else if (start) {
io_line[i] = template_lines[line];
i++;
}
}
debuginf(io_line);
for (line in io_line) {
if (connect = is_io(io_line[line])) {
io_pin_name_list.push((connect[1]));
}
}
}
function load_module() {
var innerHTML = '<ul>';
innerHTML += '<li>';
for (type in module_tree) {
innerHTML += '<span><i class="icon-folder-open"></i> '+ module_tree[type].name +'</span>';
innerHTML += '<ul>';
var module_list = module_tree[type].module;
for (module in module_list) {
innerHTML += '<li>';
innerHTML += '<span><i class="icon-minus-sign"></i> '+ module_list[module].name +'</span>';
innerHTML += '<ul>';
var connect_list = module_list[module].connect
for(connect in connect_list) {
innerHTML += '<li>'
innerHTML += '<span><i class="icon-leaf"></i> '+ connect_list[connect] +'</span>';
innerHTML += '</li>';
}
innerHTML += '</ul>';
innerHTML += '</li>';
}
innerHTML += '</ul>';
}
innerHTML += '</li>';
innerHTML += '</ul>';
document.getElementById("module").innerHTML += innerHTML;
$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
$('.tree li.parent_li > span').on('click', function (e) {
var children = $(this).parent('li.parent_li').find(' > ul > li');
if (children.is(":visible")) {
children.hide('fast');
$(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
} else {
children.show('fast');
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
}
e.stopPropagation();
});
}
function load_io() {
var i = 1;
var html ='<p>';
for (line in io_pin_name_list) {
html += '<span class="input-group-addon">';
html += io_pin_name_list[line];
html += '</span>';
html += '<input id="io_pin';
html += line;
html += '" type="text" class="form-control" placeholder="Pin to connect">'
if (i%4 == 0) {
html += '</p><p>'
}
i++;
}
html += '</p>';
document.getElementById("io").innerHTML += html;
}
// event handle for webpage
function save() {
var code = editor.getValue();
var file = document.getElementById("dialog_filename").value;
debuginf("save");
if (file != "") {
ajax_rest_post("save", file, code);
load_example_list();
return true;
} else
return false;
}
function build() {
debuginf("build");
for(i = 0;i < io_pin_name_list.length;i++) {
var name = "io_pin"+i;
var io_map = document.getElementById(name).value;
if (io_map == "")
continue;
var reg=new RegExp(io_map+"(.*)\\(.*\\)");
var rep= io_map+"("+io_pin_name_list[i]+")";
template = template.replace(reg,rep);
}
debuginf(template);
ajax_rest_post("build",template);
}
function load_example(event) {
var example = event.srcElement.innerText;
debuginf(example);
var file = example+'.v';
debuginf("load code");
var xhr = new XMLHttpRequest();
xhr.open("get","program/"+file,false);
xhr.send();
var get = xhr.responseText;
debuginf(get);
editor.setValue(get);
editor.clearSelection();
}
var timer = null;
function mousedown(event){
load_example(event);
timer = setTimeout(function() {delete_example(event)}, 1500 ); //set the timeout
};
function mouseup(event){
clearTimeout(timer);
};
function delete_example(event) {
var file = event.srcElement.innerText;
debuginf(file);
document.getElementById("pop_message").innerText = file;
$("#popdialog").modal();
}
function do_delete_example()
{
file = document.getElementById("pop_message").innerText;
debuginf("do delete code");
debuginf(file);
ajax_rest_post("delete",file);
load_example_list();
}
function clean_console() {
document.getElementById("console").innerHTML = " ";
};
function clean_error() {
document.getElementById("error").innerHTML = " ";
};
function console_polling(){
var xhr = new XMLHttpRequest();
xhr.open("get","console",false);
xhr.send();
var get = xhr.responseText;
get = get.replace(/\n/gi, '</p><p>');
get = get.replace(/\r/gi, '</p><p>');
document.getElementById("console").innerHTML += "<p>"+ get+"<\p>";
};
setInterval(console_polling, 1000);
function error_polling(){
var xhr = new XMLHttpRequest();
xhr.open("get","error",false);
xhr.send();
var get = xhr.responseText;
get = get.replace(/\n/gi, '</p><p>');
get = get.replace(/\r/gi, '</p><p>');
document.getElementById("error").innerHTML += "<p>"+ get+"<\p>";
};
setInterval(error_polling, 1000);
function file_polling(){
if (url_isExist("grid.tar.gz"))
document.getElementById("file_state").innerHTML = "File ready";
else
document.getElementById("file_state").innerHTML = "";
}
setInterval(file_polling, 5000);
function delay_refresh() {
window.location.reload();
}
function page_refresh() {
setTimeout('delay_refresh()',60000);
}
window.onload=function() {
load_template();
load_io();
load_module();
}
</script>
</body>
</html>