Debian Codegraph @

operand/const.go

raw symbols SCIP
1 package operandscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/"
5 "strconvscip-go gomod github.com/golang/go/src go1.18 strconv/"
6 "stringsscip-go gomod github.com/golang/go/src go1.18 strings/"
7 )
8
9 // Constant represents a constant literal.
10 type Constantscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Constant# interface {
11 Opscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Op#
12 Bytesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Constant#Bytes.() int
13 constantscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Constant#constant.()
14 }
15
16 //go:generate go run make_const.go -output zconst.go
17
18 // Special cases for floating point string representation.
19 //
20 // Issue 387 pointed out that floating point values that happen to be integers
21 // need to have a decimal point to be parsed correctly.
22
23 // String returns a representation the 32-bit float which is guaranteed to be
24 // parsed as a floating point constant by the Go assembler.
25 func (f F32scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/F32#) Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/F32#String().() string { return asmfloatscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/asmfloat().(float64(f), 32) }
26
27 // String returns a representation the 64-bit float which is guaranteed to be
28 // parsed as a floating point constant by the Go assembler.
29 func (f F64scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/F64#) Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/F64#String().() string { return asmfloatscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/asmfloat().(float64(f), 64) }
30
31 // asmfloat represents x as a string such that the assembler scanner will always
32 // recognize it as a float. Specifically, ensure that when x is an integral
33 // value, the result will still have a decimal point.
34 func asmfloatscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/asmfloat().(x float64, bits int) string {
35 s := strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.FormatFloatscip-go gomod github.com/golang/go/src go1.18 strconv/FormatFloat().(x, 'f', -1, bits)
36 if !stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.18 strings/ContainsRune().(s, '.') {
37 s += ".0"
38 }
39 return s
40 }
41
42 // String is a string constant.
43 type Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String# string
44
45 // Asm returns an assembly syntax representation of the string s.
46 func (s Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#) Asmscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#Asm().() string { return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("$%q", s) }
47
48 // Bytes returns the length of s.
49 func (s Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#) Bytesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#Bytes().() int { return len(s) }
50
51 func (s Stringscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#) constantscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/String#constant().() {}
52
53 // Imm returns an unsigned integer constant with size guessed from x.
54 func Immscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Imm().(x uint64) Constantscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/Constant# {
55 switch {
56 case uint64(uint8(x)) == x:
57 return U8scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/U8#(x)
58 case uint64(uint16(x)) == x:
59 return U16scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/U16#(x)
60 case uint64(uint32(x)) == x:
61 return U32scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/U32#(x)
62 }
63 return U64scip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/operand`/U64#(x)
64 }