[phc-internals] [phc commit] r1067 - in trunk/src: . ast_to_hir codegen pass_manager process_ast process_mir

codesite-noreply at google.com codesite-noreply at google.com
Tue Mar 4 01:58:29 GMT 2008


Author: paul.biggar
Date: Mon Mar  3 17:57:33 2008
New Revision: 1067

Modified:
   trunk/src/ast_to_hir/AST_shredder.cpp
   trunk/src/codegen/Compile_C.cpp
   trunk/src/codegen/Generate_C.cpp
   trunk/src/codegen/Lift_functions_and_classes.h
   trunk/src/codegen/Prune_symbol_table.cpp
   trunk/src/pass_manager/Fake_pass.h
   trunk/src/pass_manager/Pass_manager.cpp
   trunk/src/pass_manager/Pass_manager.h
   trunk/src/pass_manager/Transform_pass.h
   trunk/src/pass_manager/Visitor_pass.h
   trunk/src/phc.cpp
   trunk/src/process_ast/Invalid_check.cpp
   trunk/src/process_ast/Invalid_check.h
   trunk/src/process_ast/Pretty_print.h
   trunk/src/process_ast/Process_includes.cpp
   trunk/src/process_mir/Obfuscate.h

Log:
I spent a while looking through each pass to understand the 
dependencies and interactions. This seemed like a good time to add 
descriptions to each of the passes.


Modified: trunk/src/ast_to_hir/AST_shredder.cpp
==============================================================================
--- trunk/src/ast_to_hir/AST_shredder.cpp	(original)
+++ trunk/src/ast_to_hir/AST_shredder.cpp	Mon Mar  3 17:57:33 2008
@@ -181,7 +181,7 @@
 /*
  * foreach
  */
