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.
This commit is contained in:
cinap_lenrek 2014-02-09 22:43:09 +01:00
parent 9bdf602ebb
commit 16acf605e2
6 changed files with 26 additions and 17 deletions

View file

@ -29,6 +29,8 @@ typedef struct Frtype Frtype;
Extern int kernel;
Extern int text;
Extern int silent;
Extern int fsize[];
Extern char afmt;
Extern Fhdr fhdr;
Extern int line;
Extern Biobuf* bout;

View file

@ -87,7 +87,7 @@ struct Btab
0
};
char vfmt[] = "aBbcCdDfFgGiIoOqQrRsSuUVWxXYZ38";
char vfmt[] = "aABbcCdDfFgGiIoOqQrRsSuUVWxXYZ38";
void
mkprint(Lsym *s)
@ -365,7 +365,7 @@ follow(Node *r, Node *args)
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 @@ funcbound(Node *r, Node *args)
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 @@ void
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 @@ patom(char type, Store *res)
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 @@ comx(Node res)
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;

View file

@ -6,7 +6,7 @@
#define Extern extern
#include "acid.h"
static int fsize[] =
int fsize[] =
{
['A'] 4,
['B'] 4,
@ -149,7 +149,7 @@ oframe(Node *n, Node *res)
res->ival = ival;
res->op = OCONST;
res->fmt = 'X';
res->fmt = 'A';
res->type = TINT;
/* Try and set comt */

View file

@ -185,7 +185,7 @@ listvar(char *s, vlong v)
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 @@ trlist(Map *map, uvlong pc, uvlong sp, Symbol *sym)
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;

View file

@ -281,7 +281,7 @@ readtext(char *s)
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;

View file

@ -7,6 +7,7 @@
#include "acid.h"
#include "y.tab.h"
char afmt = 'X';
static int syren;
Lsym*
@ -88,7 +89,7 @@ varsym(void)
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 @@ varsym(void)
list->ival = s->type;
list->next = al(TINT);
list = list->next;
list->fmt = 'X';
list->fmt = l->v->fmt;
list->ival = v;
}
@ -122,6 +123,12 @@ varreg(void)
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;
v->set = 1;