OSDN Git Service

runtime: Copy runtime_printf from other Go library.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 May 2012 20:45:16 +0000 (20:45 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 May 2012 20:45:16 +0000 (20:45 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@187849 138bc75d-0d04-0410-961f-82ee72b054a4

15 files changed:
libgo/Makefile.am
libgo/Makefile.in
libgo/merge.sh
libgo/runtime/chan.c
libgo/runtime/go-assert.c
libgo/runtime/go-panic.c
libgo/runtime/go-print.c
libgo/runtime/malloc.goc
libgo/runtime/mgc0.c
libgo/runtime/mheap.c
libgo/runtime/msize.c
libgo/runtime/print.c [new file with mode: 0644]
libgo/runtime/runtime.c
libgo/runtime/runtime.h
libgo/runtime/thread-linux.c

index a27216a..1d761bc 100644 (file)
@@ -465,6 +465,7 @@ runtime_files = \
        runtime/mgc0.c \
        runtime/mheap.c \
        runtime/msize.c \
+       runtime/print.c \
        runtime/proc.c \
        runtime/runtime.c \
        runtime/signal_unix.c \
index 018ac85..af18b70 100644 (file)
@@ -209,7 +209,7 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
        runtime/lock_futex.c runtime/thread-linux.c runtime/mcache.c \
        runtime/mcentral.c runtime/mem_posix_memalign.c runtime/mem.c \
        runtime/mfinal.c runtime/mfixalloc.c runtime/mgc0.c \
-       runtime/mheap.c runtime/msize.c runtime/proc.c \
+       runtime/mheap.c runtime/msize.c runtime/print.c runtime/proc.c \
        runtime/runtime.c runtime/signal_unix.c runtime/thread.c \
        runtime/yield.c runtime/rtems-task-variable-add.c iface.c \
        malloc.c map.c mprof.c reflect.c runtime1.c sema.c sigqueue.c \
@@ -242,9 +242,9 @@ am__objects_4 = go-append.lo go-assert.lo go-assert-interface.lo \
        go-unsafe-newarray.lo go-unsafe-pointer.lo go-unwind.lo \
        chan.lo cpuprof.lo $(am__objects_1) mcache.lo mcentral.lo \
        $(am__objects_2) mfinal.lo mfixalloc.lo mgc0.lo mheap.lo \
-       msize.lo proc.lo runtime.lo signal_unix.lo thread.lo yield.lo \
-       $(am__objects_3) iface.lo malloc.lo map.lo mprof.lo reflect.lo \
-       runtime1.lo sema.lo sigqueue.lo string.lo time.lo
+       msize.lo print.lo proc.lo runtime.lo signal_unix.lo thread.lo \
+       yield.lo $(am__objects_3) iface.lo malloc.lo map.lo mprof.lo \
+       reflect.lo runtime1.lo sema.lo sigqueue.lo string.lo time.lo
 am_libgo_la_OBJECTS = $(am__objects_4)
 libgo_la_OBJECTS = $(am_libgo_la_OBJECTS)
 libgo_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -882,6 +882,7 @@ runtime_files = \
        runtime/mgc0.c \
        runtime/mheap.c \
        runtime/msize.c \
+       runtime/print.c \
        runtime/proc.c \
        runtime/runtime.c \
        runtime/signal_unix.c \
@@ -2440,6 +2441,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mheap.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprof.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msize.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reflect.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rtems-task-variable-add.Plo@am__quote@
@@ -3036,6 +3038,13 @@ msize.lo: runtime/msize.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 msize.lo `test -f 'runtime/msize.c' || echo '$(srcdir)/'`runtime/msize.c
 
+print.lo: runtime/print.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT print.lo -MD -MP -MF $(DEPDIR)/print.Tpo -c -o print.lo `test -f 'runtime/print.c' || echo '$(srcdir)/'`runtime/print.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/print.Tpo $(DEPDIR)/print.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='runtime/print.c' object='print.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 print.lo `test -f 'runtime/print.c' || echo '$(srcdir)/'`runtime/print.c
+
 proc.lo: runtime/proc.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT proc.lo -MD -MP -MF $(DEPDIR)/proc.Tpo -c -o proc.lo `test -f 'runtime/proc.c' || echo '$(srcdir)/'`runtime/proc.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/proc.Tpo $(DEPDIR)/proc.Plo
index 9e2ca01..fbc7118 100755 (executable)
@@ -163,7 +163,7 @@ done
   done
 done
 
-runtime="chan.c cpuprof.c lock_futex.c lock_sema.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c proc.c runtime.c runtime.h signal_unix.c malloc.h malloc.goc mprof.goc runtime1.goc sema.goc sigqueue.goc string.goc time.goc"
+runtime="chan.c cpuprof.c lock_futex.c lock_sema.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c print.c proc.c runtime.c runtime.h signal_unix.c malloc.h malloc.goc mprof.goc runtime1.goc sema.goc sigqueue.goc string.goc time.goc"
 for f in $runtime; do
   merge_c $f $f
 done
index 7cf307f..c8ee10e 100644 (file)
@@ -100,8 +100,8 @@ runtime_makechan_c(ChanType *t, int64 hint)
        c->dataqsiz = hint;
 
        if(debug)
-               runtime_printf("makechan: chan=%p; elemsize=%lld; elemalign=%d; dataqsiz=%d\n",
-                       c, (long long)elem->__size, elem->__align, c->dataqsiz);
+               runtime_printf("makechan: chan=%p; elemsize=%D; elemalign=%d; dataqsiz=%d\n",
+                       c, (int64)elem->__size, elem->__align, c->dataqsiz);
 
        return c;
 }
index 48aa072..a36f43a 100644 (file)
@@ -7,12 +7,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "runtime.h"
 #include "go-assert.h"
 
 void
 __go_assert_fail (const char *file, unsigned int lineno)
 {
   /* FIXME: Eventually we should dump a stack trace here.  */
-  fprintf (stderr, "%s:%u: libgo assertion failure\n", file, lineno);
+  runtime_printf ("%s:%U: libgo assertion failure\n", file, (uint64) lineno);
   abort ();
 }
index 7ba426f..05325b1 100644 (file)
@@ -24,13 +24,13 @@ __printpanics (struct __go_panic_stack *p)
   if (p->__next != NULL)
     {
       __printpanics (p->__next);
-      fprintf (stderr, "\t");
+      runtime_printf ("\t");
     }
-  fprintf (stderr, "panic: ");
+  runtime_printf ("panic: ");
   runtime_printany (p->__arg);
   if (p->__was_recovered)
-    fprintf (stderr, " [recovered]");
-  fputc ('\n', stderr);
+    runtime_printf (" [recovered]");
+  runtime_printf ("\n");
 }
 
 /* This implements __go_panic which is used for the panic
index 03cfd01..3fe879a 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include "runtime.h"
 #include "array.h"
 #include "go-panic.h"
 #include "go-string.h"
    the predeclared functions print/println/panic/panicln.  */
 
 void
