Files
llgo/internal/runtime/c/c.go

79 lines
1.9 KiB
Go
Raw Normal View History

2024-04-28 07:08:33 +08:00
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2024-04-29 09:51:32 +08:00
package c
2024-04-28 07:08:33 +08:00
2024-04-29 17:58:10 +08:00
import "C"
2024-04-28 07:08:33 +08:00
import "unsafe"
2024-05-01 12:32:09 +08:00
type (
Char = int8
Int = C.int
Pointer = unsafe.Pointer
2024-05-01 20:05:28 +08:00
FilePtr = unsafe.Pointer
2024-05-01 12:32:09 +08:00
)
//go:linkname Stdin llgo_stdin
2024-05-01 20:05:28 +08:00
var Stdin FilePtr
//go:linkname Stdout llgo_stdout
2024-05-01 20:05:28 +08:00
var Stdout FilePtr
//go:linkname Stderr llgo_stderr
2024-05-01 20:05:28 +08:00
var Stderr FilePtr
2024-04-30 08:23:55 +08:00
//go:linkname Str llgo.cstr
2024-05-01 12:32:09 +08:00
func Str(string) *Char
2024-04-29 09:51:32 +08:00
2024-05-26 08:59:10 +08:00
// llgo:link Advance llgo.advance
func Advance[PtrT any](ptr PtrT, offset int) PtrT { return ptr }
2024-05-01 23:57:19 +08:00
2024-04-29 13:59:06 +08:00
//go:linkname Alloca llgo.alloca
2024-05-01 12:32:09 +08:00
func Alloca(size uintptr) Pointer
2024-04-29 09:51:32 +08:00
2024-04-30 18:22:56 +08:00
//go:linkname AllocaCStr llgo.allocaCStr
2024-05-01 12:32:09 +08:00
func AllocaCStr(s string) *Char
2024-04-30 18:22:56 +08:00
2024-04-29 13:59:06 +08:00
//go:linkname Unreachable llgo.unreachable
2024-04-29 09:51:32 +08:00
func Unreachable()
2024-05-01 07:26:51 +08:00
//go:linkname Rand C.rand
2024-05-01 12:32:09 +08:00
func Rand() Int
2024-05-01 07:26:51 +08:00
2024-04-28 07:08:33 +08:00
//go:linkname Malloc C.malloc
2024-05-01 12:32:09 +08:00
func Malloc(size uintptr) Pointer
2024-04-28 07:08:33 +08:00
2024-04-29 09:51:32 +08:00
//go:linkname Memcpy C.memcpy
2024-05-01 12:32:09 +08:00
func Memcpy(dst, src Pointer, n uintptr) Pointer
2024-04-29 09:51:32 +08:00
2024-05-19 19:33:41 +08:00
//go:linkname Memmove C.memmove
func Memmove(dst, src Pointer, n uintptr) Pointer
//go:linkname Memset C.memset
func Memset(s Pointer, c Int, n uintptr) Pointer
2024-04-29 09:51:32 +08:00
//go:linkname Printf C.printf
2024-05-01 12:32:09 +08:00
func Printf(format *Char, __llgo_va_list ...any) Int
2024-05-01 20:05:28 +08:00
//go:linkname Fprintf C.fprintf
func Fprintf(fp FilePtr, format *Char, __llgo_va_list ...any) Int
2024-05-25 11:57:09 +08:00
//go:linkname Fwrite C.fwrite
func Fwrite(data Pointer, size, count uintptr, fp FilePtr) uintptr
//go:linkname Fputc C.fputc
func Fputc(c Int, fp FilePtr) Int