From e6d99771e5c1eef3f69fc847253d4709ffaa84be Mon Sep 17 00:00:00 2001 From: aiju Date: Sat, 10 Nov 2018 13:46:16 +0000 Subject: adding dtracy (crude early version) --- sys/src/cmd/dtracy/parse.y | 123 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 sys/src/cmd/dtracy/parse.y (limited to 'sys/src/cmd/dtracy/parse.y') diff --git a/sys/src/cmd/dtracy/parse.y b/sys/src/cmd/dtracy/parse.y new file mode 100644 index 000000000..9f231dbc9 --- /dev/null +++ b/sys/src/cmd/dtracy/parse.y @@ -0,0 +1,123 @@ +%{ +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" +%} + +%union{ + Node *n; + Symbol *sym; + DTExpr *e; + s64int num; + char *str; + Type *t; +} + +%type expr +%type type + +%token TSYM +%token TNUM +%token TSTR +%token TPRINT TPRINTF +%token TIF +%token TU8 TU16 TU32 TU64 +%token TS8 TS16 TS32 TS64 +%token TSTRING + +%right '?' +%left TOR +%left TAND +%left '|' +%left '^' +%left '&' +%left TEQ TNE +%left '<' '>' TLE TGE +%left TLSL TLSR +%left '+' '-' +%left '*' '/' '%' +%left unary +%right castprec + +%% + +program: | program clause + +clause: { clausebegin(); } probes optpredicate optaction { clauseend(); } + +optpredicate: | TIF expr { addpred(codegen(exprcheck($2, 1))); } + +optaction: + { + addstat(STATPRINT); + addarg(node(OSYM, getsym("probe"))); + } + | action +action: '{' stats '}' +stats: | stats0 | stats0 ';' +stats0: stat | stats0 ';' stat + +stat: expr { addstat(STATEXPR, exprcheck($1, 0)); } +| TPRINT { addstat(STATPRINT); } pelist +| TPRINTF { addstat(STATPRINTF); } pelist + + +pelist: + '(' ')' + | '(' arg ',' ')' + | '(' elist2 optcomma ')' + | arg optcomma + | elist2 optcomma +elist2: arg ',' arg | elist2 ',' arg +arg: expr { addarg(exprcheck($1, 0)); } +optcomma: | ',' + +expr: + TSYM { $$ = node(OSYM, $1); } + | TNUM { $$ = node(ONUM, $1); } + | TSTR { $$ = node(OSTR, $1); } + | expr '+' expr { $$ = node(OBIN, OPADD, $1, $3); } + | expr '-' expr { $$ = node(OBIN, OPSUB, $1, $3); } + | expr '*' expr { $$ = node(OBIN, OPMUL, $1, $3); } + | expr '/' expr { $$ = node(OBIN, OPDIV, $1, $3); } + | expr '%' expr { $$ = node(OBIN, OPMOD, $1, $3); } + | expr '&' expr { $$ = node(OBIN, OPAND, $1, $3); } + | expr '|' expr { $$ = node(OBIN, OPOR, $1, $3); } + | expr '^' expr { $$ = node(OBIN, OPXOR, $1, $3); } + | expr TLSL expr { $$ = node(OBIN, OPLSH, $1, $3); } + | expr TLSR expr { $$ = node(OBIN, OPRSH, $1, $3); } + | expr TEQ expr { $$ = node(OBIN, OPEQ, $1, $3); } + | expr TNE expr { $$ = node(OBIN, OPNE, $1, $3); } + | expr '<' expr { $$ = node(OBIN, OPLT, $1, $3); } + | expr TLE expr { $$ = node(OBIN, OPLE, $1, $3); } + | expr '>' expr { $$ = node(OBIN, OPLT, $3, $1); } + | expr TGE expr { $$ = node(OBIN, OPLE, $3, $1); } + | expr TAND expr { $$ = node(OBIN, OPLAND, $1, $3); } + | expr TOR expr { $$ = node(OBIN, OPLOR, $1, $3); } + | '-' expr %prec unary { $$ = node(OBIN, OPSUB, node(ONUM, 0LL), $2); } + | '~' expr %prec unary { $$ = node(OBIN, OPXNOR, node(ONUM, 0LL), $2); } + | '!' expr %prec unary { $$ = node(OLNOT, $2); } + | '(' expr ')' { $$ = $2; } + | expr '?' expr ':' expr %prec '?' { $$ = node(OTERN, $1, $3, $5); } + | '(' type ')' expr %prec castprec { $$ = node(OCAST, $2, $4); } + +type: + TU8 { $$ = type(TYPINT, 1, 0); } + | TS8 { $$ = type(TYPINT, 1, 1); } + | TU16 { $$ = type(TYPINT, 2, 0); } + | TS16 { $$ = type(TYPINT, 2, 1); } + | TU32 { $$ = type(TYPINT, 4, 0); } + | TS32 { $$ = type(TYPINT, 4, 1); } + | TU64 { $$ = type(TYPINT, 8, 0); } + | TS64 { $$ = type(TYPINT, 8, 1); } + | TSTRING { $$ = type(TYPSTRING); } + +probes: + TSYM { addprobe($1->name); } + | probes ',' TSYM { addprobe($3->name); } + + +%% -- cgit v1.2.3