| |
| |
| |
|
|
| package ir |
|
|
| import ( |
| "cmd/compile/internal/base" |
| "cmd/compile/internal/types" |
| "cmd/internal/obj" |
| "cmd/internal/src" |
| "go/constant" |
| ) |
|
|
| |
| type Decl struct { |
| miniNode |
| X *Name |
| } |
|
|
| func NewDecl(pos src.XPos, op Op, x *Name) *Decl { |
| n := &Decl{X: x} |
| n.pos = pos |
| switch op { |
| default: |
| panic("invalid Decl op " + op.String()) |
| case ODCL: |
| n.op = op |
| } |
| return n |
| } |
|
|
| func (*Decl) isStmt() {} |
|
|
| |
| |
| |
| |
| |
| |
| |
| type Stmt interface { |
| Node |
| isStmt() |
| PtrInit() *Nodes |
| } |
|
|
| |
| type miniStmt struct { |
| miniNode |
| init Nodes |
| } |
|
|
| func (*miniStmt) isStmt() {} |
|
|
| func (n *miniStmt) Init() Nodes { return n.init } |
| func (n *miniStmt) SetInit(x Nodes) { n.init = x } |
| func (n *miniStmt) PtrInit() *Nodes { return &n.init } |
|
|
| |
| |
| |
| type AssignListStmt struct { |
| miniStmt |
| Lhs Nodes |
| Def bool |
| Rhs Nodes |
| } |
|
|
| func NewAssignListStmt(pos src.XPos, op Op, lhs, rhs []Node) *AssignListStmt { |
| n := &AssignListStmt{} |
| n.pos = pos |
| n.SetOp(op) |
| n.Lhs = lhs |
| n.Rhs = rhs |
| return n |
| } |
|
|
| func (n *AssignListStmt) SetOp(op Op) { |
| switch op { |
| default: |
| panic(n.no("SetOp " + op.String())) |
| case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV, OSELRECV2: |
| n.op = op |
| } |
| } |
|
|
| |
| |
| type AssignStmt struct { |
| miniStmt |
| X Node |
| Def bool |
| Y Node |
| } |
|
|
| func NewAssignStmt(pos src.XPos, x, y Node) *AssignStmt { |
| n := &AssignStmt{X: x, Y: y} |
| n.pos = pos |
| n.op = OAS |
| return n |
| } |
|
|
| func (n *AssignStmt) SetOp(op Op) { |
| switch op { |
| default: |
| panic(n.no("SetOp " + op.String())) |
| case OAS: |
| n.op = op |
| } |
| } |
|
|
| |
| type AssignOpStmt struct { |
| miniStmt |
| X Node |
| AsOp Op |
| Y Node |
| IncDec bool |
| } |
|
|
| func NewAssignOpStmt(pos src.XPos, asOp Op, x, y Node) *AssignOpStmt { |
| n := &AssignOpStmt{AsOp: asOp, X: x, Y: y} |
| n.pos = pos |
| n.op = OASOP |
| return n |
| } |
|
|
| |
| type BlockStmt struct { |
| miniStmt |
| List Nodes |
| } |
|
|
| func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt { |
| n := &BlockStmt{} |
| n.pos = pos |
| if !pos.IsKnown() { |
| n.pos = base.Pos |
| if len(list) > 0 { |
| n.pos = list[0].Pos() |
| } |
| } |
| n.op = OBLOCK |
| n.List = list |
| return n |
| } |
|
|
| |
| type BranchStmt struct { |
| miniStmt |
| Label *types.Sym |
| } |
|
|
| func NewBranchStmt(pos src.XPos, op Op, label *types.Sym) *BranchStmt { |
| switch op { |
| case OBREAK, OCONTINUE, OFALL, OGOTO: |
| |
| default: |
| panic("NewBranch " + op.String()) |
| } |
| n := &BranchStmt{Label: label} |
| n.pos = pos |
| n.op = op |
| return n |
| } |
|
|
| func (n *BranchStmt) SetOp(op Op) { |
| switch op { |
| default: |
| panic(n.no("SetOp " + op.String())) |
| case OBREAK, OCONTINUE, OFALL, OGOTO: |
| n.op = op |
| } |
| } |
|
|
| func (n *BranchStmt) Sym() *types.Sym { return n.Label } |
|
|
| |
| type CaseClause struct { |
| miniStmt |
| Var *Name |
| List Nodes |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| RTypes Nodes |
|
|
| Body Nodes |
| } |
|
|
| func NewCaseStmt(pos src.XPos, list, body []Node) *CaseClause { |
| n := &CaseClause{List: list, Body: body} |
| n.pos = pos |
| n.op = OCASE |
| return n |
| } |
|
|
| type CommClause struct { |
| miniStmt |
| Comm Node |
| Body Nodes |
| } |
|
|
| func NewCommStmt(pos src.XPos, comm Node, body []Node) *CommClause { |
| n := &CommClause{Comm: comm, Body: body} |
| n.pos = pos |
| n.op = OCASE |
| return n |
| } |
|
|
| |
| type ForStmt struct { |
| miniStmt |
| Label *types.Sym |
| Cond Node |
| Post Node |
| Body Nodes |
| DistinctVars bool |
| } |
|
|
| func NewForStmt(pos src.XPos, init Node, cond, post Node, body []Node, distinctVars bool) *ForStmt { |
| n := &ForStmt{Cond: cond, Post: post} |
| n.pos = pos |
| n.op = OFOR |
| if init != nil { |
| n.init = []Node{init} |
| } |
| n.Body = body |
| n.DistinctVars = distinctVars |
| return n |
| } |
|
|
| |
| |
| |
| |
| |
| type GoDeferStmt struct { |
| miniStmt |
| Call Node |
| DeferAt Expr |
| } |
|
|
| func NewGoDeferStmt(pos src.XPos, op Op, call Node) *GoDeferStmt { |
| n := &GoDeferStmt{Call: call} |
| n.pos = pos |
| switch op { |
| case ODEFER, OGO: |
| n.op = op |
| default: |
| panic("NewGoDeferStmt " + op.String()) |
| } |
| return n |
| } |
|
|
| |
| type IfStmt struct { |
| miniStmt |
| Cond Node |
| Body Nodes |
| Else Nodes |
| Likely bool |
| } |
|
|
| func NewIfStmt(pos src.XPos, cond Node, body, els []Node) *IfStmt { |
| n := &IfStmt{Cond: cond} |
| n.pos = pos |
| n.op = OIF |
| n.Body = body |
| n.Else = els |
| return n |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| type JumpTableStmt struct { |
| miniStmt |
|
|
| |
| |
| |
| Idx Node |
|
|
| |
| |
| |
| Cases []constant.Value |
| Targets []*types.Sym |
| } |
|
|
| func NewJumpTableStmt(pos src.XPos, idx Node) *JumpTableStmt { |
| n := &JumpTableStmt{Idx: idx} |
| n.pos = pos |
| n.op = OJUMPTABLE |
| return n |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| type InterfaceSwitchStmt struct { |
| miniStmt |
|
|
| Case Node |
| Itab Node |
| RuntimeType Node |
| Hash Node |
| Descriptor *obj.LSym |
| } |
|
|
| func NewInterfaceSwitchStmt(pos src.XPos, case_, itab, runtimeType, hash Node, descriptor *obj.LSym) *InterfaceSwitchStmt { |
| n := &InterfaceSwitchStmt{ |
| Case: case_, |
| Itab: itab, |
| RuntimeType: runtimeType, |
| Hash: hash, |
| Descriptor: descriptor, |
| } |
| n.pos = pos |
| n.op = OINTERFACESWITCH |
| return n |
| } |
|
|
| |
| type InlineMarkStmt struct { |
| miniStmt |
| Index int64 |
| } |
|
|
| func NewInlineMarkStmt(pos src.XPos, index int64) *InlineMarkStmt { |
| n := &InlineMarkStmt{Index: index} |
| n.pos = pos |
| n.op = OINLMARK |
| return n |
| } |
|
|
| func (n *InlineMarkStmt) Offset() int64 { return n.Index } |
| func (n *InlineMarkStmt) SetOffset(x int64) { n.Index = x } |
|
|
| |
| type LabelStmt struct { |
| miniStmt |
| Label *types.Sym |
| } |
|
|
| func NewLabelStmt(pos src.XPos, label *types.Sym) *LabelStmt { |
| n := &LabelStmt{Label: label} |
| n.pos = pos |
| n.op = OLABEL |
| return n |
| } |
|
|
| func (n *LabelStmt) Sym() *types.Sym { return n.Label } |
|
|
| |
| type RangeStmt struct { |
| miniStmt |
| Label *types.Sym |
| Def bool |
| X Node |
| RType Node `mknode:"-"` |
| Key Node |
| Value Node |
| Body Nodes |
| DistinctVars bool |
| Prealloc *Name |
|
|
| |
| |
| |
| KeyTypeWord Node `mknode:"-"` |
| KeySrcRType Node `mknode:"-"` |
| ValueTypeWord Node `mknode:"-"` |
| ValueSrcRType Node `mknode:"-"` |
| } |
|
|
| func NewRangeStmt(pos src.XPos, key, value, x Node, body []Node, distinctVars bool) *RangeStmt { |
| n := &RangeStmt{X: x, Key: key, Value: value} |
| n.pos = pos |
| n.op = ORANGE |
| n.Body = body |
| n.DistinctVars = distinctVars |
| return n |
| } |
|
|
| |
| type ReturnStmt struct { |
| miniStmt |
| Results Nodes |
| } |
|
|
| func NewReturnStmt(pos src.XPos, results []Node) *ReturnStmt { |
| n := &ReturnStmt{} |
| n.pos = pos |
| n.op = ORETURN |
| n.Results = results |
| return n |
| } |
|
|
| |
| type SelectStmt struct { |
| miniStmt |
| Label *types.Sym |
| Cases []*CommClause |
|
|
| |
| Compiled Nodes |
| } |
|
|
| func NewSelectStmt(pos src.XPos, cases []*CommClause) *SelectStmt { |
| n := &SelectStmt{Cases: cases} |
| n.pos = pos |
| n.op = OSELECT |
| return n |
| } |
|
|
| |
| type SendStmt struct { |
| miniStmt |
| Chan Node |
| Value Node |
| } |
|
|
| func NewSendStmt(pos src.XPos, ch, value Node) *SendStmt { |
| n := &SendStmt{Chan: ch, Value: value} |
| n.pos = pos |
| n.op = OSEND |
| return n |
| } |
|
|
| |
| type SwitchStmt struct { |
| miniStmt |
| Tag Node |
| Cases []*CaseClause |
| Label *types.Sym |
|
|
| |
| Compiled Nodes |
| } |
|
|
| func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseClause) *SwitchStmt { |
| n := &SwitchStmt{Tag: tag, Cases: cases} |
| n.pos = pos |
| n.op = OSWITCH |
| return n |
| } |
|
|
| |
| |
| type TailCallStmt struct { |
| miniStmt |
| Call *CallExpr |
| } |
|
|
| func NewTailCallStmt(pos src.XPos, call *CallExpr) *TailCallStmt { |
| n := &TailCallStmt{Call: call} |
| n.pos = pos |
| n.op = OTAILCALL |
| return n |
| } |
|
|
| |
| type TypeSwitchGuard struct { |
| miniNode |
| Tag *Ident |
| X Node |
| Used bool |
| } |
|
|
| func NewTypeSwitchGuard(pos src.XPos, tag *Ident, x Node) *TypeSwitchGuard { |
| n := &TypeSwitchGuard{Tag: tag, X: x} |
| n.pos = pos |
| n.op = OTYPESW |
| return n |
| } |
|
|