| 1 | // Package attr provides attributes for text and data sections. |
| 2 | package attrscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/ |
| 3 | |
| 4 | import ( |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 6 | "math/bitsscip-go gomod github.com/golang/go/src go1.18 `math/bits`/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.18 strings/" |
| 8 | ) |
| 9 | |
| 10 | // Attribute represents TEXT or DATA flags. |
| 11 | type Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute# uint16 |
| 12 | |
| 13 | //go:generate go run make_textflag.go -output ztextflag.go |
| 14 | |
| 15 | // Asm returns a representation of the attributes in assembly syntax. This may use macros from "textflags.h"; see ContainsTextFlags() to determine if this header is required. |
| 16 | func (a Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#) Asmscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#Asm().() string { |
| 17 | parts, rest := a.splitscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#split().() |
| 18 | if len(parts) == 0 || rest != 0 { |
| 19 | parts = append(parts, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("%d", rest)) |
| 20 | } |
| 21 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Joinscip-go gomod github.com/golang/go/src go1.18 strings/Join().(parts, "|") |
| 22 | } |
| 23 | |
| 24 | // ContainsTextFlags returns whether the Asm() representation requires macros in "textflags.h". |
| 25 | func (a Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#) ContainsTextFlagsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#ContainsTextFlags().() bool { |
| 26 | flags, _ := a.splitscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#split().() |
| 27 | return len(flags) > 0 |
| 28 | } |
| 29 | |
| 30 | // split splits a into known flags and any remaining bits. |
| 31 | func (a Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#) splitscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#split().() ([]string, Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#) { |
| 32 | var flags []string |
| 33 | var rest Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute# |
| 34 | for a != 0 { |
| 35 | i := uint(bitsscip-go gomod github.com/golang/go/src go1.18 `math/bits`/.TrailingZeros16scip-go gomod github.com/golang/go/src go1.18 `math/bits`/TrailingZeros16().(uint16(a))) |
| 36 | bit := Attributescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/Attribute#(1) << i |
| 37 | if flag := attrnamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/attr`/attrname.[bit]; flag != "" { |
| 38 | flags = append(flags, flag) |
| 39 | } else { |
| 40 | rest |= bit |
| 41 | } |
| 42 | a ^= bit |
| 43 | } |
| 44 | return flags, rest |
| 45 | } |