// SPDX-FileCopyrightText: 2024 Himbeer // // SPDX-License-Identifier: GPL-3.0-or-later package main import "fmt" type cerType interface { fmt.Stringer qbeBaseType() string qbeExtType() string qbeABIType() string } type cerInteger struct { bits int unsigned bool } func (c cerInteger) String() string { unsigned := "" if c.unsigned { unsigned = "u" } return fmt.Sprintf("%sint%d", unsigned, c.bits) } func (c cerInteger) qbeBaseType() string { switch { case c.bits > 32: return "l" default: return "w" } } func (c cerInteger) qbeExtType() string { switch { case c.bits > 32: return "l" case c.bits > 16: return "w" case c.bits > 8: return "h" default: return "b" } } func (c cerInteger) qbeABIType() string { signedness := "s" if c.unsigned { signedness = "u" } switch { case c.bits > 32: return "l" case c.bits > 16: return "w" case c.bits > 8: return signedness + "h" default: return signedness + "b" } } func resolveType(name string) cerType { switch name { case "int8": return cerInteger{bits: 8} case "uint8": return cerInteger{bits: 8, unsigned: true} case "int16": return cerInteger{bits: 16} case "uint16": return cerInteger{bits: 16, unsigned: true} case "int32": return cerInteger{bits: 32} case "uint32": return cerInteger{bits: 32, unsigned: true} case "int64": return cerInteger{bits: 64} case "uint64": return cerInteger{bits: 64, unsigned: true} default: return nil } } var ( cerInt8 = cerInteger{bits: 8} cerUint8 = cerInteger{bits: 8, unsigned: true} cerInt16 = cerInteger{bits: 16} cerUint16 = cerInteger{bits: 16, unsigned: true} cerInt32 = cerInteger{bits: 32} cerUint32 = cerInteger{bits: 32, unsigned: true} cerInt64 = cerInteger{bits: 64} cerUint64 = cerInteger{bits: 64, unsigned: true} )