-
+// TODO remove
 Expr* Shredder::post_foreach_has_key (Foreach_has_key* in)
 {
 	return eval(in);

Modified: trunk/src/codegen/Compile_C.cpp
==============================================================================
--- trunk/src/codegen/Compile_C.cpp	(original)
+++ trunk/src/codegen/Compile_C.cpp	Mon Mar  3 17:57:33 2008
@@ -18,7 +18,8 @@
 Compile_C::Compile_C (stringstream& os)
 : os(os)
 {
-	this->name = new String ("compile_c");
+	this->name = new String ("compile-c");
+	this->description = new String ("Compile C code into an executable");
 }

 stringstream& new_arg (vector<stringstream*> &args)

Modified: trunk/src/codegen/Generate_C.cpp
==============================================================================
--- trunk/src/codegen/Generate_C.cpp	(original)
+++ trunk/src/codegen/Generate_C.cpp	Mon Mar  3 17:57:33 2008
@@ -2395,4 +2395,5 @@
 {
 	methods = new List<Signature*>;
 	name = new String ("generate-c");
+	description = new String ("Generate C code from the MIR");
 }

Modified: trunk/src/codegen/Lift_functions_and_classes.h
==============================================================================
--- trunk/src/codegen/Lift_functions_and_classes.h	(original)
+++ trunk/src/codegen/Lift_functions_and_classes.h	Mon Mar  3 17:57:33 2008
@@ -18,6 +18,7 @@
 	Lift_functions_and_classes ()
 	{
 		this->name = new String ("lfc");
+		this->description = new String ("Move statements from global scope 
into __MAIN__ method");
 	}

 	// TODO this should be done on HIR, I think

Modified: trunk/src/codegen/Prune_symbol_table.cpp
==============================================================================
--- trunk/src/codegen/Prune_symbol_table.cpp	(original)
+++ trunk/src/codegen/Prune_symbol_table.cpp	Mon Mar  3 17:57:33 2008
@@ -30,6 +30,7 @@
 Prune_symbol_table::Prune_symbol_table ()
 :  prune (true)
 {
+
 }

 // TODO we cant compile nested functions anyway, but this needs to be

Modified: trunk/src/pass_manager/Fake_pass.h
==============================================================================
--- trunk/src/pass_manager/Fake_pass.h	(original)
+++ trunk/src/pass_manager/Fake_pass.h	Mon Mar  3 17:57:33 2008
@@ -17,9 +17,10 @@
 class Fake_pass : public Pass
 {
 	public:
-	Fake_pass (const char* name)
+	Fake_pass (const char* name, const char* description)
 	{
 		this->name = new String (name);
+		this->description = new String (description);
 	}

 	void run (IR*, Pass_manager*) {}

Modified: trunk/src/pass_manager/Pass_manager.cpp
==============================================================================
--- trunk/src/pass_manager/Pass_manager.cpp	(original)
+++ trunk/src/pass_manager/Pass_manager.cpp	Mon Mar  3 17:57:33 2008
@@ -38,15 +38,15 @@
 	queues = new List <List<Pass*>* > (ast_queue, hir_queue, mir_queue);
 }

-void Pass_manager::add_ast_visitor (AST::Visitor* visitor, const char* name)
+void Pass_manager::add_ast_visitor (AST::Visitor* visitor, const char* 
name, const char* description)
 {
-	Pass* pass = new Visitor_pass (visitor, new String (name));
+	Pass* pass = new Visitor_pass (visitor, new String (name), new String (description));
 	add_pass (pass, ast_queue);
 }

-void Pass_manager::add_ast_transform (AST::Transform* transform, const 
char* name)
+void Pass_manager::add_ast_transform (AST::Transform* transform, const 
char* name, const char* description)
 {
-	Pass* pass = new Transform_pass (transform, new String (name));
+	Pass* pass = new Transform_pass (transform, new String (name), new 
String (description));
 	add_pass (pass, ast_queue);
 }

@@ -55,15 +55,15 @@
 	add_pass (pass, ast_queue);
 }

-void Pass_manager::add_hir_visitor (HIR::Visitor* visitor, const char* name)
+void Pass_manager::add_hir_visitor (HIR::Visitor* visitor, const char* 
name, const char* description)
 {
-	Pass* pass = new Visitor_pass (visitor, new String (name));
+	Pass* pass = new Visitor_pass (visitor, new String (name), new String (description));
 	add_pass (pass, hir_queue);
 }

-void Pass_manager::add_hir_transform (HIR::Transform* transform, const 
char* name)
+void Pass_manager::add_hir_transform (HIR::Transform* transform, const 
char* name, const char* description)
 {
-	Pass* pass = new Transform_pass (transform, new String (name));
+	Pass* pass = new Transform_pass (transform, new String (name), new 
String (description));
 	add_pass (pass, hir_queue);
 }

@@ -74,15 +74,15 @@



-void Pass_manager::add_mir_visitor (MIR::Visitor* visitor, const char* name)
+void Pass_manager::add_mir_visitor (MIR::Visitor* visitor, const char* 
name, const char* description)
 {
-	Pass* pass = new Visitor_pass (visitor, new String (name));
+	Pass* pass = new Visitor_pass (visitor, new String (name), new String (description));
 	add_pass (pass, mir_queue);
 }

-void Pass_manager::add_mir_transform (MIR::Transform* transform, const 
char* name)
+void Pass_manager::add_mir_transform (MIR::Transform* transform, const 
char* name, const char* description)
 {
-	Pass* pass = new Transform_pass (transform, new String (name));
+	Pass* pass = new Transform_pass (transform, new String (name), new 
String (description));
 	add_pass (pass, mir_queue);
 }

@@ -210,6 +210,52 @@
 	phc_error ("No pass with name %s was found", name);
 }