-__go_print_space ()
-{
-  putc (' ', stderr);
-}
-
-void
-__go_print_nl ()
-{
-  putc ('\n', stderr);
-}
-
-void
-__go_print_string (struct __go_string val)
-{
-  fprintf (stderr, "%.*s", (int) val.__length, (const char *) val.__data);
-}
-
-void
-__go_print_uint64 (uint64_t val)
-{
-  fprintf (stderr, "%llu", (unsigned long long) val);
-}
-
-void
-__go_print_int64 (int64_t val)
-{
-  fprintf (stderr, "%lld", (long long) val);
-}
-
-void
-__go_print_double (double v)
-{
-  char buf[20];
-  int e, s, i, n;
-  double h;
-
-  if (isnan (v))
-    {
-      fputs ("NaN", stderr);
-      return;
-    }
-  if (__builtin_isinf (v))
-    {
-      putc (v < 0 ? '-' : '+', stderr);
-      fputs ("Inf", stderr);
-      return;
-    }
-
-  /* The number of digits printed.  */
-  n = 7;
-  /* The exponent.  */
-  e = 0;
-  /* The sign.  */
-  s = 0;
-  if (v != 0)
-    {
-      if (v < 0)
-       {
-         v = -v;
-         s = 1;
-       }
-
-      /* Normalize.  */
-      while (v >= 10)
-       {
-         ++e;
-         v /= 10;
-       }
-      while (v < 1)
-       {
-         --e;
-         v *= 10;
-       }
-
-      /* Round.  */
-      h = 5;
-      for (i = 0; i < n; ++i)
-       h /= 10;
-
-      v += h;
-      if (v >= 10)
-       {
-         ++e;
-         v /= 10;
-       }
-    }
-
-  /* The format is +d.dddd+edd.  */
-  buf[0] = s ? '-' : '+';
-  for (i = 0; i < n; ++i)
-    {
-      int d;
-
-      d = v;
-      buf[i + 2] = d + '0';
-      v -= d;
-      v *= 10;
-    }
-  buf[1] = buf[2];
-  buf[2] = '.';
-
-  buf[n + 2] = 'e';
-  buf[n + 3] = e < 0 ? '-' : '+';
-  if (e < 0)
-    e = - e;
-  buf[n + 4] = e / 100 + '0';
-  buf[n + 5] = (e / 10) % 10 + '0';
-  buf[n + 6] = e % 10 + '0';
-  buf[n + 7] = '\0';
-  fputs (buf, stderr);
-}
-
-void
-__go_print_complex (__complex double val)
-{
-  putc ('(', stderr);
-  __go_print_double (__builtin_creal (val));
-  __go_print_double (__builtin_cimag (val));
-  fputs ("i)", stderr);
-}
-
-void
-__go_print_bool (_Bool val)
-{
-  fputs (val ? "true" : "false", stderr);
-}
-
-void
-__go_print_pointer (void *val)
-{
-  fprintf (stderr, "0x%lx", (unsigned long) (uintptr_t) val);
-}
-
-void
 __go_print_empty_interface (struct __go_empty_interface e)
 {
-  fprintf (stderr, "(%p,%p)", e.__type_descriptor, e.__object);
+  runtime_printf ("(%p,%p)", e.__type_descriptor, e.__object);
 }
 
 void
 __go_print_interface (struct __go_interface i)
 {
-  fprintf (stderr, "(%p,%p)", i.__methods, i.__object);
+  runtime_printf ("(%p,%p)", i.__methods, i.__object);
 }
 
 void
 __go_print_slice (struct __go_open_array val)
 {
-  fprintf (stderr, "[%d/%d]", val.__count, val.__capacity);
-  __go_print_pointer (val.__values);
+  runtime_printf ("[%d/%d]", val.__count, val.__capacity);
+  runtime_printpointer (val.__values);
 }
