Commit fee9e475 authored by Russ Cox's avatar Russ Cox

[dev.cc] runtime: convert header files to Go

The conversion was done with an automated tool and then
modified only as necessary to make it compile and run.

[This CL is part of the removal of C code from package runtime.
See golang.org/s/dev.cc for an overview.]

LGTM=r
R=r, austin
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/167550043
parent 1e2d2f09
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#define MAXALIGN 8
typedef struct WaitQ WaitQ;
typedef struct Select Select;
typedef struct Scase Scase;
struct WaitQ
{
SudoG* first;
SudoG* last;
};
struct Hchan
{
uintgo qcount; // total data in the q
uintgo dataqsiz; // size of the circular q
byte* buf;
uint16 elemsize;
uint32 closed;
Type* elemtype; // element type
uintgo sendx; // send index
uintgo recvx; // receive index
WaitQ recvq; // list of recv waiters
WaitQ sendq; // list of send waiters
Mutex lock;
};
// Buffer follows Hchan immediately in memory.
// chanbuf(c, i) is pointer to the i'th slot in the buffer.
#define chanbuf(c, i) ((byte*)((c)->buf)+(uintptr)(c)->elemsize*(i))
enum
{
debug = 0,
// Scase.kind
CaseRecv,
CaseSend,
CaseDefault,
};
// Known to compiler.
// Changes here must also be made in src/cmd/gc/select.c's selecttype.
struct Scase
{
void* elem; // data element
Hchan* chan; // chan
uintptr pc; // return pc
uint16 kind;
uint16 so; // vararg of selected bool
bool* receivedp; // pointer to received bool (recv2)
int64 releasetime;
};
// Known to compiler.
// Changes here must also be made in src/cmd/gc/select.c's selecttype.
struct Select
{
uint16 tcase; // total count of scase[]
uint16 ncase; // currently filled scase[]
uint16* pollorder; // case poll order
Hchan** lockorder; // channel lock order
Scase scase[1]; // one per case (in order of appearance)
};
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import "unsafe"
//#define MAXALIGN 8
type waitq struct {
first *sudog
last *sudog
}
type hchan struct {
qcount uint // total data in the q
dataqsiz uint // size of the circular q
buf *byte
elemsize uint16
closed uint32
elemtype *_type // element type
sendx uint // send index
recvx uint // receive index
recvq waitq // list of recv waiters
sendq waitq // list of send waiters
lock mutex
}
// Buffer follows Hchan immediately in memory.
// chanbuf(c, i) is pointer to the i'th slot in the buffer.
// #define chanbuf(c, i) ((byte*)((c)->buf)+(uintptr)(c)->elemsize*(i))
const (
// scase.kind
_CaseRecv = iota
_CaseSend
_CaseDefault
)
// Known to compiler.
// Changes here must also be made in src/cmd/gc/select.c's selecttype.
type scase struct {
elem unsafe.Pointer // data element
_chan *hchan // chan
pc uintptr // return pc
kind uint16
so uint16 // vararg of selected bool
receivedp *bool // pointer to received bool (recv2)
releasetime int64
}
// Known to compiler.
// Changes here must also be made in src/cmd/gc/select.c's selecttype.
type _select struct {
tcase uint16 // total count of scase[]
ncase uint16 // currently filled scase[]
pollorder *uint16 // case poll order
lockorder **hchan // channel lock order
scase [1]scase // one per case (in order of appearance)
}
......@@ -3,9 +3,10 @@
// license that can be found in the LICENSE file.
// This file defines the IDs for PCDATA and FUNCDATA instructions
// in Go binaries. It is included by both C and assembly, so it must
// be written using #defines. It is included by the runtime package
// as well as the compilers.
// in Go binaries. It is included by assembly sources, so it must
// be written using #defines.
//
// The Go compiler also #includes this file, for now.
//
// symtab.go also contains a copy of these constants.
......@@ -50,8 +51,7 @@
/*c2go
enum {
PCDATA_ArgSize = 0,
PCDATA_StackMapIndex = 1,
PCDATA_StackMapIndex = 0,
FUNCDATA_ArgsPointerMaps = 0,
FUNCDATA_LocalsPointerMaps = 1,
FUNCDATA_DeadValueMaps = 2,
......
This diff is collapsed.
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Runtime _type representation.
package runtime
import "unsafe"
// Needs to be in sync with ../../cmd/ld/decodesym.c:/^commonsize and pkg/reflect/type.go:/type.
type _type struct {
size uintptr
hash uint32
_unused uint8
align uint8
fieldalign uint8
kind uint8
alg unsafe.Pointer
// gc stores _type info required for garbage collector.
// If (kind&KindGCProg)==0, then gc[0] points at sparse GC bitmap
// (no indirection), 4 bits per word.
// If (kind&KindGCProg)!=0, then gc[1] points to a compiler-generated
// read-only GC program; and gc[0] points to BSS space for sparse GC bitmap.
// For huge _types (>MaxGCMask), runtime unrolls the program directly into
// GC bitmap and gc[0] is not used. For moderately-sized _types, runtime
// unrolls the program into gc[0] space on first use. The first byte of gc[0]
// (gc[0][0]) contains 'unroll' flag saying whether the program is already
// unrolled into gc[0] or not.
gc [2]uintptr
_string *string
x *uncommontype
ptrto *_type
zero *byte // ptr to the zero value for this _type
}
type method struct {
name *string
pkgpath *string
mtyp *_type
typ *_type
ifn unsafe.Pointer
tfn unsafe.Pointer
}
type uncommontype struct {
name *string
pkgpath *string
mhdr []method
m [0]method
}
type imethod struct {
name *string
pkgpath *string
_type *_type
}
type interfacetype struct {
typ _type
mhdr []imethod
m [0]imethod
}
type maptype struct {
typ _type
key *_type
elem *_type
bucket *_type // internal _type representing a hash bucket
hmap *_type // internal _type representing a hmap
keysize uint8 // size of key slot
indirectkey bool // store ptr to key instead of key itself
valuesize uint8 // size of value slot
indirectvalue bool // store ptr to value instead of value itself
bucketsize uint16 // size of bucket
}
type chantype struct {
typ _type
elem *_type
dir uintptr
}
type slicetype struct {
typ _type
elem *_type
}
type functype struct {
typ _type
dotdotdot bool
in slice
out slice
}
type ptrtype struct {
typ _type
elem *_type
}
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Runtime type representation.
typedef struct Type Type;
typedef struct UncommonType UncommonType;
typedef struct InterfaceType InterfaceType;
typedef struct Method Method;
typedef struct IMethod IMethod;
typedef struct SliceType SliceType;
typedef struct FuncType FuncType;
// Needs to be in sync with ../../cmd/ld/decodesym.c:/^commonsize and pkg/reflect/type.go:/type.
struct Type
{
uintptr size;
uint32 hash;
uint8 _unused;
uint8 align;
uint8 fieldAlign;
uint8 kind;
void* alg;
// gc stores type info required for garbage collector.
// If (kind&KindGCProg)==0, then gc[0] points at sparse GC bitmap
// (no indirection), 4 bits per word.
// If (kind&KindGCProg)!=0, then gc[1] points to a compiler-generated
// read-only GC program; and gc[0] points to BSS space for sparse GC bitmap.
// For huge types (>MaxGCMask), runtime unrolls the program directly into
// GC bitmap and gc[0] is not used. For moderately-sized types, runtime
// unrolls the program into gc[0] space on first use. The first byte of gc[0]
// (gc[0][0]) contains 'unroll' flag saying whether the program is already
// unrolled into gc[0] or not.
uintptr gc[2];
String *string;
UncommonType *x;
Type *ptrto;
byte *zero; // ptr to the zero value for this type
};
struct Method
{
String *name;
String *pkgPath;
Type *mtyp;
Type *typ;
void (*ifn)(void);
void (*tfn)(void);
};
struct UncommonType
{
String *name;
String *pkgPath;
Slice mhdr;
Method m[];
};
struct IMethod
{
String *name;
String *pkgPath;
Type *type;
};
struct InterfaceType
{
Type typ;
Slice mhdr;
IMethod m[];
};
struct MapType
{
Type typ;
Type *key;
Type *elem;
Type *bucket; // internal type representing a hash bucket
Type *hmap; // internal type representing a Hmap
uint8 keysize; // size of key slot
bool indirectkey; // store ptr to key instead of key itself
uint8 valuesize; // size of value slot
bool indirectvalue; // store ptr to value instead of value itself
uint16 bucketsize; // size of bucket
};
struct ChanType
{
Type typ;
Type *elem;
uintptr dir;
};
struct SliceType
{
Type typ;
Type *elem;
};
struct FuncType
{
Type typ;
bool dotdotdot;
Slice in;
Slice out;
};
struct PtrType
{
Type typ;
Type *elem;
};
......@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Must match runtime and reflect.
// Included by cmd/gc.
enum {
KindBool = 1,
KindInt,
......@@ -30,9 +33,8 @@ enum {
KindStruct,
KindUnsafePointer,
KindDirectIface = 1<<5,
KindGCProg = 1<<6, // Type.gc points to GC program
KindNoPointers = 1<<7,
KindMask = (1<<5)-1,
KindDirectIface = 1 << 5,
KindGCProg = 1 << 6, // Type.gc points to GC program
KindNoPointers = 1 << 7,
KindMask = (1 << 5) - 1,
};
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
const (
_KindBool = 1 + iota
_KindInt
_KindInt8
_KindInt16
_KindInt32
_KindInt64
_KindUint
_KindUint8
_KindUint16
_KindUint32
_KindUint64
_KindUintptr
_KindFloat32
_KindFloat64
_KindComplex64
_KindComplex128
_KindArray
_KindChan
_KindFunc
_KindInterface
_KindMap
_KindPtr
_KindSlice
_KindString
_KindStruct
_KindUnsafePointer
_KindDirectIface = 1 << 5
_KindGCProg = 1 << 6 // Type.gc points to GC program
_KindNoPointers = 1 << 7
_KindMask = (1 << 5) - 1
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment