~emersion/go-drm

66aafcb8e4628f28f778eb9eda337b1a7ddc8fe1 — Simon Ser a month ago ae7f101
Move String function outside of machine-generated code

This will allow us to implement better modifier pretty-printing.
3 files changed, 29 insertions(+), 8 deletions(-)

M fourcc.go
M fourcc.py
M fourcc_generated.go
M fourcc.go => fourcc.go +21 -0
@@ 4,10 4,31 @@ package drm

type Format uint32

func (fmt Format) String() string {
	if s := fmt.str(); s != "" {
		return s
	}
	return "unknown"
}

type ModifierVendor uint8

func (vendor ModifierVendor) String() string {
	if s := vendor.str(); s != "" {
		return s
	}
	return "unknown"
}

type Modifier uint64

func (mod Modifier) String() string {
	if s := mod.str(); s != "" {
		return s
	}
	return "unknown"
}

func (mod Modifier) Vendor() ModifierVendor {
	return ModifierVendor(mod >> 56)
}

M fourcc.py => fourcc.py +2 -2
@@ 132,13 132,13 @@ with open("fourcc_generated.go", "w+") as go_file:
			go_file.write('\t' + cst["go_ident"] + ' ' + cst["type"] + ' = ' + cst["value"] + '\n')
		go_file.write(')\n')
		go_file.write('\n')
		go_file.write('func (v ' + t + ') String() string {\n')
		go_file.write('func (v ' + t + ') str() string {\n')
		go_file.write('\tswitch v {\n')
		for cst in consts[t]:
			go_file.write('\tcase ' + cst["go_ident"] + ':\n')
			go_file.write('\t\treturn "' + cst["name"] + '"\n')
		go_file.write('\tdefault:\n')
		go_file.write('\t\treturn "unknown"\n')
		go_file.write('\t\treturn ""\n')
		go_file.write('\t}\n')
		go_file.write('}\n')


M fourcc_generated.go => fourcc_generated.go +6 -6
@@ 111,7 111,7 @@ const (
	FormatYVU444               Format = 0x34325659
)

func (v Format) String() string {
func (v Format) str() string {
	switch v {
	case FormatInvalid:
		return "invalid"


@@ 324,7 324,7 @@ func (v Format) String() string {
	case FormatYVU444:
		return "YVU444"
	default:
		return "unknown"
		return ""
	}
}



@@ 341,7 341,7 @@ const (
	ModifierVendorAmlogic   ModifierVendor = 0xA
)

func (v ModifierVendor) String() string {
func (v ModifierVendor) str() string {
	switch v {
	case ModifierVendorIntel:
		return "Intel"


@@ 364,7 364,7 @@ func (v ModifierVendor) String() string {
	case ModifierVendorAmlogic:
		return "Amlogic"
	default:
		return "unknown"
		return ""
	}
}



@@ 402,7 402,7 @@ const (
	ModifierALLWINNER_TILED                  Modifier = 0x900000000000001
)

func (v Modifier) String() string {
func (v Modifier) str() string {
	switch v {
	case ModifierGENERIC_16_16_TILE:
		return "GENERIC_16_16_TILE"


@@ 467,6 467,6 @@ func (v Modifier) String() string {
	case ModifierALLWINNER_TILED:
		return "ALLWINNER_TILED"
	default:
		return "unknown"
		return ""
	}
}