index ae5e15f..1a40637 100644 (file)
@@ -139,7 +139,7 @@ __go_free(void *v)
        m->mallocing = 1;
 
        if(!runtime_mlookup(v, nil, nil, &s)) {
-               // runtime_printf("free %p: not an allocated block\n", v);
+               runtime_printf("free %p: not an allocated block\n", v);
                runtime_throw("free runtime_mlookup");
        }
        prof = runtime_blockspecial(v);
@@ -367,7 +367,7 @@ runtime_mallocinit(void)
                if(p == nil)
                        runtime_throw("runtime: cannot reserve arena virtual address space");
                if((uintptr)p & (((uintptr)1<<PageShift)-1))
-                       runtime_printf("runtime: SysReserve returned unaligned address %p; asked for %p", p, (void*)(bitmap_size+arena_size));
+                       runtime_printf("runtime: SysReserve returned unaligned address %p; asked for %p", p, bitmap_size+arena_size);
        }
        if((uintptr)p & (((uintptr)1<<PageShift)-1))
                runtime_throw("runtime: SysReserve returned unaligned address");
@@ -467,15 +467,15 @@ func SetFinalizer(obj Eface, finalizer Eface) {
        const FuncType *ft;
 
        if(obj.__type_descriptor == nil) {
-               // runtimeĀ·printf("runtime.SetFinalizer: first argument is nil interface\n");
+               runtime_printf("runtime.SetFinalizer: first argument is nil interface\n");
                goto throw;
        }
        if(obj.__type_descriptor->__code != GO_PTR) {
-               // runtime_printf("runtime.SetFinalizer: first argument is %S, not pointer\n", *obj.type->string);
+               runtime_printf("runtime.SetFinalizer: first argument is %S, not pointer\n", *obj.__type_descriptor->__reflection);
                goto throw;
        }
        if(!runtime_mlookup(obj.__object, &base, &size, nil) || obj.__object != base) {
-               // runtime_printf("runtime.SetFinalizer: pointer not at beginning of allocated block\n");
+               runtime_printf("runtime.SetFinalizer: pointer not at beginning of allocated block\n");
                goto throw;
        }
        ft = nil;
@@ -494,7 +494,7 @@ func SetFinalizer(obj Eface, finalizer Eface) {
        return;
 
 badfunc:
-       // runtime_printf("runtime.SetFinalizer: second argument is %S, not func(%S)\n", *finalizer.type->string, *obj.type->string);
+       runtime_printf("runtime.SetFinalizer: second argument is %S, not func(%S)\n", *finalizer.__type_descriptor->__reflection, *obj.__type_descriptor->__reflection);
 throw:
        runtime_throw("runtime.SetFinalizer");
 }
index c08d5c1..c84bdd6 100644 (file)
@@ -159,7 +159,7 @@ scanblock(byte *b, int64 n)
        bool keepworking;
 
        if((int64)(uintptr)n != n || n < 0) {
-               // runtime_printf("scanblock %p %lld\n", b, (long long)n);
+               runtime_printf("scanblock %p %D\n", b, n);
                runtime_throw("scanblock");
        }
 
@@ -190,7 +190,7 @@ scanblock(byte *b, int64 n)
                // Each iteration scans the block b of length n, queueing pointers in
                // the work buffer.
                if(Debug > 1)
-                       runtime_printf("scanblock %p %lld\n", b, (long long) n);
+                       runtime_printf("scanblock %p %D\n", b, n);
 
                vp = (void**)b;
                n >>= (2+PtrSize/8);  /* n /= PtrSize (4 or 8) */
@@ -346,7 +346,7 @@ debug_scanblock(byte *b, int64 n)
                runtime_throw("debug_scanblock without DebugMark");
 
        if((int64)(uintptr)n != n || n < 0) {
-               //runtime_printf("debug_scanblock %p %D\n", b, n);
+               runtime_printf("debug_scanblock %p %D\n", b, n);
                runtime_throw("debug_scanblock");
        }
 
@@ -1047,14 +1047,13 @@ runtime_gc(int32 force)
        mstats.pause_total_ns += t3 - t0;
        mstats.numgc++;
        if(mstats.debuggc)
-               runtime_printf("pause %llu\n", (unsigned long long)t3-t0);
+               runtime_printf("pause %D\n", t3-t0);
 
        if(gctrace) {
-               runtime_printf("gc%d(%d): %llu+%llu+%llu ms %llu -> %llu MB %llu -> %llu (%llu-%llu) objects %llu handoff\n",
-                       mstats.numgc, work.nproc, (unsigned long long)(t1-t0)/1000000, (unsigned long long)(t2-t1)/1000000, (unsigned long long)(t3-t2)/1000000,
-                       (unsigned long long)heap0>>20, (unsigned long long)heap1>>20, (unsigned long long)obj0, (unsigned long long)obj1,
-                       (unsigned long long) mstats.nmalloc, (unsigned long long)mstats.nfree,
-                       (unsigned long long) nhandoff);
+               runtime_printf("gc%d(%d): %D+%D+%D ms, %D -> %D MB %D -> %D (%D-%D) objects\n",
+                       mstats.numgc, work.nproc, (t1-t0)/1000000, (t2-t1)/1000000, (t3-t2)/1000000,
+                       heap0>>20, heap1>>20, obj0, obj1,
+                       mstats.nmalloc, mstats.nfree);
        }
        
        runtime_MProf_GC();
@@ -1152,8 +1151,8 @@ runtime_markallocated(void *v, uintptr n, bool noptr)
 {
        uintptr *b, obits, bits, off, shift;
 
-       // if(0)
-               // runtime_printf("markallocated %p+%p\n", v, n);
+       if(0)
+               runtime_printf("markallocated %p+%p\n", v, n);
 
        if((byte*)v+n > (byte*)runtime_mheap.arena_used || (byte*)v < runtime_mheap.arena_start)
                runtime_throw("markallocated: bad pointer");
@@ -1184,8 +1183,8 @@ runtime_markfreed(void *v, uintptr n)
 {
        uintptr *b, obits, bits, off, shift;
 
-       // if(0)
-               // runtime_printf("markallocated %p+%p\n", v, n);
+       if(0)
+               runtime_printf("markallocated %p+%p\n", v, n);
 
        if((byte*)v+n > (byte*)runtime_mheap.arena_used || (byte*)v < runtime_mheap.arena_start)
                runtime_throw("markallocated: bad pointer");
@@ -1227,7 +1226,7 @@ runtime_checkfreed(void *v, uintptr n)
        bits = *b>>shift;
        if((bits & bitAllocated) != 0) {
                runtime_printf("checkfreed %p+%p: off=%p have=%p\n",
-                       v, (void*)n, (void*)off, (void*)(bits & bitMask));
+                       v, n, off, bits & bitMask);
                runtime_throw("checkfreed: not freed");
        }
 }
index 6bf38aa..221c5af 100644 (file)
@@ -191,7 +191,7 @@ MHeap_Grow(MHeap *h, uintptr npage)
                        v = runtime_MHeap_SysAlloc(h, ask);
                }
                if(v == nil) {
-                       runtime_printf("runtime: out of memory: cannot allocate %llu-byte block (%llu in use)\n", (unsigned long long)ask, (unsigned long long)mstats.heap_sys);
+                       runtime_printf("runtime: out of memory: cannot allocate %D-byte block (%D in use)\n", (uint64)ask, mstats.heap_sys);
                        return false;
                }
        }
