fmtof(x) returns the format character of x: acid: +fmtof(33) W fmtsize(x) returns the size in bytes of a single element of result's format: acid: +fmtsize(0\eX) 4 Reference: /n/sources/patch/applied/acid.fmt-inspection Date: Tue Jan 16 12:40:53 CET 2007 Signed-off-by: philip.dye@cs.cmu.edu --- /sys/doc/acid.ms Tue Jan 16 12:40:40 2007 +++ /sys/doc/acid.ms Tue Jan 16 12:40:38 2007 @@ -1202,6 +1202,38 @@ .\" .\" .\" +.Ip fmt fmtof item "Get format +.CW fmtof +evaluates the expression +.I item +and returns the format of the result. +.Ex +acid: +fmtof(33) +W +acid: +fmtof("string") +s +.Ee +.\" +.\" +.\" +.Ip integer fmtsize item "Get format size +.CW fmtsize +evaluates the expression +.I item +and returns the size in bytes of a single element of result's format. +.Ex +acid: +fmtsize('c') +8 +acid: +fmtsize('c'\ec) +1 +acid: +fmtsize(0\eX) +4 +acid: +fmtsize('c'\e3) +10 +.Ee +.\" +.\" +.\" .Ip list fnbound integer "Find start and end address of a function .CW fnbound interprets its --- /sys/src/cmd/acid/builtin.c Tue Jan 16 12:40:44 2007 +++ /sys/src/cmd/acid/builtin.c Wed Jan 17 06:05:05 2007 @@ -40,6 +40,8 @@ void include(Node*, Node*); void regexp(Node*, Node*); void dosysr1(Node*, Node*); +void fmtof(Node*, Node*) ; +void dofmtsize(Node*, Node*) ; typedef struct Btab Btab; struct Btab @@ -80,6 +82,8 @@ "interpret", interpret, "include", include, "regexp", regexp, + "fmtof", fmtof, + "fmtsize", dofmtsize, 0 }; @@ -1264,4 +1268,48 @@ if(p == 0) error("pcline(addr): funny file %s", buf); r->ival = strtol(p+1, 0, 0); +} + +void fmtof(Node *r, Node *args) +{ + Node *av[Maxarg]; + Node res; + + na = 0; + flatten(av, args); + if(na < 1) + error("fmtof(obj): no argument"); + if(na > 1) + error("fmtof(obj): too many arguments") ; + expr(av[0], &res); + + r->op = OCONST; + r->type = TINT ; + r->ival = res.fmt ; + r->fmt = 'c'; +} + +void dofmtsize(Node *r, Node *args) +{ + Node *av[Maxarg]; + Node res; + Store * s ; + Value v ; + + na = 0; + flatten(av, args); + if(na < 1) + error("fmtsize(obj): no argument"); + if(na > 1) + error("fmtsize(obj): too many arguments") ; + expr(av[0], &res); + + v.type = res.type ; + s = &v.Store ; + *s = res ; + + r->op = OCONST; + r->type = TINT ; + r->ival = fmtsize(&v) ; + r->fmt = 'D'; } --- /sys/src/cmd/acid/acid.h Tue Jan 16 12:40:49 2007 +++ /sys/src/cmd/acid/acid.h Tue Jan 16 12:40:49 2007 @@ -53,8 +53,10 @@ Extern List* tracelist; Extern int initialising; Extern int quiet; + extern void (*expop[])(Node*, Node*); #define expr(n, r) (r)->comt=0; (*expop[(n)->op])(n, r); +extern int fmtsize(Value *v) ; enum {