Source file src/cmd/internal/obj/riscv/list.go

     1  // Copyright 2019 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 riscv
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"cmd/internal/obj"
    11  )
    12  
    13  func init() {
    14  	obj.RegisterRegister(obj.RBaseRISCV, REG_END, RegName)
    15  	obj.RegisterOpcode(obj.ABaseRISCV, Anames)
    16  	obj.RegisterOpSuffix("riscv64", opSuffixString)
    17  }
    18  
    19  func RegName(r int) string {
    20  	switch {
    21  	case r == 0:
    22  		return "NONE"
    23  	case r == REG_G:
    24  		return "g"
    25  	case r == REG_SP:
    26  		return "SP"
    27  	case REG_X0 <= r && r <= REG_X31:
    28  		return fmt.Sprintf("X%d", r-REG_X0)
    29  	case REG_F0 <= r && r <= REG_F31:
    30  		return fmt.Sprintf("F%d", r-REG_F0)
    31  	default:
    32  		return fmt.Sprintf("Rgok(%d)", r-obj.RBaseRISCV)
    33  	}
    34  }
    35  
    36  func opSuffixString(s uint8) string {
    37  	if s&rmSuffixBit == 0 {
    38  		return ""
    39  	}
    40  
    41  	ss, err := rmSuffixString(s)
    42  	if err != nil {
    43  		ss = fmt.Sprintf("<invalid 0x%x>", s)
    44  	}
    45  	if ss == "" {
    46  		return ss
    47  	}
    48  	return fmt.Sprintf(".%s", ss)
    49  }
    50  

View as plain text