|
a |
|
b/example.html |
|
|
1 |
<!doctype html> |
|
|
2 |
<html lang="en-us"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
|
6 |
<title>c2iec transpiler</title> |
|
|
7 |
</head> |
|
|
8 |
<body> |
|
|
9 |
<div class="spinner" id='spinner'></div> |
|
|
10 |
<div class="emscripten" id="status">Downloading...</div> |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
<div class="emscripten"> |
|
|
14 |
<progress value="0" max="100" id="progress" hidden=1></progress> |
|
|
15 |
</div> |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
<div class="emscripten_border"> |
|
|
19 |
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas> |
|
|
20 |
</div> |
|
|
21 |
<script type='text/javascript'> |
|
|
22 |
var statusElement = document.getElementById('status'); |
|
|
23 |
var progressElement = document.getElementById('progress'); |
|
|
24 |
var spinnerElement = document.getElementById('spinner'); |
|
|
25 |
|
|
|
26 |
var Module = { |
|
|
27 |
preRun: [], |
|
|
28 |
postRun: [], |
|
|
29 |
noInitialRun: true, |
|
|
30 |
print: (function() { |
|
|
31 |
var element = document.getElementById('output'); |
|
|
32 |
if (element) element.value = ''; // clear browser cache |
|
|
33 |
return function(text) { |
|
|
34 |
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); |
|
|
35 |
// These replacements are necessary if you render to raw HTML |
|
|
36 |
//text = text.replace(/&/g, "&"); |
|
|
37 |
//text = text.replace(/</g, "<"); |
|
|
38 |
//text = text.replace(/>/g, ">"); |
|
|
39 |
//text = text.replace('\n', '<br>', 'g'); |
|
|
40 |
console.log(text); |
|
|
41 |
if (element) { |
|
|
42 |
element.value += text + "\n"; |
|
|
43 |
element.scrollTop = element.scrollHeight; // focus on bottom |
|
|
44 |
} |
|
|
45 |
}; |
|
|
46 |
})(), |
|
|
47 |
printErr: function(text) { |
|
|
48 |
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); |
|
|
49 |
console.error(text); |
|
|
50 |
}, |
|
|
51 |
canvas: (function() { |
|
|
52 |
var canvas = document.getElementById('canvas'); |
|
|
53 |
|
|
|
54 |
// As a default initial behavior, pop up an alert when webgl context is lost. To make your |
|
|
55 |
// application robust, you may want to override this behavior before shipping! |
|
|
56 |
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 |
|
|
57 |
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false); |
|
|
58 |
|
|
|
59 |
return canvas; |
|
|
60 |
})(), |
|
|
61 |
setStatus: function(text) { |
|
|
62 |
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' }; |
|
|
63 |
if (text === Module.setStatus.last.text) return; |
|
|
64 |
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); |
|
|
65 |
var now = Date.now(); |
|
|
66 |
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon |
|
|
67 |
Module.setStatus.last.time = now; |
|
|
68 |
Module.setStatus.last.text = text; |
|
|
69 |
if (m) { |
|
|
70 |
text = m[1]; |
|
|
71 |
progressElement.value = parseInt(m[2])*100; |
|
|
72 |
progressElement.max = parseInt(m[4])*100; |
|
|
73 |
progressElement.hidden = false; |
|
|
74 |
spinnerElement.hidden = false; |
|
|
75 |
} else { |
|
|
76 |
progressElement.value = null; |
|
|
77 |
progressElement.max = null; |
|
|
78 |
progressElement.hidden = true; |
|
|
79 |
if (!text) spinnerElement.style.display = 'none'; |
|
|
80 |
} |
|
|
81 |
statusElement.innerHTML = text; |
|
|
82 |
}, |
|
|
83 |
totalDependencies: 0, |
|
|
84 |
monitorRunDependencies: function(left) { |
|
|
85 |
this.totalDependencies = Math.max(this.totalDependencies, left); |
|
|
86 |
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); |
|
|
87 |
} |
|
|
88 |
}; |
|
|
89 |
Module.setStatus('Downloading...'); |
|
|
90 |
window.onerror = function(event) { |
|
|
91 |
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus |
|
|
92 |
Module.setStatus('Exception thrown, see JavaScript console'); |
|
|
93 |
spinnerElement.style.display = 'none'; |
|
|
94 |
Module.setStatus = function(text) { |
|
|
95 |
if (text) Module.printErr('[post-exception status] ' + text); |
|
|
96 |
}; |
|
|
97 |
}; |
|
|
98 |
</script> |
|
|
99 |
<script async type="text/javascript" src="c2iec.js"></script> |
|
|
100 |
<script> |
|
|
101 |
var message; |
|
|
102 |
var point = -1; |
|
|
103 |
function getArea(){ |
|
|
104 |
point = -1; |
|
|
105 |
message = document.getElementById('input').value.split('\n'); |
|
|
106 |
} |
|
|
107 |
function areaInput(){ |
|
|
108 |
if(point >= message.length - 1){ |
|
|
109 |
return null; |
|
|
110 |
} |
|
|
111 |
point += 1; |
|
|
112 |
return message[point]; |
|
|
113 |
} |
|
|
114 |
window.prompt = function(message) { |
|
|
115 |
return areaInput(); |
|
|
116 |
}; |
|
|
117 |
function execEmscript(){ |
|
|
118 |
window.console = { |
|
|
119 |
log: function(str){ |
|
|
120 |
document.getElementById("output").value += "\n" + str; |
|
|
121 |
} |
|
|
122 |
} |
|
|
123 |
getArea(); |
|
|
124 |
run(); |
|
|
125 |
callMain(); |
|
|
126 |
} |
|
|
127 |
</script> |
|
|
128 |
<textarea id="input" cols="80" rows="30" placeholder="Input: Paste your C-Code here..."></textarea> |
|
|
129 |
<textarea id="output" cols="80" rows="30" placeholder="Output: Resulting ST code..."></textarea> |
|
|
130 |
<button onclick="execEmscript();">run</button> |
|
|
131 |
|
|
|
132 |
</body> |
|
|
133 |
</html> |
|
|
134 |
|
|
|
135 |
|