diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | parse.cxx | 55 | ||||
-rw-r--r-- | parse.h | 2 | ||||
-rw-r--r-- | stap.1.in | 7 | ||||
-rw-r--r-- | testsuite/ChangeLog | 5 | ||||
-rwxr-xr-x | testsuite/parseok/eighteen.stp | 6 | ||||
-rwxr-xr-x | testsuite/semok/twentythree.stp | 6 |
7 files changed, 82 insertions, 7 deletions
@@ -1,3 +1,11 @@ +2006-09-06 Frank Ch. Eigler <fche@elastic.org> + + Add basic support for initialized globals. + * parse.cxx (parse_global): Parse initialization clause, implement + by rewriting to "probe begin { var = value }". + * parse.h: Corresponding changes. + * stap.1.in: Document optional initialization. + 2006-09-04 Frank Ch. Eigler <fche@elastic.org> Improve unresolved target-symbol error messages. @@ -785,7 +785,7 @@ parser::parse () else if (t->type == tok_keyword && t->content == "global") { context = con_global; - parse_global (f->globals); + parse_global (f->globals, f->probes); } else if (t->type == tok_keyword && t->content == "function") { @@ -1024,7 +1024,7 @@ parser::parse_statement () void -parser::parse_global (vector <vardecl*>& globals) +parser::parse_global (vector <vardecl*>& globals, vector<probe*>& probes) { const token* t0 = next (); if (! (t0->type == tok_keyword && t0->content == "global")) @@ -1046,7 +1046,56 @@ parser::parse_global (vector <vardecl*>& globals) globals.push_back (d); t = peek (); - if (t && t->type == tok_operator && t->content == ",") + if (t && t->type == tok_operator && t->content == "=") // initialization + { + next (); + + // Create synthetic "begin" probe to assign value to global. + // + // An alternative would be to store the initializer value + // within a new field of vardecl, and use e.g. the + // type-resolution stage to do the rewriting. It could go + // farther: the initializer could live through till + // translation and be emitted as a plain C-level variable + // initializer. + + literal* value = parse_literal (); + + probe_point* pp = new probe_point; + probe_point::component* ppc = new probe_point::component; + ppc->functor = string("begin"); + pp->tok = t; + pp->components.push_back (ppc); + + probe* p = new probe; + p->tok = t; + p->locations.push_back (pp); + + symbol* sym = new symbol; + sym->tok = t; + sym->name = d->name; + + assignment* a = new assignment; + a->tok = t; + a->op = "="; + a->left = sym; + a->right = value; + + expr_statement* es = new expr_statement; + es->tok = t; + es->value = a; + + block* blk = new block; + blk->tok = t; + blk->statements.push_back (es); + + p->body = blk; + probes.push_back (p); + + t = peek (); + } + + if (t && t->type == tok_operator && t->content == ",") // next global { next (); continue; @@ -154,7 +154,7 @@ private: private: // nonterminals void parse_probe (std::vector<probe*>&, std::vector<probe_alias*>&); - void parse_global (std::vector<vardecl*>&); + void parse_global (std::vector<vardecl*>&, std::vector<probe*>&); void parse_functiondecl (std::vector<functiondecl*>&); embeddedcode* parse_embeddedcode (); probe_point* parse_probe_point (); @@ -266,11 +266,12 @@ probes and live as long as the entire systemtap session. There is one namespace for all global variables, regardless of which script file they are found within. A global declaration may be written at the outermost level anywhere, not within a block of code. The following -declaration marks "var1" and "var2" as global. The translator will +declaration marks a few variables as global. The translator will infer for each its value type, and if it is used as an array, its key -types. +types. Optionally, scalar globals may be initialized with a string +or number literal. .RS -.BR global " var1" , " var2" +.BR global " var1" , " var2" , " var3=4" .RE .\" XXX add statistics type here once it's supported diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 3bca1e4c..ee5664ca 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-09-06 Frank Ch. Eigler <fche@elastic.org> + + * parseok/eighteen.stp, semok/twentythree.stp: New files for + testing initialized globals. + 2006-08-21 Martin Hunt <hunt@redhat.com> * lib/stap_run.exp: Check for existence of installtest_p diff --git a/testsuite/parseok/eighteen.stp b/testsuite/parseok/eighteen.stp new file mode 100755 index 00000000..883a6514 --- /dev/null +++ b/testsuite/parseok/eighteen.stp @@ -0,0 +1,6 @@ +#! stap -p1 + +global c, a = 1 +global b = "hello", d + +probe begin { } diff --git a/testsuite/semok/twentythree.stp b/testsuite/semok/twentythree.stp new file mode 100755 index 00000000..dbdaf7e5 --- /dev/null +++ b/testsuite/semok/twentythree.stp @@ -0,0 +1,6 @@ +#! stap -p2 + +global c, a = 1 +global b = "hello", d + +probe begin { print (c = a) print (d = b) } |