Commit 2b57a112 authored by Ian Lance Taylor's avatar Ian Lance Taylor

Add cgo2c program to translate mixed Go/C code into C. This

lets us use a single source file for both 6c and gcc, handling
the incompatible handling of return values.

R=rsc
DELTA=649  (613 added, 35 deleted, 1 changed)
OCL=22682
CL=22730
parent 58b280db
......@@ -24,6 +24,7 @@ LIBOFILES=\
array.$O\
mem.$O\
malloc.$O\
malloc_go.$O\
mcache.$O\
mcentral.$O\
mfixalloc.$O\
......@@ -57,7 +58,7 @@ nuke:
rm -f *.$(O) *.a $(GOROOT)/lib/$(LIB)
clean:
rm -f *.$(O) *.a runtime.acid
rm -f *.$(O) *.a runtime.acid cgo2c
%.$O: %.c
$(CC) -wF $<
......@@ -65,6 +66,13 @@ clean:
sys_file.$O: sys_file.c sys_types.h $(OS_H)
$(CC) -wF -D$(GOARCH)_$(GOOS) $<
cgo2c: cgo2c.c
quietgcc -o $@ $<
%.c: %.cgo cgo2c
./cgo2c < $< > $@.tmp
mv -f $@.tmp $@
%.$O: %.s
$(AS) $<
......
This diff is collapsed.
......@@ -257,38 +257,3 @@ stackfree(void *v)
}
free(v);
}
// Go function stubs.
#ifndef __GNUC__
#define malloc_Alloc malloc·Alloc
#define malloc_Free malloc·Free
#define malloc_Lookup malloc·Lookup
#define malloc_GetStats malloc·GetStats
#endif
void
malloc_Alloc(uintptr n, byte *p)
{
p = malloc(n);
FLUSH(&p);
}
void
malloc_Free(byte *p)
{
free(p);
}
void
malloc_Lookup(byte *p, byte *base, uintptr size)
{
mlookup(p, &base, &size);
}
void
malloc_GetStats(MStats *s)
{
s = &mstats;
FLUSH(&s);
}
......@@ -364,3 +364,7 @@ void MHeap_Init(MHeap *h, void *(*allocator)(uintptr));
MSpan* MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass);
void MHeap_Free(MHeap *h, MSpan *s);
MSpan* MHeap_Lookup(MHeap *h, PageID p);
void* malloc(uintptr size);
void free(void *v);
void mlookup(void *v, byte **base, uintptr *size);
// 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 malloc
#include "runtime.h"
#include "malloc.h"
func Alloc(n uintptr) (p *byte) {
p = malloc(n);
}
func Free(p *byte) {
free(p);
}
func Lookup(p *byte) (base *byte, size uintptr) {
mlookup(p, &base, &size);
}
func GetStats() (s *MStats) {
s = &mstats;
}
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