1
2
3
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 case REG_V0 <= r && r <= REG_V31:
32 return fmt.Sprintf("V%d", r-REG_V0)
33 default:
34 return fmt.Sprintf("Rgok(%d)", r-obj.RBaseRISCV)
35 }
36 }
37
38 func opSuffixString(s uint8) string {
39 if s&rmSuffixBit == 0 {
40 return ""
41 }
42
43 ss, err := rmSuffixString(s)
44 if err != nil {
45 ss = fmt.Sprintf("<invalid 0x%x>", s)
46 }
47 if ss == "" {
48 return ss
49 }
50 return fmt.Sprintf(".%s", ss)
51 }
52
View as plain text