summaryrefslogtreecommitdiffstats
path: root/staptree.h
diff options
context:
space:
mode:
authorfche <fche>2006-01-24 17:58:02 +0000
committerfche <fche>2006-01-24 17:58:02 +0000
commitcbfbbf6996cbe3b9fe57ac2014aa7262bb6890d6 (patch)
tree89b507411bd828b12142f0962be3eb4a33c3a45d /staptree.h
parent46746514a6943520ff73b6f77d35477e2abb30ba (diff)
downloadsystemtap-steved-cbfbbf6996cbe3b9fe57ac2014aa7262bb6890d6.tar.gz
systemtap-steved-cbfbbf6996cbe3b9fe57ac2014aa7262bb6890d6.tar.xz
systemtap-steved-cbfbbf6996cbe3b9fe57ac2014aa7262bb6890d6.zip
2006-01-24 Frank Ch. Eigler <fche@elastic.org>
PR 2060 etc. * tapsets.cxx (visit_target_symbol): Tolerate failed resolution by letting target_symbol instance pass through to optimizer and type checker. * elaborate.cxx (semantic_pass_optimize): New family of functions and associated visitor classes. (visit_for_loop): Tolerate absent init/incr clauses. (semantic_pass): Invoke unless unoptimized (-u) option given. * main.cxx, session.h: Add support for flag. * staptree.cxx (visit_for_loop): Tolerate absent init/incr clauses. (traversing_visitor::visit_arrayindex): Visit the index expressions. (functioncall_traversing_visitor): New class. (varuse_tracking_visitor): New class. * staptree.h: Corresponding changes. * parse.cxx (parse_for_loop): Represent absent init/incr expressions with null statement pointer instead of optimized-out dummy numbers. * stap.1.in: Document optimization. * testsuite/{semko,transko}/*.stp: Added "-u" or other code to many tests to check bad code without optimizer elision. * testsuite/semok/optimize.stp: New test. * elaborate.cxx (unresolved, invalid, mismatch): Standardize error message wording. * stapfuncs.5.in: Tweak print/printf docs. * tapset/logging.stp: Remove redundant "print" auxiliary function, since it's a translator built-in. * testsuite/transok/five.stp: Extend test. * translate.cxx (emit_symbol_data): Put symbol table into a separate temporary header file, to make "-p3" output easier on the eyes. * buildrun.cxx (compile_pass): Eliminate test-mode support throughout. * main.cxx, session.h, translate.cxx: Ditto. * main.cxx (main): For last-pass=2 runs, print post-optimization ASTs.
Diffstat (limited to 'staptree.h')
-rw-r--r--staptree.h49
1 files changed, 43 insertions, 6 deletions
diff --git a/staptree.h b/staptree.h
index 4b3eb996..fecd6aaf 100644
--- a/staptree.h
+++ b/staptree.h
@@ -12,6 +12,7 @@
#include "session.h"
#include <map>
#include <stack>
+#include <set>
#include <string>
#include <vector>
#include <iostream>
@@ -443,9 +444,9 @@ struct block: public statement
struct expr_statement;
struct for_loop: public statement
{
- expr_statement* init;
+ expr_statement* init; // may be 0
expression* cond;
- expr_statement* incr;
+ expr_statement* incr; // may be 0
statement* block;
void print (std::ostream& o) const;
void visit (visitor* u);
@@ -485,7 +486,7 @@ struct if_statement: public statement
{
expression* condition;
statement* thenblock;
- statement* elseblock;
+ statement* elseblock; // may be 0
void print (std::ostream& o) const;
void visit (visitor* u);
};
@@ -630,9 +631,9 @@ struct visitor
};
-// A default kind of visitor, which by default travels down
-// to the leaves of the statement/expression tree, up to
-// but excluding following vardecls (referent pointers).
+// A simple kind of visitor, which travels down to the leaves of the
+// statement/expression tree, up to but excluding following vardecls
+// and functioncalls.
struct traversing_visitor: public visitor
{
void visit_block (block *s);
@@ -670,6 +671,42 @@ struct traversing_visitor: public visitor
};
+// A kind of traversing visitor, which also follows function calls.
+// It uses an internal set object to prevent infinite recursion.
+struct functioncall_traversing_visitor: public traversing_visitor
+{
+ std::set<functiondecl*> traversed;
+ void visit_functioncall (functioncall* e);
+};
+
+
+// A kind of traversing visitor, which also follows function calls,
+// and stores the vardecl* referent of each variable read and/or
+// written and other such sundry side-effect data. It's used by
+// the elaboration-time optimizer pass.
+struct varuse_collecting_visitor: public functioncall_traversing_visitor
+{
+ std::set<vardecl*> read;
+ std::set<vardecl*> written;
+ bool embedded_seen;
+ expression* current_lvalue;
+ expression* current_lrvalue;
+ varuse_collecting_visitor():
+ embedded_seen (false),
+ current_lvalue(0),
+ current_lrvalue(0) {}
+ void visit_embeddedcode (embeddedcode *s);
+ void visit_print_format (print_format *e);
+ void visit_assignment (assignment *e);
+ void visit_arrayindex (arrayindex *e);
+ void visit_symbol (symbol *e);
+ void visit_pre_crement (pre_crement *e);
+ void visit_post_crement (post_crement *e);
+};
+
+
+
+
// A kind of visitor that throws an semantic_error exception
// whenever a non-overridden method is called.
struct throwing_visitor: public visitor