@@ -277,7 +277,7 @@ MHeap_FreeLocked(MHeap *h, MSpan *s)
        PageID p;
 
        if(s->state != MSpanInUse || s->ref != 0) {
-               // runtime_printf("MHeap_FreeLocked - span %p ptr %p state %d ref %d\n", s, s->start<<PageShift, s->state, s->ref);
+               runtime_printf("MHeap_FreeLocked - span %p ptr %p state %d ref %d\n", s, s->start<<PageShift, s->state, s->ref);
                runtime_throw("MHeap_FreeLocked - invalid free");
        }
        mstats.heap_idle += s->npages<<PageShift;
@@ -397,10 +397,10 @@ runtime_MHeap_Scavenger(void* dummy)
 
                if(trace) {
                        if(sumreleased > 0)
-                               runtime_printf("scvg%d: %p MB released\n", k, (void*)(sumreleased>>20));
-                       runtime_printf("scvg%d: inuse: %lld, idle: %lld, sys: %lld, released: %lld, consumed: %lld (MB)\n",
-                               k, (long long)(mstats.heap_inuse>>20), (long long)(mstats.heap_idle>>20), (long long)(mstats.heap_sys>>20),
-                               (long long)(mstats.heap_released>>20), (long long)((mstats.heap_sys - mstats.heap_released)>>20));
+                               runtime_printf("scvg%d: %p MB released\n", k, sumreleased>>20);
+                       runtime_printf("scvg%d: inuse: %D, idle: %D, sys: %D, released: %D, consumed: %D (MB)\n",
+                               k, mstats.heap_inuse>>20, mstats.heap_idle>>20, mstats.heap_sys>>20,
+                               mstats.heap_released>>20, (mstats.heap_sys - mstats.heap_released)>>20);
                }
        }
 }
