コード例 #1
0
ファイル: print.c プロジェクト: Ahmah2009/golang
// Very simple printf.  Only for debugging prints.
// Do not add to this without checking with Rob.
static void
vprintf(int8 *s, byte *base)
{
	int8 *p, *lp;
	uintptr arg, narg;
	byte *v;

//	lock(&debuglock);

	lp = p = s;
	arg = 0;
	for(; *p; p++) {
		if(*p != '%')
			continue;
		if(p > lp)
			runtime·write(2, lp, p-lp);
		p++;
		narg = 0;
		switch(*p) {
		case 't':
			narg = arg + 1;
			break;
		case 'd':	// 32-bit
		case 'x':
			arg = runtime·rnd(arg, 4);
			narg = arg + 4;
			break;
		case 'D':	// 64-bit
		case 'U':
		case 'X':
		case 'f':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + 8;
			break;
		case 'C':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + 16;
			break;
		case 'p':	// pointer-sized
		case 's':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(uintptr);
			break;
		case 'S':	// pointer-aligned but bigger
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(String);
			break;
		case 'a':	// pointer-aligned but bigger
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Slice);
			break;
		case 'i':	// pointer-aligned but bigger
		case 'e':
			arg = runtime·rnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Eface);
			break;
		}
		v = base+arg;
		switch(*p) {
		case 'a':
			runtime·printslice(*(Slice*)v);
			break;
		case 'd':
			runtime·printint(*(int32*)v);
			break;
		case 'D':
			runtime·printint(*(int64*)v);
			break;
		case 'e':
			runtime·printeface(*(Eface*)v);
			break;
		case 'f':
			runtime·printfloat(*(float64*)v);
			break;
		case 'C':
			runtime·printcomplex(*(Complex128*)v);
			break;
		case 'i':
			runtime·printiface(*(Iface*)v);
			break;
		case 'p':
			runtime·printpointer(*(void**)v);
			break;
		case 's':
			runtime·prints(*(int8**)v);
			break;
		case 'S':
			runtime·printstring(*(String*)v);
			break;
		case 't':
			runtime·printbool(*(bool*)v);
			break;
		case 'U':
			runtime·printuint(*(uint64*)v);
			break;
		case 'x':
			runtime·printhex(*(uint32*)v);
			break;
		case 'X':
			runtime·printhex(*(uint64*)v);
			break;
		}
		arg = narg;
		lp = p+1;
	}
	if(p > lp)
		runtime·write(2, lp, p-lp);

//	unlock(&debuglock);
}
コード例 #2
0
ファイル: print.c プロジェクト: lougxing/golang-china
// Very simple printf.  Only for debugging prints.
// Do not add to this without checking with Rob.
static void
vprintf(int8 *s, byte *arg)
{
	int8 *p, *lp;
	byte *narg;

//	lock(&debuglock);

	lp = p = s;
	for(; *p; p++) {
		if(*p != '%')
			continue;
		if(p > lp)
			write(fd, lp, p-lp);
		p++;
		narg = nil;
		switch(*p) {
		case 't':
			narg = arg + 1;
			break;
		case 'd':	// 32-bit
		case 'x':
			arg = vrnd(arg, 4);
			narg = arg + 4;
			break;
		case 'D':	// 64-bit
		case 'U':
		case 'X':
		case 'f':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + 8;
			break;
		case 'p':	// pointer-sized
		case 's':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(uintptr);
			break;
		case 'S':	// pointer-aligned but bigger
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(String);
			break;
		case 'a':	// pointer-aligned but bigger
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Slice);
			break;
		case 'i':	// pointer-aligned but bigger
		case 'e':
			arg = vrnd(arg, sizeof(uintptr));
			narg = arg + sizeof(Eface);
			break;
		}
		switch(*p) {
		case 'a':
			·printslice(*(Slice*)arg);
			break;
		case 'd':
			·printint(*(int32*)arg);
			break;
		case 'D':
			·printint(*(int64*)arg);
			break;
		case 'e':
			·printeface(*(Eface*)arg);
			break;
		case 'f':
			·printfloat(*(float64*)arg);
			break;
		case 'i':
			·printiface(*(Iface*)arg);
			break;
		case 'p':
			·printpointer(*(void**)arg);
			break;
		case 's':
			prints(*(int8**)arg);
			break;
		case 'S':
			·printstring(*(String*)arg);
			break;
		case 't':
			·printbool(*(bool*)arg);
			break;
		case 'U':
			·printuint(*(uint64*)arg);
			break;
		case 'x':
			·printhex(*(uint32*)arg);
			break;
		case 'X':
			·printhex(*(uint64*)arg);
			break;
		case '!':
			·panicl(-1);
		}
		arg = narg;
		lp = p+1;
	}
	if(p > lp)
		write(fd, lp, p-lp);

//	unlock(&debuglock);
}