github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/obj/util.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 package obj 6 7 import ( 8 "github.com/shogo82148/std/io" 9 ) 10 11 const REG_NONE = 0 12 13 // Line returns a string containing the filename and line number for p 14 func (p *Prog) Line() string 15 16 func (p *Prog) InnermostLine(w io.Writer) 17 18 // InnermostLineNumber returns a string containing the line number for the 19 // innermost inlined function (if any inlining) at p's position 20 func (p *Prog) InnermostLineNumber() string 21 22 // InnermostLineNumberHTML returns a string containing the line number for the 23 // innermost inlined function (if any inlining) at p's position 24 func (p *Prog) InnermostLineNumberHTML() string 25 26 // InnermostFilename returns a string containing the innermost 27 // (in inlining) filename at p's position 28 func (p *Prog) InnermostFilename() string 29 30 /* ARM scond byte */ 31 const ( 32 C_SCOND = (1 << 4) - 1 33 C_SBIT = 1 << 4 34 C_PBIT = 1 << 5 35 C_WBIT = 1 << 6 36 C_FBIT = 1 << 7 37 C_UBIT = 1 << 7 38 C_SCOND_XOR = 14 39 ) 40 41 // CConv formats opcode suffix bits (Prog.Scond). 42 func CConv(s uint8) string 43 44 // CConvARM formats ARM opcode suffix bits (mostly condition codes). 45 func CConvARM(s uint8) string 46 47 func (p *Prog) String() string 48 49 func (p *Prog) InnermostString(w io.Writer) 50 51 // InstructionString returns a string representation of the instruction without preceding 52 // program counter or file and line number. 53 func (p *Prog) InstructionString() string 54 55 // WriteInstructionString writes a string representation of the instruction without preceding 56 // program counter or file and line number. 57 func (p *Prog) WriteInstructionString(w io.Writer) 58 59 func (ctxt *Link) NewProg() *Prog 60 61 func (ctxt *Link) CanReuseProgs() bool 62 63 // Dconv accepts an argument 'a' within a prog 'p' and returns a string 64 // with a formatted version of the argument. 65 func Dconv(p *Prog, a *Addr) string 66 67 // DconvWithABIDetail accepts an argument 'a' within a prog 'p' 68 // and returns a string with a formatted version of the argument, in 69 // which text symbols are rendered with explicit ABI selectors. 70 func DconvWithABIDetail(p *Prog, a *Addr) string 71 72 // WriteDconv accepts an argument 'a' within a prog 'p' 73 // and writes a formatted version of the arg to the writer. 74 func WriteDconv(w io.Writer, p *Prog, a *Addr) 75 76 func (a *Addr) WriteNameTo(w io.Writer) 77 78 // RegisterOpSuffix assigns cconv function for formatting opcode suffixes 79 // when compiling for GOARCH=arch. 80 // 81 // cconv is never called with 0 argument. 82 func RegisterOpSuffix(arch string, cconv func(uint8) string) 83 84 const ( 85 // Because of masking operations in the encodings, each register 86 // space should start at 0 modulo some power of 2. 87 RBase386 = 1 * 1024 88 RBaseAMD64 = 2 * 1024 89 RBaseARM = 3 * 1024 90 RBasePPC64 = 4 * 1024 91 RBaseARM64 = 8 * 1024 92 RBaseMIPS = 13 * 1024 93 RBaseS390X = 14 * 1024 94 RBaseRISCV = 15 * 1024 95 RBaseWasm = 16 * 1024 96 RBaseLOONG64 = 17 * 1024 97 ) 98 99 // RegisterRegister binds a pretty-printer (Rconv) for register 100 // numbers to a given register number range. Lo is inclusive, 101 // hi exclusive (valid registers are lo through hi-1). 102 func RegisterRegister(lo, hi int, Rconv func(int) string) 103 104 func Rconv(reg int) string 105 106 // Each architecture is allotted a distinct subspace: [Lo, Hi) for declaring its 107 // arch-specific register list numbers. 108 const ( 109 RegListARMLo = 0 110 RegListARMHi = 1 << 16 111 112 // arm64 uses the 60th bit to differentiate from other archs 113 RegListARM64Lo = 1 << 60 114 RegListARM64Hi = 1<<61 - 1 115 116 // x86 uses the 61th bit to differentiate from other archs 117 RegListX86Lo = 1 << 61 118 RegListX86Hi = 1<<62 - 1 119 ) 120 121 // RegisterRegisterList binds a pretty-printer (RLconv) for register list 122 // numbers to a given register list number range. Lo is inclusive, 123 // hi exclusive (valid register list are lo through hi-1). 124 func RegisterRegisterList(lo, hi int64, rlconv func(int64) string) 125 126 func RLconv(list int64) string 127 128 // RegisterSpecialOperands binds a pretty-printer (SPCconv) for special 129 // operand numbers to a given special operand number range. Lo is inclusive, 130 // hi is exclusive (valid special operands are lo through hi-1). 131 func RegisterSpecialOperands(lo, hi int64, rlconv func(int64) string) 132 133 // SPCconv returns the string representation of the special operand spc. 134 func SPCconv(spc int64) string 135 136 // RegisterOpcode binds a list of instruction names 137 // to a given instruction number range. 138 func RegisterOpcode(lo As, Anames []string) 139 140 func (a As) String() string 141 142 var Anames = []string{ 143 "XXX", 144 "CALL", 145 "DUFFCOPY", 146 "DUFFZERO", 147 "END", 148 "FUNCDATA", 149 "JMP", 150 "NOP", 151 "PCALIGN", 152 "PCDATA", 153 "RET", 154 "GETCALLERPC", 155 "TEXT", 156 "UNDEF", 157 } 158 159 func Bool2int(b bool) int