@@ -451,7 +451,7 @@ void
 runtime_MSpanList_Insert(MSpan *list, MSpan *span)
 {
        if(span->next != nil || span->prev != nil) {
-               // runtime_printf("failed MSpanList_Insert %p %p %p\n", span, span->next, span->prev);
+               runtime_printf("failed MSpanList_Insert %p %p %p\n", span, span->next, span->prev);
                runtime_throw("MSpanList_Insert");
        }
        span->next = list->next;
index e2672b0..3b5591c 100644 (file)
@@ -103,7 +103,7 @@ runtime_InitSizes(void)
                sizeclass++;
        }
        if(sizeclass != NumSizeClasses) {
-               // runtime_printf("sizeclass=%d NumSizeClasses=%d\n", sizeclass, NumSizeClasses);
+               runtime_printf("sizeclass=%d NumSizeClasses=%d\n", sizeclass, NumSizeClasses);
                runtime_throw("InitSizes - bad NumSizeClasses");
        }
 
@@ -122,13 +122,13 @@ runtime_InitSizes(void)
                for(n=0; n < MaxSmallSize; n++) {
                        sizeclass = runtime_SizeToClass(n);
                        if(sizeclass < 1 || sizeclass >= NumSizeClasses || runtime_class_to_size[sizeclass] < n) {
-                               // runtime_printf("size=%d sizeclass=%d runtime_class_to_size=%d\n", n, sizeclass, runtime_class_to_size[sizeclass]);
-                               // runtime_printf("incorrect SizeToClass");
+                               runtime_printf("size=%d sizeclass=%d runtime_class_to_size=%d\n", n, sizeclass, runtime_class_to_size[sizeclass]);
+                               runtime_printf("incorrect SizeToClass");
                                goto dump;
                        }
                        if(sizeclass > 1 && runtime_class_to_size[sizeclass-1] >= n) {
-                               // runtime_printf("size=%d sizeclass=%d runtime_class_to_size=%d\n", n, sizeclass, runtime_class_to_size[sizeclass]);
-                               // runtime_printf("SizeToClass too big");
+                               runtime_printf("size=%d sizeclass=%d runtime_class_to_size=%d\n", n, sizeclass, runtime_class_to_size[sizeclass]);
+                               runtime_printf("SizeToClass too big");
                                goto dump;
                        }
                }
