-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
122 lines (103 loc) · 2.4 KB
/
main.go
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
// Go has strange behavior -- in one case it doesn't support generics
// In over case it can't convert []AnyType to []interface[] even pointers
// So it doesn't support sub-typing that makes generic coding really hard
package main
import (
"awesomeProject/go2ssa"
"fmt"
"go/ast"
"go/parser"
"go/scanner"
"go/token"
"os"
"reflect"
)
func _fake() {
ast.Print(nil, nil)
token.NewFileSet()
reflect.ValueOf(nil)
fmt.Print()
parser.ParseExpr("")
}
func check(e error) {
if e != nil {
panic(e)
}
}
func GoydaFilter(k string, v reflect.Value) bool {
if v.Type().AssignableTo(reflect.TypeOf(token.Pos(0))) {
return false
}
switch k {
case "Obj":
return false
}
return ast.NotNilFilter(k, v)
}
func main() {
println("----")
filePath := "./hello.go"
fset := token.NewFileSet()
code, err := parser.ParseFile(fset, filePath, nil, 0)
if err != nil {
panic(err)
}
g := &go2ssa.GhostVisitor{}
ast.Walk(g, code)
//fmt.Printf("%+v\n", g.Result)
println("render:")
for _, operator := range g.Result.Blocks[0].Items {
operator.RenderTo(os.Stdout, "")
println()
}
//Fprint(os.Stdout, fset, code, GoydaFilter)
return
}
//return
//op2 := ir.Operator{
// Name: "fn",
// Dialect: "go",
// Blocks: nil,
// ReturnNames: "",
// Attributes: map[string]ir.Attribute{"dfadsfg": ir.StringAttr("\"dsad\""), "dfadsfg2": ir.NumberAttr(123)},
//}
//label := &ir.BlockLabel{
// Name: "^bb0",
// ParamValues: nil,
// ParamTypes: nil,
//}
//bb0 := ir.BasicBlock{
// Label: label,
// Items: []ir.Operator{op2, op2},
//}
//
//op := ir.Operator{
// Name: "fn",
// Dialect: "go",
// Blocks: []ir.Region{[]ir.BasicBlock{bb0, bb0}},
// ReturnNames: "%078",
// Attributes: map[string]ir.Attribute{"symbol_name": ir.StringAttr("@main")},
//}
func main2() {
filename := "./resources/result.clj"
src, err := os.ReadFile(filename)
check(err)
// src := []byte("cos(x) + 1i*sin(x) // Euler")
// Initialize the scanner.
var s scanner.Scanner
fset := token.NewFileSet()
file := fset.AddFile("", fset.Base(), len(src)) // register input "file"
s.Init(file, src, nil /* no error handler */, scanner.ScanComments)
// Repeated calls to Scan yield the token sequence found in the input.
for {
_, tok, lit := s.Scan()
if tok == token.SEMICOLON {
continue
}
if tok == token.EOF {
break
}
fmt.Printf("\t%s %q\n", tok, lit)
// fmt.Printf("%s\t%s\t%q\n", fset.Position(pos), tok, lit)
}
}