shithub: riscv

Download patch

ref: 16acf605e21e55e8f0520cf54016bfec5291802e
parent: 9bdf602ebbdcfcb4baaeb17499a1f1f6865ddc61
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Feb 9 17:43:09 EST 2014

acid: make 'a' and 'A' format to have the same size as mach->szaddr

to make it easier to write portable acid code, we
introduce 'A' format in the same meaning as in db(1):

A    Print the value of dot in hexadecimal.  Dot is
     unaffected.

both 'a' (symbolic) and 'A' will both have 64 or 32 bit
size depending on the mach, so pointer array indexing
works the same.

--- a/sys/src/cmd/acid/acid.h
+++ b/sys/src/cmd/acid/acid.h
@@ -29,6 +29,8 @@
 Extern int	kernel;
 Extern int	text;
 Extern int	silent;
+Extern int	fsize[];
+Extern char	afmt;
 Extern Fhdr	fhdr;
 Extern int	line;
 Extern Biobuf*	bout;
--- a/sys/src/cmd/acid/builtin.c
+++ b/sys/src/cmd/acid/builtin.c
@@ -87,7 +87,7 @@
 	0
 };
 
-char vfmt[] = "aBbcCdDfFgGiIoOqQrRsSuUVWxXYZ38";
+char vfmt[] = "aABbcCdDfFgGiIoOqQrRsSuUVWxXYZ38";
 
 void
 mkprint(Lsym *s)
@@ -365,7 +365,7 @@
 	for(i = 0; i < n; i++) {
 		l = al(TINT);
 		l->ival = f[i];
-		l->fmt = 'X';
+		l->fmt = 'A';
 		*tail = l;
 		tail = &l->next;
 	}
@@ -390,11 +390,11 @@
 		r->l = al(TINT);
 		l = r->l;
 		l->ival = bounds[0];
-		l->fmt = 'X';
+		l->fmt = 'A';
 		l->next = al(TINT);
 		l = l->next;
 		l->ival = bounds[1];
-		l->fmt = 'X';
+		l->fmt = 'A';
 	}
 }
 
@@ -970,10 +970,14 @@
 patom(char type, Store *res)
 {
 	int i;
+	char fmt;
 	char buf[512];
 	extern char *typenames[];
 
-	switch(res->fmt) {
+	fmt = res->fmt;
+	if(fmt == 'A')
+		fmt = afmt;
+	switch(fmt) {
 	case 'c':
 		Bprint(bout, "%c", (int)res->ival);
 		break;
@@ -1065,7 +1069,6 @@
 			Bprint(bout, "%S", (Rune*)res->string->string);
 		break;
 	case 'a':
-	case 'A':
 		symoff(buf, sizeof(buf), res->ival, CANY);
 		Bprint(bout, "%s", buf);
 		break;
@@ -1117,10 +1120,7 @@
 	Lsym *sl;
 	Node *n, xx;
 
-	if(res.fmt != 'a' && res.fmt != 'A')
-		return 0;
-
-	if(res.comt == 0 || res.comt->base == 0)
+	if(res.fmt != 'a' || res.comt == 0 || res.comt->base == 0)
 		return 0;
 
 	sl = res.comt->base;
--- a/sys/src/cmd/acid/expr.c
+++ b/sys/src/cmd/acid/expr.c
@@ -6,7 +6,7 @@
 #define Extern extern
 #include "acid.h"
 
-static int fsize[] =
+int fsize[] =
 {
 	['A'] 4,
 	['B'] 4,
@@ -149,7 +149,7 @@
 
 	res->ival = ival;
 	res->op = OCONST;
-	res->fmt = 'X';
+	res->fmt = 'A';
 	res->type = TINT;
 
 	/* Try and set comt */
--- a/sys/src/cmd/acid/list.c
+++ b/sys/src/cmd/acid/list.c
@@ -185,7 +185,7 @@
 	l->string = strnode(s);
 	l->next = al(TINT);
 	l = l->next;
-	l->fmt = 'X';
+	l->fmt = 'A';
 	l->ival = v;
 
 	return tl;
@@ -260,7 +260,7 @@
 	l = al(TINT);			/* Function address */
 	q->l = l;
 	l->ival = sym->value;
-	l->fmt = 'X';
+	l->fmt = 'A';
 
 	l->next = al(TINT);		/* called from address */
 	l = l->next;
--- a/sys/src/cmd/acid/main.c
+++ b/sys/src/cmd/acid/main.c
@@ -281,7 +281,7 @@
 	if(mach->sbreg && lookup(0, mach->sbreg, &sym)) {
 		mach->sb = sym.value;
 		l = enter("SB", Tid);
-		l->v->fmt = 'X';
+		l->v->fmt = 'A';
 		l->v->ival = mach->sb;
 		l->v->type = TINT;
 		l->v->set = 1;
--- a/sys/src/cmd/acid/util.c
+++ b/sys/src/cmd/acid/util.c
@@ -7,6 +7,7 @@
 #include "acid.h"
 #include "y.tab.h"
 
+char afmt = 'X';
 static int syren;
 
 Lsym*
@@ -88,7 +89,7 @@
 			l->v->type = TINT;
 			l->v->ival = v;
 			if(l->v->comt == 0)
-				l->v->fmt = 'X';
+				l->v->fmt = 'A';
 
 			/* Enter as list of { name, type, value } */
 			list = al(TSTRING);
@@ -101,7 +102,7 @@
 			list->ival = s->type;
 			list->next = al(TINT);
 			list = list->next;
-			list->fmt = 'X';
+			list->fmt = l->v->fmt;
 			list->ival = v;
 
 		}
@@ -121,6 +122,12 @@
 	Value *v;
 	Reglist *r;
 	List **tail, *li;
+
+	if(mach->szaddr == 8){
+		afmt = 'Y';
+		fsize['a'] = fsize[afmt];
+		fsize['A'] = fsize[afmt];
+	}
 
 	l = mkvar("registers");
 	v = l->v;