diff --git a/libgo/runtime/print.c b/libgo/runtime/print.c
new file mode 100644 (file)
index 0000000..3eafeb7
--- /dev/null
@@ -0,0 +1,310 @@
+// 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.
+
+#include <stdarg.h>
+#include "runtime.h"
+
+//static Lock debuglock;
+
+static void go_vprintf(const char*, va_list);
+
+// write to goroutine-local buffer if diverting output,
+// or else standard error.
+static void
+gwrite(const void *v, int32 n)
+{
+       G* g = runtime_g();
+
+       if(g == nil || g->writebuf == nil) {
+               runtime_write(2, v, n);
+               return;
+       }
+       
+       if(g->writenbuf == 0)
+               return;
+       
+       if(n > g->writenbuf)
+               n = g->writenbuf;
+       runtime_memmove(g->writebuf, v, n);
+       g->writebuf += n;
+       g->writenbuf -= n;
+}
+
+void
+runtime_dump(byte *p, int32 n)
+{
+       int32 i;
+
+       for(i=0; i<n; i++) {
+               runtime_printpointer((byte*)(uintptr)(p[i]>>4));
+               runtime_printpointer((byte*)(uintptr)(p[i]&0xf));
+               if((i&15) == 15)
+                       runtime_prints("\n");
+               else
+                       runtime_prints(" ");
+       }
+       if(n & 15)
+               runtime_prints("\n");
+}
+
+void
+runtime_prints(const char *s)
+{
+       gwrite(s, runtime_findnull((const byte*)s));
+}
+
+void
+runtime_printf(const char *s, ...)
+{
+       va_list va;
+
+       va_start(va, s);
+       go_vprintf(s, va);
+       va_end(va);
+}
+
+// Very simple printf.  Only for debugging prints.
+// Do not add to this without checking with Rob.
+static void
+go_vprintf(const char *s, va_list va)
+{
+       const char *p, *lp;
+
+       //runtime_lock(&debuglock);
+
+       lp = p = s;
+       for(; *p; p++) {
+               if(*p != '%')
+                       continue;
+               if(p > lp)
+                       gwrite(lp, p-lp);
+               p++;
+               switch(*p) {
+               case 'a':
+                       runtime_printslice(va_arg(va, Slice));
+                       break;
+               case 'd':
+                       runtime_printint(va_arg(va, int32));
+                       break;
+               case 'D':
+                       runtime_printint(va_arg(va, int64));
+                       break;
+               case 'e':
+                       runtime_printeface(va_arg(va, Eface));
+                       break;
+               case 'f':
+                       runtime_printfloat(va_arg(va, float64));
+                       break;
+               case 'C':
+                       runtime_printcomplex(va_arg(va, __complex double));
+                       break;
+               case 'i':
+                       runtime_printiface(va_arg(va, Iface));
+                       break;
+               case 'p':
+                       runtime_printpointer(va_arg(va, void*));
+                       break;
+               case 's':
+                       runtime_prints(va_arg(va, char*));
+                       break;
+               case 'S':
+                       runtime_printstring(va_arg(va, String));
+                       break;
+               case 't':
+                       runtime_printbool(va_arg(va, int));
+                       break;
+               case 'U':
+                       runtime_printuint(va_arg(va, uint64));
+                       break;
+               case 'x':
+                       runtime_printhex(va_arg(va, uint32));
+                       break;
+               case 'X':
+                       runtime_printhex(va_arg(va, uint64));
+                       break;
+               }
+               lp = p+1;
+       }
+       if(p > lp)
+               gwrite(lp, p-lp);
+
+       //runtime_unlock(&debuglock);
+}
+
+void
+runtime_printpc(void *p __attribute__ ((unused)))
+{
+       runtime_prints("PC=");
+       runtime_printhex((uint64)runtime_getcallerpc(p));
+}
+
+void
+runtime_printbool(_Bool v)
+{
+       if(v) {
+               gwrite("true", 4);
+               return;
+       }
+       gwrite("false", 5);
+}
+
+void
+runtime_printfloat(double v)
+{
+       byte buf[20];
+       int32 e, s, i, n;
+       float64 h;
+
+       if(runtime_isNaN(v)) {
+               gwrite("NaN", 3);
+               return;
+       }
+       if(runtime_isInf(v, 1)) {
+               gwrite("+Inf", 4);
+               return;
+       }
+       if(runtime_isInf(v, -1)) {
+               gwrite("-Inf", 4);
+               return;
+       }
+
+       n = 7;  // digits printed
+       e = 0;  // exp
+       s = 0;  // sign
+       if(v != 0) {
+               // sign
+               if(v < 0) {
+                       v = -v;
+                       s = 1;
+               }
+
+               // normalize
+               while(v >= 10) {
+                       e++;
+                       v /= 10;
+               }
+               while(v < 1) {
+                       e--;
+                       v *= 10;
+               }
+
+               // round
+               h = 5;
+               for(i=0; i<n; i++)
+                       h /= 10;
+
+               v += h;
+               if(v >= 10) {
+                       e++;
+                       v /= 10;
+               }
+       }
+
+       // format +d.dddd+edd
+       buf[0] = '+';
+       if(s)
+               buf[0] = '-';
+       for(i=0; i<n; i++) {
+               s = v;
+               buf[i+2] = s+'0';
+               v -= s;
+               v *= 10.;
+       }
+       buf[1] = buf[2];
+       buf[2] = '.';
+
+       buf[n+2] = 'e';
+       buf[n+3] = '+';
+       if(e < 0) {
+               e = -e;
+               buf[n+3] = '-';
+       }
+
+       buf[n+4] = (e/100) + '0';
+       buf[n+5] = (e/10)%10 + '0';
+       buf[n+6] = (e%10) + '0';
+       gwrite(buf, n+7);
+}
+
+void
+runtime_printcomplex(__complex double v)
+{
+       gwrite("(", 1);
+       runtime_printfloat(__builtin_creal(v));
+       runtime_printfloat(__builtin_cimag(v));
+       gwrite("i)", 2);
+}
+
+void
+runtime_printuint(uint64 v)
+{
+       byte buf[100];
+       int32 i;
+
+       for(i=nelem(buf)-1; i>0; i--) {
+               buf[i] = v%10 + '0';
+               if(v < 10)
+                       break;
+               v = v/10;
+       }
+       gwrite(buf+i, nelem(buf)-i);
+}
+
+void
+runtime_printint(int64 v)
+{
+       if(v < 0) {
+               gwrite("-", 1);
+               v = -v;
+       }
+       runtime_printuint(v);
+}
+
+void
+runtime_printhex(uint64 v)
+{
+       static const char *dig = "0123456789abcdef";
+       byte buf[100];
+       int32 i;
+
+       i=nelem(buf);
+       for(; v>0; v/=16)
+               buf[--i] = dig[v%16];
+       if(i == nelem(buf))
+               buf[--i] = '0';
+       buf[--i] = 'x';
+       buf[--i] = '0';
+       gwrite(buf+i, nelem(buf)-i);
+}
+
+void
+runtime_printpointer(void *p)
+{
+       runtime_printhex((uint64)(uintptr)p);
+}
+
+void
+runtime_printstring(String v)
+{
+       // extern uint32 runtime_maxstring;
+
+       // if(v.len > runtime_maxstring) {
+       //      gwrite("[invalid string]", 16);
+       //      return;
+       // }
+       if(v.__length > 0)
+               gwrite(v.__data, v.__length);
+}
+
+void
+__go_print_space(void)
+{
+       gwrite(" ", 1);
+}
+
+void
+__go_print_nl(void)
+{
+       gwrite("\n", 1);
+}
index 3c8d762..72875fd 100644 (file)
@@ -236,3 +236,15 @@ runtime_showframe(const unsigned char *s)
                traceback = runtime_gotraceback();
        return traceback > 1 || (__builtin_strchr((const char*)s, '.') != nil && __builtin_memcmp(s, "runtime.", 7) != 0);
 }
