forked from tmc/ssaview
/
index.html
109 lines (98 loc) · 2.85 KB
/
index.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
107
108
109
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<style> #source, #result { height: 900px; }</style>
</head>
<body>
<div class="container">
<h1>Go SSA viewer, now with method bodies!</h1>
<p class="lead"><a href="https://github.com/julien-lange/ssaview">https://github.com/julien-lange/ssaview</a>
(forked from <a href="https://github.com/tmc/ssaview">https://github.com/tmc/ssaview</a>)</p>
<p class="lead">Shows the <a href="http://en.wikipedia.org/wiki/Static_single_assignment_form">SSA (Static Single Assignment)</a> representation of input code.<br/>Uses the wonderful <a href="https://godoc.org/golang.org/x/tools/go/ssa">golang.org/x/tools/go/ssa</a> package.</p>
</div>
<div id="tools">
<div class="well row">
<div>
<button id="submit" class="btn btn-default" type="submit">Render SSA</button>
status: <code id="msg" class="has-error"></code></li><br/>
</div>
<div id="userinput" class="col-sm-6">
<form id="form" target="/ssa" method="post">
Input
<pre id="source">
package main
import (
"fmt"
)
type I interface { method(y int) int }
type A struct { x int }
func (x A) method(y int) int {return y}
func foo(x I) {
a := x.(A)
a.x = 0
fmt.Println("2:", a.x)
}
func main() {
a := A{42}
a.method(35)
fmt.Println("1:", a.x) // Prints 42
foo(a) // Prints 0
fmt.Println("3:", a.x) // Still prints 42 -- struct was "passed by value" to the interface parameter
}</pre>
</form>
</div>
<div class="col-sm-6">
Result
<pre id="result"></pre>
</div>
</div>
</div>
<script>
(function() {
var form = $('#form')
,error = $('#error')
,msg = $('#msg')
,source = $('#source')
,submit = $('#submit')
,result = $('#result')
,editor = ace.edit("source")
,result = ace.edit("result")
form.submit(function(e){
msg.text("converting to SSA..")
e.preventDefault();
$.post(form[0].target, editor.getValue())
.done(function(data) {
data = $.parseJSON(data)
result.setValue(data.All)
result.clearSelection()
result.resize(true)
editor.resize(true)
error.text("(no errors)")
msg.text("done")
})
.fail(function (data) {
msg.text("error:"+$.parseJSON(data.responseText).Error)
})
})
var sourceTimeout
source.on('keyup', function() {
if (sourceTimeout) { window.clearTimeout(sourceTimeout) }
sourceTimeout = setTimeout(function(){
source.submit()
}, 300)
})
$('#submit').hide() // don't need it if we have js
source.submit()
editor.setTheme("ace/theme/tomorrow_night")
editor.getSession().setMode("ace/mode/golang")
result.setTheme("ace/theme/tomorrow_night")
result.getSession().setMode("ace/mode/golang")
result.setReadOnly(true)
// @todo resizing
}())
</script>
</body>
</html>