Commit 3b8dffe7 by Ian Lance Taylor Committed by Ian Lance Taylor

Change builtin make to runtime call at lowering time.

Use kindNoPointers as 6g does.

	* Make-lang.in (go/expressions.o): Depend on $(GO_RUNTIME_H).

From-SVN: r175008
parent 8365a060
2011-06-13 Ian Lance Taylor <iant@google.com>
* Make-lang.in (go/expressions.o): Depend on $(GO_RUNTIME_H).
2011-06-10 Ian Lance Taylor <iant@google.com>
* go-gcc.cc: Include "toplev.h".
......
......@@ -255,7 +255,7 @@ go/expressions.o: go/gofrontend/expressions.cc $(GO_SYSTEM_H) $(TOPLEV_H) \
intl.h $(TREE_H) $(GIMPLE_H) tree-iterator.h convert.h $(REAL_H) \
realmpfr.h $(GO_C_H) $(GO_GOGO_H) $(GO_TYPES_H) \
go/gofrontend/export.h $(GO_IMPORT_H) $(GO_STATEMENTS_H) $(GO_LEX_H) \
go/gofrontend/backend.h $(GO_EXPRESSIONS_H)
$(GO_RUNTIME_H) go/gofrontend/backend.h $(GO_EXPRESSIONS_H)
go/go.o: go/gofrontend/go.cc $(GO_SYSTEM_H) $(GO_C_H) $(GO_LEX_H) \
$(GO_PARSE_H) go/gofrontend/backend.h $(GO_GOGO_H)
go/go-dump.o: go/gofrontend/go-dump.cc $(GO_SYSTEM_H) $(GO_C_H) \
......
......@@ -78,7 +78,6 @@ class Expression
EXPRESSION_FIELD_REFERENCE,
EXPRESSION_INTERFACE_FIELD_REFERENCE,
EXPRESSION_ALLOCATION,
EXPRESSION_MAKE,
EXPRESSION_TYPE_GUARD,
EXPRESSION_CONVERSION,
EXPRESSION_UNSAFE_CONVERSION,
......@@ -92,6 +91,7 @@ class Expression
EXPRESSION_TYPE_DESCRIPTOR,
EXPRESSION_TYPE_INFO,
EXPRESSION_STRUCT_FIELD_OFFSET,
EXPRESSION_MAP_DESCRIPTOR,
EXPRESSION_LABEL_ADDR
};
......@@ -236,10 +236,6 @@ class Expression
static Expression*
make_allocation(Type*, source_location);
// Make a call to the builtin function make.
static Expression*
make_make(Type*, Expression_list*, source_location);
// Make a type guard expression.
static Expression*
make_type_guard(Expression*, Type*, source_location);
......@@ -276,8 +272,8 @@ class Expression
static Receive_expression*
make_receive(Expression* channel, source_location);
// Make an expression which evaluates to the type descriptor of a
// type.
// Make an expression which evaluates to the address of the type
// descriptor for TYPE.
static Expression*
make_type_descriptor(Type* type, source_location);
......@@ -304,6 +300,11 @@ class Expression
static Expression*
make_struct_field_offset(Struct_type*, const Struct_field*);
// Make an expression which evaluates to the address of the map
// descriptor for TYPE.
static Expression*
make_map_descriptor(Map_type* type, source_location);
// Make an expression which evaluates to the address of an unnamed
// label.
static Expression*
......
......@@ -64,6 +64,8 @@ enum Runtime_function_type
RFT_FUNC_PTR,
// Pointer to Go type descriptor.
RFT_TYPE,
// Pointer to map descriptor.
RFT_MAPDESCRIPTOR,
NUMBER_OF_RUNTIME_FUNCTION_TYPES
};
......@@ -175,6 +177,10 @@ runtime_function_type(Runtime_function_type bft)
case RFT_TYPE:
t = Type::make_type_descriptor_ptr_type();
break;
case RFT_MAPDESCRIPTOR:
t = Type::make_pointer_type(Map_type::make_map_descriptor_type());
break;
}
runtime_function_types[bft] = t;
......@@ -225,6 +231,11 @@ convert_to_runtime_function_type(Runtime_function_type bft, Expression* e,
case RFT_TYPE:
go_assert(e->type() == Type::make_type_descriptor_ptr_type());
return e;
case RFT_MAPDESCRIPTOR:
go_assert(e->type()->points_to()
== Map_type::make_map_descriptor_type());
return e;
}
}
......
......@@ -65,8 +65,14 @@ DEF_GO_RUNTIME(STRING_TO_INT_ARRAY, "__go_string_to_int_array",
P1(STRING), R1(SLICE))
// Make a slice.
DEF_GO_RUNTIME(MAKESLICE1, "__go_make_slice1", P2(TYPE, UINTPTR), R1(SLICE))
DEF_GO_RUNTIME(MAKESLICE2, "__go_make_slice2", P3(TYPE, UINTPTR, UINTPTR),
R1(SLICE))
// Make a map.
DEF_GO_RUNTIME(NEW_MAP, "__go_new_map", P2(TYPE, UINTPTR), R1(MAP))
DEF_GO_RUNTIME(MAKEMAP, "__go_new_map", P2(MAPDESCRIPTOR, UINTPTR), R1(MAP))
// Build a map from a composite literal.
DEF_GO_RUNTIME(CONSTRUCT_MAP, "__go_construct_map",
......@@ -103,7 +109,7 @@ DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(MAPITER), R0())
// Make a channel.
DEF_GO_RUNTIME(NEW_CHANNEL, "__go_new_channel", P2(UINTPTR, UINTPTR), R1(CHAN))
DEF_GO_RUNTIME(MAKECHAN, "__go_new_channel", P2(TYPE, UINTPTR), R1(CHAN))
// Get the length of a channel (the number of unread values).
DEF_GO_RUNTIME(CHAN_LEN, "__go_chan_len", P1(CHAN), R1(INT))
......
......@@ -78,6 +78,8 @@ static const int RUNTIME_TYPE_KIND_STRING = 24;
static const int RUNTIME_TYPE_KIND_STRUCT = 25;
static const int RUNTIME_TYPE_KIND_UNSAFE_POINTER = 26;
static const int RUNTIME_TYPE_KIND_NO_POINTERS = (1 << 7);
// To build the complete list of methods for a named type we need to
// gather all methods from anonymous fields. Those methods may
// require an arbitrary set of indirections and field offsets. There
......@@ -811,13 +813,6 @@ class Type
is_unexported_field_or_method(Gogo*, const Type*, const std::string&,
std::vector<const Named_type*>*);
// This type was passed to the builtin function make. ARGS are the
// arguments passed to make after the type; this may be NULL if
// there were none. Issue any required errors.
bool
check_make_expression(Expression_list* args, source_location location)
{ return this->do_check_make_expression(args, location); }
// Convert the builtin named types.
static void
convert_builtin_named_types(Gogo*);
......@@ -826,12 +821,6 @@ class Type
Btype*
get_backend(Gogo*);
// Return a tree for a make expression applied to this type.
tree
make_expression_tree(Translate_context* context, Expression_list* args,
source_location location)
{ return this->do_make_expression_tree(context, args, location); }
// Build a type descriptor entry for this type. Return a pointer to
// it. The location is the location which causes us to need the
// entry.
......@@ -878,16 +867,9 @@ class Type
virtual unsigned int
do_hash_for_method(Gogo*) const;
virtual bool
do_check_make_expression(Expression_list* args, source_location);
virtual Btype*
do_get_backend(Gogo*) = 0;
virtual tree
do_make_expression_tree(Translate_context*, Expression_list*,
source_location);
virtual Expression*
do_type_descriptor(Gogo*, Named_type* name) = 0;
......@@ -901,10 +883,6 @@ class Type
virtual void
do_export(Export*) const;
// Return whether an expression is an integer.
static bool
check_int_value(Expression*, const char*, source_location);
// Return whether a method expects a pointer as the receiver.
static bool
method_expects_pointer(const Named_object*);
......@@ -2083,16 +2061,9 @@ class Array_type : public Type
unsigned int
do_hash_for_method(Gogo*) const;
bool
do_check_make_expression(Expression_list*, source_location);
Btype*
do_get_backend(Gogo*);
tree
do_make_expression_tree(Translate_context*, Expression_list*,
source_location);
Expression*
do_type_descriptor(Gogo*, Named_type*);
......@@ -2180,16 +2151,9 @@ class Map_type : public Type
unsigned int
do_hash_for_method(Gogo*) const;
bool
do_check_make_expression(Expression_list*, source_location);
Btype*
do_get_backend(Gogo*);
tree
do_make_expression_tree(Translate_context*, Expression_list*,
source_location);
Expression*
do_type_descriptor(Gogo*, Named_type*);
......@@ -2269,16 +2233,9 @@ class Channel_type : public Type
unsigned int
do_hash_for_method(Gogo*) const;
bool
do_check_make_expression(Expression_list*, source_location);
Btype*
do_get_backend(Gogo*);
tree
do_make_expression_tree(Translate_context*, Expression_list*,
source_location);
Expression*
do_type_descriptor(Gogo*, Named_type*);
......@@ -2611,18 +2568,9 @@ class Named_type : public Type
unsigned int
do_hash_for_method(Gogo*) const;
bool
do_check_make_expression(Expression_list* args, source_location location)
{ return this->type_->check_make_expression(args, location); }
Btype*
do_get_backend(Gogo*);
tree
do_make_expression_tree(Translate_context* context, Expression_list* args,
source_location location)
{ return this->type_->make_expression_tree(context, args, location); }
Expression*
do_type_descriptor(Gogo*, Named_type*);
......@@ -2751,18 +2699,9 @@ class Forward_declaration_type : public Type
do_hash_for_method(Gogo* gogo) const
{ return this->real_type()->hash_for_method(gogo); }
bool
do_check_make_expression(Expression_list* args, source_location location)
{ return this->base()->check_make_expression(args, location); }
Btype*
do_get_backend(Gogo* gogo);
tree
do_make_expression_tree(Translate_context* context, Expression_list* args,
source_location location)
{ return this->base()->make_expression_tree(context, args, location); }
Expression*
do_type_descriptor(Gogo*, Named_type*);
......
......@@ -381,6 +381,7 @@ runtime_files = \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c \
runtime/go-lock-os-thread.c \
runtime/go-make-slice.c \
runtime/go-map-delete.c \
runtime/go-map-index.c \
runtime/go-map-len.c \
......
......@@ -184,18 +184,18 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
runtime/go-interface-compare.c \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c runtime/go-lock-os-thread.c \
runtime/go-map-delete.c runtime/go-map-index.c \
runtime/go-map-len.c runtime/go-map-range.c \
runtime/go-nanotime.c runtime/go-new-channel.c \
runtime/go-new-map.c runtime/go-new.c runtime/go-note.c \
runtime/go-panic.c runtime/go-panic-defer.c runtime/go-print.c \
runtime/go-rec-big.c runtime/go-rec-nb-big.c \
runtime/go-rec-nb-small.c runtime/go-rec-small.c \
runtime/go-recover.c runtime/go-reflect.c \
runtime/go-reflect-call.c runtime/go-reflect-chan.c \
runtime/go-reflect-map.c runtime/go-rune.c \
runtime/go-runtime-error.c runtime/go-sched.c \
runtime/go-select.c runtime/go-semacquire.c \
runtime/go-make-slice.c runtime/go-map-delete.c \
runtime/go-map-index.c runtime/go-map-len.c \
runtime/go-map-range.c runtime/go-nanotime.c \
runtime/go-new-channel.c runtime/go-new-map.c runtime/go-new.c \
runtime/go-note.c runtime/go-panic.c runtime/go-panic-defer.c \
runtime/go-print.c runtime/go-rec-big.c \
runtime/go-rec-nb-big.c runtime/go-rec-nb-small.c \
runtime/go-rec-small.c runtime/go-recover.c \
runtime/go-reflect.c runtime/go-reflect-call.c \
runtime/go-reflect-chan.c runtime/go-reflect-map.c \
runtime/go-rune.c runtime/go-runtime-error.c \
runtime/go-sched.c runtime/go-select.c runtime/go-semacquire.c \
runtime/go-send-big.c runtime/go-send-nb-big.c \
runtime/go-send-nb-small.c runtime/go-send-small.c \
runtime/go-setenv.c runtime/go-signal.c runtime/go-strcmp.c \
......@@ -227,25 +227,25 @@ am__objects_3 = go-append.lo go-assert.lo go-assert-interface.lo \
go-gomaxprocs.lo go-int-array-to-string.lo go-int-to-string.lo \
go-interface-compare.lo go-interface-eface-compare.lo \
go-interface-val-compare.lo go-lock-os-thread.lo \
go-map-delete.lo go-map-index.lo go-map-len.lo go-map-range.lo \
go-nanotime.lo go-new-channel.lo go-new-map.lo go-new.lo \
go-note.lo go-panic.lo go-panic-defer.lo go-print.lo \
go-rec-big.lo go-rec-nb-big.lo go-rec-nb-small.lo \
go-rec-small.lo go-recover.lo go-reflect.lo go-reflect-call.lo \
go-reflect-chan.lo go-reflect-map.lo go-rune.lo \
go-runtime-error.lo go-sched.lo go-select.lo go-semacquire.lo \
go-send-big.lo go-send-nb-big.lo go-send-nb-small.lo \
go-send-small.lo go-setenv.lo go-signal.lo go-strcmp.lo \
go-string-to-byte-array.lo go-string-to-int-array.lo \
go-strplus.lo go-strslice.lo go-trampoline.lo go-type-eface.lo \
go-type-error.lo go-type-identity.lo go-type-interface.lo \
go-type-string.lo go-typedesc-equal.lo go-typestring.lo \
go-unreflect.lo go-unsafe-new.lo go-unsafe-newarray.lo \
go-unsafe-pointer.lo go-unwind.lo cpuprof.lo mcache.lo \
mcentral.lo $(am__objects_1) mfinal.lo mfixalloc.lo mgc0.lo \
mheap.lo msize.lo proc.lo thread.lo $(am__objects_2) chan.lo \
iface.lo malloc.lo map.lo mprof.lo reflect.lo sigqueue.lo \
string.lo
go-make-slice.lo go-map-delete.lo go-map-index.lo \
go-map-len.lo go-map-range.lo go-nanotime.lo go-new-channel.lo \
go-new-map.lo go-new.lo go-note.lo go-panic.lo \
go-panic-defer.lo go-print.lo go-rec-big.lo go-rec-nb-big.lo \
go-rec-nb-small.lo go-rec-small.lo go-recover.lo go-reflect.lo \
go-reflect-call.lo go-reflect-chan.lo go-reflect-map.lo \
go-rune.lo go-runtime-error.lo go-sched.lo go-select.lo \
go-semacquire.lo go-send-big.lo go-send-nb-big.lo \
go-send-nb-small.lo go-send-small.lo go-setenv.lo go-signal.lo \
go-strcmp.lo go-string-to-byte-array.lo \
go-string-to-int-array.lo go-strplus.lo go-strslice.lo \
go-trampoline.lo go-type-eface.lo go-type-error.lo \
go-type-identity.lo go-type-interface.lo go-type-string.lo \
go-typedesc-equal.lo go-typestring.lo go-unreflect.lo \
go-unsafe-new.lo go-unsafe-newarray.lo go-unsafe-pointer.lo \
go-unwind.lo cpuprof.lo mcache.lo mcentral.lo $(am__objects_1) \
mfinal.lo mfixalloc.lo mgc0.lo mheap.lo msize.lo proc.lo \
thread.lo $(am__objects_2) chan.lo iface.lo malloc.lo map.lo \
mprof.lo reflect.lo sigqueue.lo string.lo
am_libgo_la_OBJECTS = $(am__objects_3)
libgo_la_OBJECTS = $(am_libgo_la_OBJECTS)
libgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
......@@ -800,6 +800,7 @@ runtime_files = \
runtime/go-interface-eface-compare.c \
runtime/go-interface-val-compare.c \
runtime/go-lock-os-thread.c \
runtime/go-make-slice.c \
runtime/go-map-delete.c \
runtime/go-map-index.c \
runtime/go-map-len.c \
......@@ -2309,6 +2310,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-interface-val-compare.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-lock-os-thread.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-make-slice.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-delete.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-index.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-map-len.Plo@am__quote@
......@@ -2610,6 +2612,13 @@ go-lock-os-thread.lo: runtime/go-lock-os-thread.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-lock-os-thread.lo `test -f 'runtime/go-lock-os-thread.c' || echo '$(srcdir)/'`runtime/go-lock-os-thread.c
go-make-slice.lo: runtime/go-make-slice.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-make-slice.lo -MD -MP -MF $(DEPDIR)/go-make-slice.Tpo -c -o go-make-slice.lo `test -f 'runtime/go-make-slice.c' || echo '$(srcdir)/'`runtime/go-make-slice.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/go-make-slice.Tpo $(DEPDIR)/go-make-slice.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='runtime/go-make-slice.c' object='go-make-slice.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-make-slice.lo `test -f 'runtime/go-make-slice.c' || echo '$(srcdir)/'`runtime/go-make-slice.c
go-map-delete.lo: runtime/go-map-delete.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT go-map-delete.lo -MD -MP -MF $(DEPDIR)/go-map-delete.Tpo -c -o go-map-delete.lo `test -f 'runtime/go-map-delete.c' || echo '$(srcdir)/'`runtime/go-map-delete.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/go-map-delete.Tpo $(DEPDIR)/go-map-delete.Plo
......
......@@ -13,17 +13,26 @@
#include "channel.h"
struct __go_channel*
__go_new_channel (const struct __go_type_descriptor *element_type,
__go_new_channel (const struct __go_type_descriptor *channel_type,
uintptr_t entries)
{
const struct __go_channel_type *ctd;
const struct __go_type_descriptor *element_type;
uintptr_t element_size;
int ientries;
struct __go_channel* ret;
size_t alloc_size;
int i;
__go_assert (channel_type->__code == GO_CHAN);
ctd = (const struct __go_channel_type *) channel_type;
element_type = ctd->__element_type;
element_size = element_type->__size;
if ((uintptr_t) (int) entries != entries
ientries = (int) entries;
if (ientries < 0
|| (uintptr_t) ientries != entries
|| entries > (uintptr_t) -1 / element_size)
__go_panic_msg ("chan size out of range");
......
......@@ -106,9 +106,11 @@ __go_map_next_prime (uintptr_t n)
struct __go_map *
__go_new_map (const struct __go_map_descriptor *descriptor, uintptr_t entries)
{
int ientries;
struct __go_map *ret;
if ((uintptr_t) (int) entries != entries)
ientries = (int) entries;
if (ientries < 0 || (uintptr_t) ientries != entries)
__go_panic_msg ("map size out of range");
if (entries == 0)
......
......@@ -161,7 +161,7 @@ go_complex_to_ffi (ffi_type *float_type)
static ffi_type *
go_type_to_ffi (const struct __go_type_descriptor *descriptor)
{
switch (descriptor->__code)
switch (descriptor->__code & GO_CODE_MASK)
{
case GO_BOOL:
if (sizeof (_Bool) == 1)
......
......@@ -26,9 +26,6 @@ makechan (const struct __go_type_descriptor *typ, uint32_t size)
struct __go_channel *channel;
void *ret;
__go_assert (typ->__code == GO_CHAN);
typ = ((const struct __go_channel_type *) typ)->__element_type;
channel = __go_new_channel (typ, size);
ret = __go_alloc (sizeof (void *));
......
......@@ -57,7 +57,7 @@ extern const struct __go_type_descriptor ptr_struct_descriptor
const struct __go_type_descriptor *
get_descriptor (int code)
{
switch (code)
switch (code & GO_CODE_MASK)
{
case GO_BOOL:
return &ptr_bool_descriptor;
......
......@@ -53,13 +53,17 @@
#define GO_STRUCT 25
#define GO_UNSAFE_POINTER 26
#define GO_NO_POINTERS (1 << 7)
#define GO_CODE_MASK 0x7f
/* For each Go type the compiler constructs one of these structures.
This is used for type reflectin, interfaces, maps, and reference
counting. */
struct __go_type_descriptor
{
/* The type code for this type, a value in enum __go_type_codes.
/* The type code for this type, one of the type kind values above.
This is used by unsafe.Reflect and unsafe.Typeof to determine the
type descriptor to return for this type itself. It is also used
by reflect.toType when mapping to a reflect Type structure. */
......
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