forked from deleterium/SmartC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.html
106 lines (102 loc) · 3.96 KB
/
debug.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="dist/smartc.dev.js"></script>
<script>
function compileCode () {
document.getElementById('assembly').innerHTML = '';
document.getElementById('debug-info').innerHTML = '';
const sourceCode = document.getElementById('sourcecode').value;
const t0 = new Date();
try {
const compiler = new SmartC({ language: 'C', sourceCode });
compiler.compile();
const asmCode = compiler.getAssemblyCode();
const bcode = compiler.getMachineCode();
const t1 = new Date();
let compileMessage = `<span class='msg_success'>Compile sucessfull!!!</span> Done at ${t1.getHours()}:${t1.getMinutes()}:${t1.getSeconds()} in ${t1 - t0} ms.`;
if (bcode.Warnings.length != 0) {
compileMessage += `<br>${bcode.Warnings}`;
}
document.getElementById('status').innerHTML = compileMessage;
document.getElementById('assembly').innerText = asmCode;
document.getElementById('debug-info').innerHTML = JSON.stringify(bcode, null, ' ');
} catch (e) {
document.getElementById('status').innerHTML = `<span class='msg_failure'>Compile failed</span><br>${e.message}`
document.getElementById('debug-info').innerHTML = e.stack
}
}
function startUpTest () {
const startUpTest = new SmartC({
language: 'C',
sourceCode: '#pragma version dev\n#pragma maxAuxVars 1\nlong a, b, c; a=b/~c;'
})
try {
startUpTest.compile()
if (startUpTest.getMachineCode().MachineCodeHashId === '7488355358104845254') {
document.getElementById('status').innerHTML = '<span class="msg_success">Start up test done!</span>'
} else {
document.getElementById('status').innerHTML = '<span class="msg_failure">Start up test failed...</span>'
}
} catch (e) {
document.getElementById('status').innerHTML = '<span class="msg_failure">Start up test crashed...</span>'
}
}
window.onload = () => {
document.getElementById("compile").addEventListener('click', compileCode);
startUpTest();
}
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=800, initial-scale=1.0">
<title>Simple debugger page</title>
<style type="text/css" media="all">
body {
font-family: 'Courier New', Courier, monospace;
font-size: 14pt;
box-sizing: border-box;
}
textarea {
padding: 1ch;
height: 75vh;
font-size: inherit;
width: calc(50vw - 2ch);
}
td {
vertical-align: top;
}
pre {
padding: 1ch;
border: 1px black solid;
word-wrap: anywhere;
white-space: pre-wrap;
margin: 0;
}
.msg_failure {
font-weight: bold;
color: red;
}
.msg_success {
font-weight: bold;
color: green;
}
</style>
</head>
<body>
<header>Simple debugger page</header>
<p>Use this page to debug or inspect SmartC process, using a browser.</p>
<main>
<div style="width: 100%;">
<div style="width: 50vw; float: left;">
<textarea id="sourcecode" spellcheck="false"></textarea><br><button id="compile" accesskey="c">Compile</button>
</div>
<div style="margin-left: 53vw;">
<pre id="status"></pre>
<pre id="assembly"></pre>
<pre id="debug-info"></pre>
</div>
</div>
</main>
</body>
</html>