-
Notifications
You must be signed in to change notification settings - Fork 16
/
func.go
88 lines (70 loc) · 1.75 KB
/
func.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
// Copyright (c) 2016 Timo Savola. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gen
import (
"github.com/tsavola/wag/abi"
"github.com/tsavola/wag/internal/gen/link"
"github.com/tsavola/wag/internal/gen/regalloc"
"github.com/tsavola/wag/internal/gen/val"
"github.com/tsavola/wag/internal/module"
"github.com/tsavola/wag/internal/obj"
"github.com/tsavola/wag/trap"
)
type BranchTarget struct {
Label link.L
StackOffset int32
ValueType abi.Type
FuncEnd bool
}
type BranchTable struct {
RODataAddr int32
Targets []*BranchTarget
CodeStackOffset int32 // -1 indicates common offset
}
type TrapTrampoline struct {
StackOffset int32
Link link.L
}
type Func struct {
*module.M
*Prog
Regs regalloc.Allocator
ResultType abi.Type
Vars []VarState
NumStackParams int32
NumInitedVars int32
StackOffset int32
MaxStackOffset int32
StackCheckAddr int32
Operands []val.Operand
MinBlockOperand int
NumStableOperands int
NumPersistentOperands int
BranchTargets []*BranchTarget
BranchTables []BranchTable
TrapTrampolines [trap.NumTraps]TrapTrampoline
}
func (f *Func) Consumed(x val.Operand) {
switch x.Storage {
case val.TempReg:
f.Regs.Free(x.Type, x.Reg())
case val.Stack:
f.StackOffset -= obj.Word
}
}
func (f *Func) TrapTrampolineAddr(id trap.Id) (addr int32) {
t := &f.TrapTrampolines[id]
if t.StackOffset == f.StackOffset {
addr = t.Link.Addr
}
return
}
func (f *Func) InitTrapTrampoline(id trap.Id) {
t := &f.TrapTrampolines[id]
t.StackOffset = f.StackOffset
t.Link.Addr = f.Text.Addr
}
func (f *Func) MapCallAddr(retAddr int32) {
f.Map.PutCallSite(retAddr, f.StackOffset+obj.Word)
}