github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/ir/reassign_consistency_check.go (about) 1 // Copyright 2023 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 package ir 6 7 import ( 8 "fmt" 9 "path/filepath" 10 "strings" 11 12 "github.com/go-asm/go/cmd/compile/base" 13 "github.com/go-asm/go/cmd/src" 14 ) 15 16 // checkStaticValueResult compares the result from ReassignOracle.StaticValue 17 // with the corresponding result from ir.StaticValue to make sure they agree. 18 // This method is called only when turned on via build tag. 19 func checkStaticValueResult(n Node, newres Node) { 20 oldres := StaticValue(n) 21 if oldres != newres { 22 base.Fatalf("%s: new/old static value disagreement on %v:\nnew=%v\nold=%v", fmtFullPos(n.Pos()), n, newres, oldres) 23 } 24 } 25 26 // checkStaticValueResult compares the result from ReassignOracle.Reassigned 27 // with the corresponding result from ir.Reassigned to make sure they agree. 28 // This method is called only when turned on via build tag. 29 func checkReassignedResult(n *Name, newres bool) { 30 origres := Reassigned(n) 31 if newres != origres { 32 base.Fatalf("%s: new/old reassigned disagreement on %v (class %s) newres=%v oldres=%v", fmtFullPos(n.Pos()), n, n.Class.String(), newres, origres) 33 } 34 } 35 36 // fmtFullPos returns a verbose dump for pos p, including inlines. 37 func fmtFullPos(p src.XPos) string { 38 var sb strings.Builder 39 sep := "" 40 base.Ctxt.AllPos(p, func(pos src.Pos) { 41 fmt.Fprintf(&sb, sep) 42 sep = "|" 43 file := filepath.Base(pos.Filename()) 44 fmt.Fprintf(&sb, "%s:%d:%d", file, pos.Line(), pos.Col()) 45 }) 46 return sb.String() 47 }