+// TODO this could be much nicer, but its not important
+/* Format the string so that each line in LENGTH long, and all lines 
except the
+ * first have WHITESPACE of leading whitespace */
+String* format (String* str, int prefix_length)
+{
+	const int LINE_LENGTH = 80;
+	assert (prefix_length < LINE_LENGTH);
+	stringstream result;
+	stringstream line;
+	stringstream word;
+
+	string leading_whitespace (prefix_length, ' ');
+
+
+	for (unsigned int i = 0; i < str->size (); i++)
+	{
+		// add the letter to the word
+		word << (*str)[i];
+
+		// end of word
+		if ((*str)[i] == ' ')
+		{
+			line << word.str();
+			word.str(""); // erase
+		}
+		else
+		{
+			// end of line?
+			if (line.str().size() + word.str().size() > (unsigned 
int)(LINE_LENGTH - prefix_length))
+			{
+				result << line.str() << "\n";
+				line.str (""); // erase
+				line << leading_whitespace;
+
+				// only use the prefix on the first line
+				prefix_length = 0;
+			}
+		}
+	}
+
+	// flush the remainder of the string
+	result << line.str () << word.str ();
+
+	return new String (result.str ());
+}
+
 void Pass_manager::list_passes ()
 {
 	cout << "Passes:\n";
@@ -219,8 +265,9 @@
 			const char* name = "AST";
 			if ((*q) == hir_queue) name = "HIR";
 			if ((*q) == mir_queue) name = "MIR";
-			String* desc = (*p)->description;
-			printf ("%-30s\t(%-8s - %s)\t%s\n",
+			String* desc = format ((*p)->description, 39);
+
+			printf ("%-15s    (%-8s - %3s)    %s\n",
 					(*p)->name->c_str (),
 					(*p)->is_enabled (this) ? "enabled" : "disabled",
 					name,

Modified: trunk/src/pass_manager/Pass_manager.h
==============================================================================
--- trunk/src/pass_manager/Pass_manager.h	(original)
+++ trunk/src/pass_manager/Pass_manager.h	Mon Mar  3 17:57:33 2008
@@ -36,22 +36,22 @@

 	// Add AST passes
 	void add_ast_pass (Pass* pass);
-	void add_ast_visitor (AST::Visitor* visitor, const char* name);
-	void add_ast_transform (AST::Transform* transform, const char* name);
+	void add_ast_visitor (AST::Visitor* visitor, const char* name, const 
char* description);
+	void add_ast_transform (AST::Transform* transform, const char* name, 
const char* description);
 	void add_after_each_ast_pass (Pass* pass);
 	bool is_ast_pass (String* name);

 	// Add HIR passes
 	void add_hir_pass (Pass* pass);
-	void add_hir_visitor (HIR::Visitor* visitor, const char* name);
-	void add_hir_transform (HIR::Transform* transform, const char* name);
+	void add_hir_visitor (HIR::Visitor* visitor, const char* name, const 
char* description);
+	void add_hir_transform (HIR::Transform* transform, const char* name, 
const char* description);
 	void add_after_each_hir_pass (Pass* pass);
 	bool is_hir_pass (String* name);

 	// Add MIR passes
 	void add_mir_pass (Pass* pass);
-	void add_mir_visitor (MIR::Visitor* visitor, const char* name);
-	void add_mir_transform (MIR::Transform* transform, const char* name);
+	void add_mir_visitor (MIR::Visitor* visitor, const char* name, const 
char* description);
+	void add_mir_transform (MIR::Transform* transform, const char* name, 
const char* description);
 	void add_after_each_mir_pass (Pass* pass);
 	bool is_mir_pass (String* name);


Modified: trunk/src/pass_manager/Transform_pass.h
==============================================================================
--- trunk/src/pass_manager/Transform_pass.h	(original)
+++ trunk/src/pass_manager/Transform_pass.h	Mon Mar  3 17:57:33 2008
@@ -19,25 +19,28 @@

 public:

-	Transform_pass (AST::Transform* t, String* name)
+	Transform_pass (AST::Transform* t, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_transform = t;
 		hir_transform = NULL;
 		mir_transform = NULL;
 	}

-	Transform_pass (MIR::Transform* t, String* name)
+	Transform_pass (MIR::Transform* t, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_transform = NULL;
 		hir_transform = NULL;
 		mir_transform = t;
 	}

-	Transform_pass (HIR::Transform* t, String* name)
+	Transform_pass (HIR::Transform* t, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_transform = NULL;
 		hir_transform = t;
 		mir_transform = NULL;

Modified: trunk/src/pass_manager/Visitor_pass.h
==============================================================================
--- trunk/src/pass_manager/Visitor_pass.h	(original)
+++ trunk/src/pass_manager/Visitor_pass.h	Mon Mar  3 17:57:33 2008
@@ -20,25 +20,28 @@

 public:

-	Visitor_pass (AST::Visitor* v, String* name)
+	Visitor_pass (AST::Visitor* v, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_visitor = v;
 		hir_visitor = NULL;
 		mir_visitor = NULL;
 	}

-	Visitor_pass (HIR::Visitor* v, String* name)
+	Visitor_pass (HIR::Visitor* v, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_visitor = NULL;
 		hir_visitor = v;
 		mir_visitor = NULL;
 	}

-	Visitor_pass (MIR::Visitor* v, String* name)
+	Visitor_pass (MIR::Visitor* v, String* name, String* description)
 	{
 		this->name = name;
+		this->description = description;
 		ast_visitor = NULL;
 		hir_visitor = NULL;
 		mir_visitor = v;

Modified: trunk/src/phc.cpp
==============================================================================
--- trunk/src/phc.cpp	(original)
+++ trunk/src/phc.cpp	Mon Mar  3 17:57:33 2008
@@ -115,55 +115,55 @@

 	// process_ast passes
 	pm->add_ast_pass (new Invalid_check ());
-	pm->add_ast_pass (new Fake_pass ("ast"));
+	pm->add_ast_pass (new Fake_pass ("ast", "Abstract Syntax Tree - a 
representation of the PHP program, as written"));
 	pm->add_ast_pass (new Process_includes (false, new String ("ast"), pm, "incl1"));
 	pm->add_ast_pass (new Pretty_print ());

 	// Begin lowering to hir
-	pm->add_ast_visitor (new Strip_unparser_attributes (), "sua");
-	pm->add_ast_visitor (new Note_top_level_declarations (), "ntld");
+	pm->add_ast_visitor (new Strip_unparser_attributes (), "sua", "Remove 
the attributes used to pretty-print source code");
+	pm->add_ast_visitor (new Note_top_level_declarations 
(), "ntld", "Make a note of top-level-declarations before the 
information is lost");

 	// Small optimization on the AST
-	pm->add_ast_transform (new Remove_concat_null (), "rcn");
+	pm->add_ast_transform (new Remove_concat_null (), "rcn", "Remove 
concatentations with \"\"");



 	// Make simple statements simpler
 	// these passes could really go to either AST, or HIR.
 	// TODO move these to the end of the AST, just before the HIR
-	pm->add_ast_transform (new Split_multiple_arguments (), "sma");
-	pm->add_ast_transform (new Split_unset_isset (), "sui");
-	pm->add_ast_transform (new Echo_split (), "ecs");
-	pm->add_ast_transform (new Translate_empty (), "empty");
-
-	pm->add_ast_transform (new Early_lower_control_flow (), "elcf"); // AST
-	pm->add_ast_transform (new Lower_expr_flow (), "lef"); // AST
-	pm->add_ast_transform (new Desugar (), "desug"); // AST
-	pm->add_ast_transform (new Pre_post_op_shredder (), "pps"); // AST
-	pm->add_ast_transform (new List_shredder (), "lish"); // AST
-	pm->add_ast_transform (new AST::Shredder (), "ashred"); // AST
-	pm->add_ast_transform (new Tidy_print (), "tidyp"); // AST
-	pm->add_ast_pass (new Fake_pass ("AST-to-HIR"));
-
-
-	pm->add_hir_pass (new Fake_pass ("hir"));
-	pm->add_hir_transform (new Lower_control_flow (), "lcf"); // HIR
-	pm->add_hir_transform (new HIR::Shredder (), "hshred"); // HIR
+	pm->add_ast_transform (new Split_multiple_arguments (), "sma", "Split 
multiple arguments for globals, attributes and static declarations");
+	pm->add_ast_transform (new Split_unset_isset (), "sui", "Split 
unset() and isset() into multiple calls with one argument each");
+	pm->add_ast_transform (new Echo_split (), "ecs", "Split echo() into 
multiple calls with one argument each");
+	pm->add_ast_transform (new Translate_empty (), "empty", "Translate 
calls to empty() into casts");
+
+	pm->add_ast_transform (new Early_lower_control_flow 
(), "elcf", "Early Lower Control Flow - lower for, while, do and switch 
statements"); // AST
+	pm->add_ast_transform (new Lower_expr_flow (), "lef", "Lower 
Expression Flow - Lower ||, && and ?: expressions");
+	pm->add_ast_transform (new Desugar (), "desug", "Desugar");
+	pm->add_ast_transform (new Pre_post_op_shredder (), "pps", "Shred 
pre- and post-ops, removing post-ops");
+	pm->add_ast_transform (new List_shredder (), "lish", "List shredder - 
simplify to array assignments");
+	pm->add_ast_transform (new AST::Shredder (), "ashred", "Shredder - 
turn the AST into three-address-code, replacing complex expressions 
with a temporary variable");
+	pm->add_ast_transform (new Tidy_print (), "tidyp", "Replace calls to 
echo() and print() with printf()");
+	pm->add_ast_pass (new Fake_pass ("AST-to-HIR", "The HIR in AST form"));
+
+
+	pm->add_hir_pass (new Fake_pass ("hir", "High-level Internal 
Representation - the smallest subset of PHP which can represent the 
entire language"));
+	pm->add_hir_transform (new Lower_control_flow (), "lcf", "Lower 
Control Flow - Use gotos in place of loops, ifs, breaks and continues");
+	pm->add_hir_transform (new HIR::Shredder (), "hshred", "HIR Shredder 
- Shred contructs introduced by the compiler into 3-address-code");


 	// process_hir passes
-	pm->add_hir_visitor (new Strip_comments (), "decomment");
+	pm->add_hir_visitor (new Strip_comments (), "decomment", "Remove 
comments"); // TODO move to AST
 	pm->add_hir_pass (new Obfuscate ()); // TODO move to MIR
-	pm->add_hir_pass (new Fake_pass ("HIR-to-MIR"));
+	pm->add_hir_pass (new Fake_pass ("HIR-to-MIR", "The MIR in HIR form"));


 	// codegen passes
 	// Use ss to pass generated code between Generate_C and Compile_C
-	pm->add_mir_pass (new Fake_pass ("mir"));
+	pm->add_mir_pass (new Fake_pass ("mir", "Medium-level Internal 
Representation - simple code with high-level constructs lowered to 
straight-line code."));
 //	pm->add_mir_pass (new Process_includes (true, new String ("mir"), pm, "incl2"));
 	pm->add_mir_pass (new Lift_functions_and_classes ());
-	pm->add_mir_visitor (new Clarify (), "clar");
-	pm->add_mir_visitor (new Prune_symbol_table (), "pst");
+	pm->add_mir_visitor (new Clarify (), "clar", "Clarify - Make implicit 
defintions explicit");
+	pm->add_mir_visitor (new Prune_symbol_table (), "pst", "Prune Symbol 
Table - Note whether a symbol table is required in generated code");
 	stringstream ss;
 	pm->add_mir_pass (new Generate_C (ss));
 	pm->add_mir_pass (new Compile_C (ss));

Modified: trunk/src/process_ast/Invalid_check.cpp
==============================================================================
--- trunk/src/process_ast/Invalid_check.cpp	(original)
+++ trunk/src/process_ast/Invalid_check.cpp	Mon Mar  3 17:57:33 2008
@@ -37,6 +37,14 @@
 			|| dynamic_cast <HIR::Constant*> (in));
 }

+Invalid_check::Invalid_check (bool use_ice)
+: Pass ()
+, use_ice (use_ice)
+{
+	this->name = new String ("check");
+	this->description = new String ("Check for invalid PHP statements");
+}
+


 void Invalid_check::run (IR* in, Pass_manager* pm)

Modified: trunk/src/process_ast/Invalid_check.h
==============================================================================
--- trunk/src/process_ast/Invalid_check.h	(original)
+++ trunk/src/process_ast/Invalid_check.h	Mon Mar  3 17:57:33 2008
@@ -26,11 +26,7 @@

 	// If this is set, use phc_internal_error instead of phc_error
 	bool use_ice; // ice == Internal Compiler Error
-	Invalid_check (bool use_ice = false)
-	: use_ice (use_ice)
-	{
-		this->name = new String ("check");
-	}
+	Invalid_check (bool use_ice = false);

 	// decide the error based on whether USE_ICE is set
 	void error (const char* message, AST::Node* node);

Modified: trunk/src/process_ast/Pretty_print.h
==============================================================================
--- trunk/src/process_ast/Pretty_print.h	(original)
+++ trunk/src/process_ast/Pretty_print.h	Mon Mar  3 17:57:33 2008
@@ -21,6 +21,7 @@
 	Pretty_print ()
 	{
 		this->name = new String ("pretty-print");
+		this->description = new String ("Print the formatted program source");
 	}

 	void run (IR* in, Pass_manager* pm)

Modified: trunk/src/process_ast/Process_includes.cpp
==============================================================================
--- trunk/src/process_ast/Process_includes.cpp	(original)
+++ trunk/src/process_ast/Process_includes.cpp	Mon Mar  3 17:57:33 2008
@@ -174,6 +174,7 @@
   pm (pm)
 {
 	this->name = new String (name);
+	this->description = new String ("Insert included and required files 
into the AST");
 }

 bool Process_includes::pass_is_enabled (Pass_manager* pm)

Modified: trunk/src/process_mir/Obfuscate.h
==============================================================================
--- trunk/src/process_mir/Obfuscate.h	(original)
+++ trunk/src/process_mir/Obfuscate.h	Mon Mar  3 17:57:33 2008
@@ -17,6 +17,7 @@
 	Obfuscate ()
 	{
 		name = new String ("obfuscate");
+		description = new String ("Print program with obfuscated control-flow");
 	}

 	void run (IR* in, Pass_manager* pm)


More information about the phc-internals mailing list