+
+bool
+runtime_isInf(float64 f, int32 sign)
+{
+       if(!__builtin_isinf(f))
+               return false;
+       if(sign == 0)
+               return true;
+       if(sign > 0)
+               return f > 0;
+       return f < 0;
+}
index 67dabd2..8828aa5 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include <pthread.h>
 #include <semaphore.h>
 #include <ucontext.h>
@@ -275,6 +276,7 @@ int32       runtime_ncpu;
  * common functions and data
  */
 int32  runtime_findnull(const byte*);
+void   runtime_dump(byte*, int32);
 
 /*
  * very low level c-called
@@ -286,6 +288,8 @@ void        runtime_goenvs(void);
 void   runtime_goenvs_unix(void);
 void   runtime_throw(const char*) __attribute__ ((noreturn));
 void   runtime_panicstring(const char*) __attribute__ ((noreturn));
+void   runtime_prints(const char*);
+void   runtime_printf(const char*, ...);
 void*  runtime_mal(uintptr);
 void   runtime_schedinit(void);
 void   runtime_initsig(void);
@@ -374,9 +378,35 @@ void __wrap_rtems_task_variable_add(void **);
 #endif
 
 /*
+ * Names generated by gccgo.
+ */
+#define runtime_printbool      __go_print_bool
+#define runtime_printfloat     __go_print_double
+#define runtime_printint       __go_print_int64
+#define runtime_printiface     __go_print_interface
+#define runtime_printeface     __go_print_empty_interface
+#define runtime_printstring    __go_print_string
+#define runtime_printpointer   __go_print_pointer
+#define runtime_printuint      __go_print_uint64
+#define runtime_printslice     __go_print_slice
+#define runtime_printcomplex   __go_print_complex
+
+/*
  * runtime go-called
  */
