diff options
author | fche <fche> | 2006-09-06 15:01:37 +0000 |
---|---|---|
committer | fche <fche> | 2006-09-06 15:01:37 +0000 |
commit | 4b5f3e450724431c52c100143d859846f4009329 (patch) | |
tree | 9f56e99a45928635482aa0356b18bac47fa730de /parse.cxx | |
parent | bf72ac26078c3c179c98afca46e69827acf4d246 (diff) | |
download | systemtap-steved-4b5f3e450724431c52c100143d859846f4009329.tar.gz systemtap-steved-4b5f3e450724431c52c100143d859846f4009329.tar.xz systemtap-steved-4b5f3e450724431c52c100143d859846f4009329.zip |
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-06 Frank Ch. Eigler <fche@elastic.org>
* parseok/eighteen.stp, semok/twentythree.stp: New files for
testing initialized globals.
Diffstat (limited to 'parse.cxx')
-rw-r--r-- | parse.cxx | 55 |
1 files changed, 52 insertions, 3 deletions
@@ -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; |