[phc-internals] [phc commit] r1136 - in trunk/src: codegen
generated generated_src pass_manager process_ir
codesite-noreply at google.com
codesite-noreply at google.com
Wed Apr 2 22:28:37 IST 2008
Author: paul.biggar
Date: Wed Apr 2 14:26:03 2008
New Revision: 1136
Modified:
trunk/src/codegen/Propagate_copies.cpp
trunk/src/generated/cmdline.c
trunk/src/generated/cmdline.h
trunk/src/generated_src/phc.ggo
trunk/src/pass_manager/Pass_manager.cpp
trunk/src/pass_manager/Pass_manager.h
trunk/src/process_ir/debug.cpp
trunk/src/process_ir/debug.h
Log:
Passes in phc don't really have a good of way of doing debugging. This
adds the --debug=pass flag, which turns on the new cdebug stream during
the execution of that pass.
I uncommented the debugging commands in Propagate_copies, they will now
print to standard error if --debug=prc is passed.
Modified: trunk/src/codegen/Propagate_copies.cpp
==============================================================================
--- trunk/src/codegen/Propagate_copies.cpp (original)
+++ trunk/src/codegen/Propagate_copies.cpp Wed Apr 2 14:26:03 2008
@@ -161,7 +161,7 @@
{
map<string, int>::const_iterator i;
for(i = in.begin(); i != in.end(); i++)
- cout << (*i).first << ": " << (*i).second << endl;
+ cdebug << (*i).first << ": " << (*i).second << endl;
}
bool extract_simple_assignment (Eval_expr* in, VARIABLE_NAME*& lhs,
VARIABLE_NAME*& rhs, Assignment*& assignment)
@@ -188,38 +188,40 @@
return;
}
-// debug (in);
+ cdebug << "TEST" << endl;
+
+ debug (in);
// get useful variables
VARIABLE_NAME *lhs, *rhs;
Assignment* assignment;
if (extract_simple_assignment (in, lhs, rhs, assignment))
{
-// xadebug (lhs);
-// xadebug (rhs);
-// cout << "is simple assignment" << endl;
+ xadebug (lhs);
+ xadebug (rhs);
+ cdebug << "is simple assignment" << endl;
string slhs = *lhs->value;
string srhs = *rhs->value;
// add to the list of for future consideration
if (lhs->attrs->is_true ("phc.codegen.compiler_generated"))
{
-// cout << "lhs is compiler generated" << endl;
+ cdebug << "lhs is compiler generated" << endl;
assert (replaceable.find (slhs) == replaceable.end ());
replaceable [slhs] = assignment;
}
-// cout << "use counts" << endl;
-// print_map (use_counts);
-// cout << "def counts" << endl;
-// print_map (def_counts);
+ cdebug << "use counts" << endl;
+ print_map (use_counts);
+ cdebug << "def counts" << endl;
+ print_map (def_counts);
// be conservative
if (replaceable.find (srhs) != replaceable.end ()
&& use_counts [srhs] == 1
&& def_counts [srhs] == 1)
{
-// cout << "r s is replacable" << endl;
+ cdebug << "r s is replacable" << endl;
replaceable [srhs]->variable = new Variable (NULL, new
VARIABLE_NAME (s(slhs)), new List<Expr*>);
// note lack of out->push_back (in);
return;
Modified: trunk/src/generated/cmdline.c
==============================================================================
--- trunk/src/generated/cmdline.c (original)
+++ trunk/src/generated/cmdline.c Wed Apr 2 14:26:03 2008
@@ -58,10 +58,11 @@
" --tab=STRING String to use for tabs while unparsing
\n (default=`\t')",
" --no-hash-bang Do not output any #! lines (default=off)",
"\nDEBUGGING PHC:",
- " -D, --dump=passname Dump input as PHP (although potentially
with gotos \n and labels) after the pass named 'passname'",
- " -U, --udump=passname Dump input as runnable PHP after the
pass named \n 'passname'",
+ " --debug=passname Print debugging information for the pass
named \n 'passname",
+ " --dump=passname Dump input as PHP (although potentially
with gotos \n and labels) after the pass named 'passname'",
+ " --udump=passname Dump input as runnable PHP after the
pass named \n 'passname'",
" --ddump=passname Dump input as DOT after the pass named 'passname'",
- " -X, --xdump=passname Dump input as XML after the pass named 'passname'",
+ " --xdump=passname Dump input as XML after the pass named 'passname'",
" --list-passes List the passes to be run (default=off)",
" --dont-fail Dont fail on error (after parsing) (default=off)",
" --no-xml-attrs When dumping XML, omit node attributes
\n (default=off)",
@@ -147,6 +148,7 @@
args_info->no_empty_lists_given = 0 ;
args_info->tab_given = 0 ;
args_info->no_hash_bang_given = 0 ;
+ args_info->debug_given = 0 ;
args_info->dump_given = 0 ;
args_info->udump_given = 0 ;
args_info->ddump_given = 0 ;
@@ -190,6 +192,8 @@
args_info->tab_arg = gengetopt_strdup ("\t");
args_info->tab_orig = NULL;
args_info->no_hash_bang_flag = 0;
+ args_info->debug_arg = NULL;
+ args_info->debug_orig = NULL;
args_info->dump_arg = NULL;
args_info->dump_orig = NULL;
args_info->udump_arg = NULL;
@@ -240,21 +244,24 @@
args_info->no_empty_lists_help = gengetopt_args_info_full_help[26] ;
args_info->tab_help = gengetopt_args_info_full_help[27] ;
args_info->no_hash_bang_help = gengetopt_args_info_full_help[28] ;
- args_info->dump_help = gengetopt_args_info_full_help[30] ;
+ args_info->debug_help = gengetopt_args_info_full_help[30] ;
+ args_info->debug_min = -1;
+ args_info->debug_max = -1;
+ args_info->dump_help = gengetopt_args_info_full_help[31] ;
args_info->dump_min = -1;
args_info->dump_max = -1;
- args_info->udump_help = gengetopt_args_info_full_help[31] ;
+ args_info->udump_help = gengetopt_args_info_full_help[32] ;
args_info->udump_min = -1;
args_info->udump_max = -1;
- args_info->ddump_help = gengetopt_args_info_full_help[32] ;
+ args_info->ddump_help = gengetopt_args_info_full_help[33] ;
args_info->ddump_min = -1;
args_info->ddump_max = -1;
- args_info->xdump_help = gengetopt_args_info_full_help[33] ;
+ args_info->xdump_help = gengetopt_args_info_full_help[34] ;
args_info->xdump_min = -1;
args_info->xdump_max = -1;
- args_info->list_passes_help = gengetopt_args_info_full_help[34] ;
- args_info->dont_fail_help = gengetopt_args_info_full_help[35] ;
- args_info->no_xml_attrs_help = gengetopt_args_info_full_help[36] ;
+ args_info->list_passes_help = gengetopt_args_info_full_help[35] ;
+ args_info->dont_fail_help = gengetopt_args_info_full_help[36] ;
+ args_info->no_xml_attrs_help = gengetopt_args_info_full_help[37] ;
}
@@ -403,6 +410,7 @@
free_string_field (&(args_info->output_orig));
free_string_field (&(args_info->tab_arg));
free_string_field (&(args_info->tab_orig));
+ free_multiple_string_field (args_info->debug_given,
&(args_info->debug_arg), &(args_info->debug_orig));
free_multiple_string_field (args_info->dump_given,
&(args_info->dump_arg), &(args_info->dump_orig));
free_multiple_string_field (args_info->udump_given,
&(args_info->udump_arg), &(args_info->udump_orig));
free_multiple_string_field (args_info->ddump_given,
&(args_info->ddump_arg), &(args_info->ddump_orig));
@@ -496,6 +504,7 @@
write_into_file(outfile, "tab", args_info->tab_orig, 0);
if (args_info->no_hash_bang_given)
write_into_file(outfile, "no-hash-bang", 0, 0 );
+ write_multiple_into_file(outfile, args_info->debug_given, "debug",
args_info->debug_orig, 0);
write_multiple_into_file(outfile, args_info->dump_given, "dump",
args_info->dump_orig, 0);
write_multiple_into_file(outfile, args_info->udump_given, "udump",
args_info->udump_orig, 0);
write_multiple_into_file(outfile, args_info->ddump_given, "ddump",
args_info->ddump_orig, 0);
@@ -764,16 +773,19 @@
if (check_multiple_option_occurrences(prog_name,
args_info->c_option_given, args_info->c_option_min,
args_info->c_option_max, "'--c-option' ('-C')"))
error = 1;
- if (check_multiple_option_occurrences(prog_name,
args_info->dump_given, args_info->dump_min,
args_info->dump_max, "'--dump' ('-D')"))
+ if (check_multiple_option_occurrences(prog_name,
args_info->debug_given, args_info->debug_min, args_info->debug_max, "'--debug'"))
error = 1;
- if (check_multiple_option_occurrences(prog_name,
args_info->udump_given, args_info->udump_min,
args_info->udump_max, "'--udump' ('-U')"))
+ if (check_multiple_option_occurrences(prog_name,
args_info->dump_given, args_info->dump_min, args_info->dump_max, "'--dump'"))
+ error = 1;
+
+ if (check_multiple_option_occurrences(prog_name,
args_info->udump_given, args_info->udump_min, args_info->udump_max, "'--udump'"))
error = 1;
if (check_multiple_option_occurrences(prog_name,
args_info->ddump_given, args_info->ddump_min, args_info->ddump_max, "'--ddump'"))
error = 1;
- if (check_multiple_option_occurrences(prog_name,
args_info->xdump_given, args_info->xdump_min,
args_info->xdump_max, "'--xdump' ('-X')"))
+ if (check_multiple_option_occurrences(prog_name,
args_info->xdump_given, args_info->xdump_min, args_info->xdump_max, "'--xdump'"))
error = 1;
@@ -1010,6 +1022,7 @@
struct generic_list * run_list = NULL;
struct generic_list * r_option_list = NULL;
struct generic_list * c_option_list = NULL;
+ struct generic_list * debug_list = NULL;
struct generic_list * dump_list = NULL;
struct generic_list * udump_list = NULL;
struct generic_list * ddump_list = NULL;
@@ -1069,17 +1082,18 @@
{ "no-empty-lists", 0, NULL, 0 },
{ "tab", 1, NULL, 0 },
{ "no-hash-bang", 0, NULL, 0 },
- { "dump", 1, NULL, 'D' },
- { "udump", 1, NULL, 'U' },
+ { "debug", 1, NULL, 0 },
+ { "dump", 1, NULL, 0 },
+ { "udump", 1, NULL, 0 },
{ "ddump", 1, NULL, 0 },
- { "xdump", 1, NULL, 'X' },
+ { "xdump", 1, NULL, 0 },
{ "list-passes", 0, NULL, 0 },
{ "dont-fail", 0, NULL, 0 },
{ "no-xml-attrs", 0, NULL, 0 },
{ NULL, 0, NULL, 0 }
};
- c = getopt_long (argc, argv, "hVvcC:O:o:D:U:X:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVvcC:O:o:", long_options, &option_index);
if (c == -1) break; /* Exit from `while (1)' loop. */
@@ -1148,33 +1162,6 @@
goto failure;
break;
- case 'D': /* Dump input as PHP (although potentially with
gotos and labels) after the pass named 'passname'. */
-
- if (update_multiple_arg_temp(&dump_list,
- &(local_args_info.dump_given), optarg, 0, 0, ARG_STRING,
- "dump", 'D',
- additional_error))
- goto failure;
-
- break;
- case 'U': /* Dump input as runnable PHP after the pass
named 'passname'. */
-
- if (update_multiple_arg_temp(&udump_list,
- &(local_args_info.udump_given), optarg, 0, 0, ARG_STRING,
- "udump", 'U',
- additional_error))
- goto failure;
-
- break;
- case 'X': /* Dump input as XML after the pass
named 'passname'. */
-
- if (update_multiple_arg_temp(&xdump_list,
- &(local_args_info.xdump_given), optarg, 0, 0, ARG_STRING,
- "xdump", 'X',
- additional_error))
- goto failure;
-
- break;
case 0: /* Long option with no short option */
if (strcmp (long_options[option_index].name, "full-help") ==
0) {
@@ -1393,6 +1380,39 @@
goto failure;
}
+ /* Print debugging information for the pass named 'passname.
*/
+ else if (strcmp (long_options[option_index].name, "debug")
== 0)
+ {
+
+ if (update_multiple_arg_temp(&debug_list,
+ &(local_args_info.debug_given), optarg, 0, 0, ARG_STRING,
+ "debug", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Dump input as PHP (although potentially with gotos and
labels) after the pass named 'passname'. */
+ else if (strcmp (long_options[option_index].name, "dump") == 0)
+ {
+
+ if (update_multiple_arg_temp(&dump_list,
+ &(local_args_info.dump_given), optarg, 0, 0, ARG_STRING,
+ "dump", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Dump input as runnable PHP after the pass
named 'passname'. */
+ else if (strcmp (long_options[option_index].name, "udump")
== 0)
+ {
+
+ if (update_multiple_arg_temp(&udump_list,
+ &(local_args_info.udump_given), optarg, 0, 0, ARG_STRING,
+ "udump", '-',
+ additional_error))
+ goto failure;
+
+ }
/* Dump input as DOT after the pass named 'passname'. */
else if (strcmp (long_options[option_index].name, "ddump")
== 0)
{
@@ -1404,6 +1424,17 @@
goto failure;
}
+ /* Dump input as XML after the pass named 'passname'. */
+ else if (strcmp (long_options[option_index].name, "xdump")
== 0)
+ {
+
+ if (update_multiple_arg_temp(&xdump_list,
+ &(local_args_info.xdump_given), optarg, 0, 0, ARG_STRING,
+ "xdump", '-',
+ additional_error))
+ goto failure;
+
+ }
/* List the passes to be run. */
else if (strcmp
(long_options[option_index].name, "list-passes") == 0)
{
@@ -1465,6 +1496,10 @@
&(args_info->c_option_orig), args_info->c_option_given,
local_args_info.c_option_given, 0 ,
ARG_STRING, c_option_list);
+ update_multiple_arg((void *)&(args_info->debug_arg),
+ &(args_info->debug_orig), args_info->debug_given,
+ local_args_info.debug_given, 0 ,
+ ARG_STRING, debug_list);
update_multiple_arg((void *)&(args_info->dump_arg),
&(args_info->dump_orig), args_info->dump_given,
local_args_info.dump_given, 0 ,
@@ -1488,6 +1523,8 @@
local_args_info.r_option_given = 0;
args_info->c_option_given += local_args_info.c_option_given;
local_args_info.c_option_given = 0;
+ args_info->debug_given += local_args_info.debug_given;
+ local_args_info.debug_given = 0;
args_info->dump_given += local_args_info.dump_given;
local_args_info.dump_given = 0;
args_info->udump_given += local_args_info.udump_given;
@@ -1537,6 +1574,7 @@
free_list (run_list, 1 );
free_list (r_option_list, 1 );
free_list (c_option_list, 1 );
+ free_list (debug_list, 1 );
free_list (dump_list, 1 );
free_list (udump_list, 1 );
free_list (ddump_list, 1 );
Modified: trunk/src/generated/cmdline.h
==============================================================================
--- trunk/src/generated/cmdline.h (original)
+++ trunk/src/generated/cmdline.h Wed Apr 2 14:26:03 2008
@@ -94,6 +94,11 @@
const char *tab_help; /**< @brief String to use for tabs while
unparsing help description. */
int no_hash_bang_flag; /**< @brief Do not output any #! lines
(default=off). */
const char *no_hash_bang_help; /**< @brief Do not output any #!
lines help description. */
+ char ** debug_arg; /**< @brief Print debugging information for the
pass named 'passname. */
+ char ** debug_orig; /**< @brief Print debugging information for the
pass named 'passname original value given at command line. */
+ int debug_min; /**< @brief Print debugging information for the pass
named 'passname's minimum occurreces */
+ int debug_max; /**< @brief Print debugging information for the pass
named 'passname's maximum occurreces */
+ const char *debug_help; /**< @brief Print debugging information for
the pass named 'passname help description. */
char ** dump_arg; /**< @brief Dump input as PHP (although
potentially with gotos and labels) after the pass named 'passname'. */
char ** dump_orig; /**< @brief Dump input as PHP (although
potentially with gotos and labels) after the pass named 'passname'
original value given at command line. */
int dump_min; /**< @brief Dump input as PHP (although potentially
with gotos and labels) after the pass named 'passname''s minimum
occurreces */
@@ -146,6 +151,7 @@
unsigned int no_empty_lists_given ; /**< @brief Whether
no-empty-lists was given. */
unsigned int tab_given ; /**< @brief Whether tab was given. */
unsigned int no_hash_bang_given ; /**< @brief Whether no-hash-bang
was given. */
+ unsigned int debug_given ; /**< @brief Whether debug was given. */
unsigned int dump_given ; /**< @brief Whether dump was given. */
unsigned int udump_given ; /**< @brief Whether udump was given. */
unsigned int ddump_given ; /**< @brief Whether ddump was given. */
Modified: trunk/src/generated_src/phc.ggo
==============================================================================
--- trunk/src/generated_src/phc.ggo (original)
+++ trunk/src/generated_src/phc.ggo Wed Apr 2 14:26:03 2008
@@ -31,10 +31,11 @@
option "no-hash-bang" - "Do not output any #! lines" flag off
section "DEBUGGING PHC"
-option "dump" D "Dump input as PHP (although potentially with gotos
and labels) after the pass named 'passname'" string typestr="passname"
multiple hidden optional
-option "udump" U "Dump input as runnable PHP after the pass
named 'passname'" string typestr="passname" multiple hidden optional
+option "debug" - "Print debugging information for the pass
named 'passname" string typestr="passname" multiple hidden optional
+option "dump" - "Dump input as PHP (although potentially with gotos
and labels) after the pass named 'passname'" string typestr="passname"
multiple hidden optional
+option "udump" - "Dump input as runnable PHP after the pass
named 'passname'" string typestr="passname" multiple hidden optional
option "ddump" - "Dump input as DOT after the pass named 'passname'"
string typestr="passname" multiple hidden optional
-option "xdump" X "Dump input as XML after the pass named 'passname'"
string typestr="passname" multiple hidden optional
+option "xdump" - "Dump input as XML after the pass named 'passname'"
string typestr="passname" multiple hidden optional
option "list-passes" - "List the passes to be run" flag off hidden
option "dont-fail" - "Dont fail on error (after parsing)" flag off hidden
option "no-xml-attrs" - "When dumping XML, omit node attributes" flag
off hidden
Modified: trunk/src/pass_manager/Pass_manager.cpp
==============================================================================
--- trunk/src/pass_manager/Pass_manager.cpp (original)
+++ trunk/src/pass_manager/Pass_manager.cpp Wed Apr 2 14:26:03 2008
@@ -288,6 +288,20 @@
}
}
+void Pass_manager::maybe_enable_debug (Pass* pass)
+{
+ disable_cdebug ();
+
+ String* name = pass->name;
+ for (unsigned int i = 0; i < args_info->debug_given; i++)
+ {
+ if (*name == args_info->debug_arg [i])
+ {
+ enable_cdebug ();
+ }
+ }
+}
+
void Pass_manager::dump (IR* in, Pass* pass)
{
String* name = pass->name;
@@ -379,6 +393,8 @@
if (args_info->verbose_flag && dump)
cout << "Running pass: " << *pass->name << endl;
+
+ maybe_enable_debug (pass);
pass->run_pass (in, this);
if (dump)
Modified: trunk/src/pass_manager/Pass_manager.h
==============================================================================
--- trunk/src/pass_manager/Pass_manager.h (original)
+++ trunk/src/pass_manager/Pass_manager.h Wed Apr 2 14:26:03 2008
@@ -81,6 +81,7 @@
void list_passes ();
void dump (IR* in, Pass* pass);
+ void maybe_enable_debug (Pass* pass);
protected:
List<Pass*>* ast_queue;
Modified: trunk/src/process_ir/debug.cpp
==============================================================================
--- trunk/src/process_ir/debug.cpp (original)
+++ trunk/src/process_ir/debug.cpp Wed Apr 2 14:26:03 2008
@@ -16,55 +16,76 @@
void debug (AST::Node *in)
{
- static AST_unparser *pup = new AST_unparser (cerr);
+ static AST_unparser *pup = new AST_unparser (cdebug);
in->visit (pup);
}
void xdebug (AST::Node* in)
{
- AST_XML_unparser *xup = new AST_XML_unparser (cerr, false);
+ AST_XML_unparser *xup = new AST_XML_unparser (cdebug, false);
in->visit (xup);
}
void xadebug (AST::Node* in)
{
- AST_XML_unparser *xup = new AST_XML_unparser (cerr, true);
+ AST_XML_unparser *xup = new AST_XML_unparser (cdebug, true);
in->visit (xup);
}
void debug (HIR::Node *in)
{
- static HIR_unparser *pup = new HIR_unparser (cerr);
+ static HIR_unparser *pup = new HIR_unparser (cdebug);
in->visit (pup);
}
void xdebug (HIR::Node* in)
{
- HIR_XML_unparser *xup = new HIR_XML_unparser (cerr, false);
+ HIR_XML_unparser *xup = new HIR_XML_unparser (cdebug, false);
in->visit (xup);
}
void xadebug (HIR::Node* in)
{
- HIR_XML_unparser *xup = new HIR_XML_unparser (cerr, true);
+ HIR_XML_unparser *xup = new HIR_XML_unparser (cdebug, true);
in->visit (xup);
}
void debug (MIR::Node *in)
{
- static MIR_unparser *pup = new MIR_unparser (cerr);
+ static MIR_unparser *pup = new MIR_unparser (cdebug);
in->visit (pup);
}
void xdebug (MIR::Node* in)
{
- MIR_XML_unparser *xup = new MIR_XML_unparser (cerr, false);
+ MIR_XML_unparser *xup = new MIR_XML_unparser (cdebug, false);
in->visit (xup);
}
void xadebug (MIR::Node* in)
{
- MIR_XML_unparser *xup = new MIR_XML_unparser (cerr, true);
+ MIR_XML_unparser *xup = new MIR_XML_unparser (cdebug, true);
in->visit (xup);
}
+
+// set badbit. This wont print anything into the stream.
+ostream cdebug_buffer (0);
+
+// If we initialize to cdebug_buffer, then we won't be able to turn it
off once
+// it's on.
+ostringstream initializer;
+ostream& cdebug = initializer;
+
+void enable_cdebug ()
+{
+ // ceer prints input to console
+ cdebug.rdbuf (cerr.rdbuf());
+}
+
+void disable_cdebug ()
+{
+ // cdebug_buffer ignores all input
+ cdebug.rdbuf (cdebug_buffer.rdbuf());
+}
+
Modified: trunk/src/process_ir/debug.h
==============================================================================
--- trunk/src/process_ir/debug.h (original)
+++ trunk/src/process_ir/debug.h Wed Apr 2 14:26:03 2008
@@ -16,6 +16,7 @@
#include "AST.h"
#include "HIR.h"
#include "MIR.h"
+#include <ostream>
/* Dump the XML for anynode to stderr. A global function. */
// these are split so they're easy to call from the debugger
@@ -30,5 +31,9 @@
void debug (MIR::Node* in);
void xdebug (MIR::Node* in);
void xadebug (MIR::Node* in);
+
+extern ostream& cdebug;
+void enable_cdebug ();
+void disable_cdebug ();
#endif // PHC_DEBUG
More information about the phc-internals
mailing list