github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/ssa/_gen/rulegen.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This program generates Go code that applies rewrite rules to a Value. 6 // The generated code implements a function of type func (v *Value) bool 7 // which reports whether if did something. 8 // Ideas stolen from Swift: http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-2000-2.html 9 10 package main 11 12 import ( 13 "github.com/shogo82148/std/go/ast" 14 ) 15 16 type Rule struct { 17 Rule string 18 Loc string 19 } 20 21 func (r Rule) String() string 22 23 // Node can be a Statement or an ast.Expr. 24 type Node interface{} 25 26 // Statement can be one of our high-level statement struct types, or an 27 // ast.Stmt under some limited circumstances. 28 type Statement interface{} 29 30 // BodyBase is shared by all of our statement pseudo-node types which can 31 // contain other statements. 32 type BodyBase struct { 33 List []Statement 34 CanFail bool 35 } 36 37 // These types define some high-level statement struct types, which can be used 38 // as a Statement. This allows us to keep some node structs simpler, and have 39 // higher-level nodes such as an entire rule rewrite. 40 // 41 // Note that ast.Expr is always used as-is; we don't declare our own expression 42 // nodes. 43 type ( 44 File struct { 45 BodyBase 46 Arch arch 47 Suffix string 48 } 49 Func struct { 50 BodyBase 51 Kind string 52 Suffix string 53 ArgLen int32 54 } 55 Switch struct { 56 BodyBase 57 Expr ast.Expr 58 } 59 Case struct { 60 BodyBase 61 Expr ast.Expr 62 } 63 RuleRewrite struct { 64 BodyBase 65 Match, Cond, Result string 66 Check string 67 68 Alloc int 69 Loc string 70 CommuteDepth int 71 } 72 Declare struct { 73 Name string 74 Value ast.Expr 75 } 76 CondBreak struct { 77 Cond ast.Expr 78 InsideCommuteLoop bool 79 } 80 StartCommuteLoop struct { 81 Depth int 82 V string 83 } 84 )