-void   runtime_panic(Eface);
+void   runtime_printbool(_Bool);
+void   runtime_printfloat(double);
+void   runtime_printint(int64);
+void   runtime_printiface(Iface);
+void   runtime_printeface(Eface);
+void   runtime_printstring(String);
+void   runtime_printpc(void*);
+void   runtime_printpointer(void*);
+void   runtime_printuint(uint64);
+void   runtime_printhex(uint64);
+void   runtime_printslice(Slice);
+void   runtime_printcomplex(__complex double);
+
 struct __go_func_type;
 void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
                  void **, void **)
@@ -384,7 +414,7 @@ void reflect_call(const struct __go_func_type *, const void *, _Bool, _Bool,
 
 /* Functions.  */
 #define runtime_panic __go_panic
-#define runtime_printf printf
+#define runtime_write(d, v, n) write((d), (v), (n))
 #define runtime_malloc(s) __go_alloc(s)
 #define runtime_free(p) __go_free(p)
 #define runtime_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
@@ -432,6 +462,8 @@ void        runtime_newErrorString(String, Eface*)
 /*
  * wrapped for go users
  */
+bool   runtime_isInf(float64 f, int32 sign);
+#define runtime_isNaN(f) __builtin_isnan(f)
 void   runtime_semacquire(uint32 volatile *);
 void   runtime_semrelease(uint32 volatile *);
 int32  runtime_gomaxprocsfunc(int32 n);
index 6a69fb4..0014068 100644 (file)
@@ -68,7 +68,7 @@ runtime_futexwakeup(uint32 *addr, uint32 cnt)
        // I don't know that futex wakeup can return
        // EAGAIN or EINTR, but if it does, it would be
        // safe to loop and call futex again.
-       runtime_printf("futexwakeup addr=%p returned %lld\n", addr, (long long)ret);
+       runtime_printf("futexwakeup addr=%p returned %D\n", addr, ret);
        *(int32*)0x1006 = 0x1006;
 }