From 9b5af2958a35174a67076c0f27cff0ed5950736d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 11 Feb 2009 14:34:32 -0800 Subject: Add high-level support for @cast()ing This handles all of the parsing, traversal, and optimization. It doesn't actually resolve the cast yet though. * staptree.h (struct cast_op, visitor::visit_cast_op): New. * staptree.cxx (cast_op::print/visit, various visitor::visit_cast_op's): Incorporate cast_op into the basic tree operations. * parse.cxx (parser::parse_symbol): Parse @cast operator with an expression operand, type string, and optional module string. * translate.cxx (c_unparser::visit_cast_op): Error out if a @cast survives to translation. * elaborate.cxx (typeresolution_info::visit_cast_op): Error out if a @cast survives to type resolution. (symbol_fetcher::visit_cast_op): treat @casts as a symbol target (void_statement_reducer::visit_cast_op): unused @casts can be discarded, but the operand should still be evaluated. --- elaborate.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'elaborate.cxx') diff --git a/elaborate.cxx b/elaborate.cxx index ba50defb..981fc7c7 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -701,6 +701,11 @@ struct symbol_fetcher e->base->visit_indexable (this); } + void visit_cast_op (cast_op* e) + { + sym = e; + } + void throwone (const token* t) { throw semantic_error ("Expecting symbol or array index expression", t); @@ -2505,6 +2510,7 @@ struct void_statement_reducer: public update_visitor void visit_concatenation (concatenation* e); void visit_functioncall (functioncall* e); void visit_print_format (print_format* e); + void visit_cast_op (cast_op* e); // these are a bit hairy to grok due to the intricacies of indexables and // stats, so I'm chickening out and skipping them... @@ -2772,6 +2778,19 @@ void_statement_reducer::visit_print_format (print_format* e) provide (e); } +void +void_statement_reducer::visit_cast_op (cast_op* e) +{ + // When the result of a cast operation isn't needed, it's just as good to + // evaluate the operand directly + + if (session.verbose>2) + clog << "Eliding unused typecast " << *e->tok << endl; + + relaxed_p = false; + e->operand->visit(this); +} + void semantic_pass_opt5 (systemtap_session& s, bool& relaxed_p) { @@ -3398,6 +3417,18 @@ typeresolution_info::visit_target_symbol (target_symbol* e) } +void +typeresolution_info::visit_cast_op (cast_op* e) +{ + // Like target_symbol, a cast_op shouldn't survive this far + // unless it was not resolved and its value is really needed. + if (e->saved_conversion_error) + throw (* (e->saved_conversion_error)); + else + throw semantic_error("unresolved cast expression", e->tok); +} + + void typeresolution_info::visit_arrayindex (arrayindex* e) { -- cgit From f80d90043cf900dc6027329a61489444d7ab4ee3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 11 Feb 2009 15:28:41 -0800 Subject: Enable session-wide code filtering This will be used to hook to dwarf_builder to all functions and probes so it can attempt @cast expansion. * session.h (systemtap_session): Add a vector of update_visitors that will act as filters for all probes and functions. * elaborate.cxx (semantic_pass_symbols): Run probes and functions through each registered code filter. --- elaborate.cxx | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'elaborate.cxx') diff --git a/elaborate.cxx b/elaborate.cxx index 981fc7c7..9f8aa450 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1092,6 +1092,9 @@ semantic_pass_symbols (systemtap_session& s) try { + for (unsigned j=0; jbody = s.code_filters[j]->require (fd->body); + sym.current_function = fd; sym.current_probe = 0; fd->body->visit (& sym); @@ -1124,6 +1127,9 @@ semantic_pass_symbols (systemtap_session& s) try { + for (unsigned k=0; kbody = s.code_filters[k]->require (dp->body); + sym.current_function = 0; sym.current_probe = dp; dp->body->visit (& sym); -- cgit From 482fe2af17347b472232c5d7c4b26e53606e395e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 17 Feb 2009 19:19:48 -0800 Subject: Bump copyright years to 2009 --- elaborate.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'elaborate.cxx') diff --git a/elaborate.cxx b/elaborate.cxx index 9f8aa450..02229fbe 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1,5 +1,5 @@ // elaboration functions -// Copyright (C) 2005-2008 Red Hat Inc. +// Copyright (C) 2005-2009 Red Hat Inc. // Copyright (C) 2008 Intel Corporation // // This file is part of systemtap, and is free software. You can -- cgit