github.com/goplus/llgo@v0.8.3/internal/runtime/z_type.go (about)

     1  /*
     2   * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package runtime
    18  
    19  import (
    20  	"unsafe"
    21  
    22  	"github.com/goplus/llgo/internal/abi"
    23  )
    24  
    25  // -----------------------------------------------------------------------------
    26  
    27  type Kind = abi.Kind
    28  type Type = abi.Type
    29  
    30  func Basic(kind Kind) *Type {
    31  	return basicTypes[kind]
    32  }
    33  
    34  var (
    35  	basicTypes = [...]*Type{
    36  		abi.Bool:       basicType(abi.Bool),
    37  		abi.Int:        basicType(abi.Int),
    38  		abi.Int8:       basicType(abi.Int8),
    39  		abi.Int16:      basicType(abi.Int16),
    40  		abi.Int32:      basicType(abi.Int32),
    41  		abi.Int64:      basicType(abi.Int64),
    42  		abi.Uint:       basicType(abi.Uint),
    43  		abi.Uint8:      basicType(abi.Uint8),
    44  		abi.Uint16:     basicType(abi.Uint16),
    45  		abi.Uint32:     basicType(abi.Uint32),
    46  		abi.Uint64:     basicType(abi.Uint64),
    47  		abi.Uintptr:    basicType(abi.Uintptr),
    48  		abi.Float32:    basicType(abi.Float32),
    49  		abi.Float64:    basicType(abi.Float64),
    50  		abi.Complex64:  basicType(abi.Complex64),
    51  		abi.Complex128: basicType(abi.Complex128),
    52  		abi.String:     basicType(abi.String),
    53  	}
    54  )
    55  
    56  var (
    57  	sizeBasicTypes = [...]uintptr{
    58  		abi.Bool:       unsafe.Sizeof(false),
    59  		abi.Int:        unsafe.Sizeof(0),
    60  		abi.Int8:       1,
    61  		abi.Int16:      2,
    62  		abi.Int32:      4,
    63  		abi.Int64:      8,
    64  		abi.Uint:       unsafe.Sizeof(uint(0)),
    65  		abi.Uint8:      1,
    66  		abi.Uint16:     2,
    67  		abi.Uint32:     4,
    68  		abi.Uint64:     8,
    69  		abi.Uintptr:    unsafe.Sizeof(uintptr(0)),
    70  		abi.Float32:    4,
    71  		abi.Float64:    8,
    72  		abi.Complex64:  8,
    73  		abi.Complex128: 16,
    74  		abi.String:     unsafe.Sizeof(String{}),
    75  	}
    76  )
    77  
    78  func basicType(kind abi.Kind) *Type {
    79  	return &Type{
    80  		Size_: sizeBasicTypes[kind],
    81  		Hash:  uint32(kind),
    82  		Kind_: uint8(kind),
    83  	}
    84  }
    85  
    86  // -----------------------------------------------------------------------------