]> sourceware.org Git - systemtap.git/commitdiff
2005-12-01 Frank Ch. Eigler <fche@elastic.org>
authorfche <fche>
Fri, 2 Dec 2005 03:21:00 +0000 (03:21 +0000)
committerfche <fche>
Fri, 2 Dec 2005 03:21:00 +0000 (03:21 +0000)
PR 1944 improved hack.
* translator.cxx (c_tmpcounter::visit_block): New routine, allows
overlay of sequential statements' temporaries within context.

ChangeLog
translate.cxx

index 2fe5bebf895e3def53148b6d31670af2dafbf125..096f61c9f9c50d1a8cba1472d5ff14cbf197133f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-01  Frank Ch. Eigler  <fche@elastic.org>
+
+       PR 1944 improved hack.
+       * translator.cxx (c_tmpcounter::visit_block): New routine, allows
+       overlay of sequential statements' temporaries within context.
+
 2005-12-01  Frank Ch. Eigler  <fche@redhat.com>
 
        PR 1944 quick hack.
index a55d48a886c85bbb8eee6dc289ae7bc9769def3b..1f87f70c88aaa0071a210a1b0662edfa8c4d903e 100644 (file)
@@ -171,6 +171,7 @@ struct c_tmpcounter:
     parent->tmpvar_counter = 0;
   }
 
+  void visit_block (block *s);
   void visit_for_loop (for_loop* s);
   void visit_foreach_loop (foreach_loop* s);
   // void visit_return_statement (return_statement* s);
@@ -939,8 +940,8 @@ c_unparser::emit_module_init ()
   o->newline() << "if (sizeof (struct context) <= 131072)";
   o->newline(1) << "contexts = alloc_percpu (struct context);";
   o->newline(-1) << "if (contexts == NULL) {";
-  o->newline() << "_stp_error (\"percpu context (size %lu) allocation failed\", sizeof (struct context));";
-  o->newline(1) << "rc = -ENOMEM;";
+  o->newline(1) << "_stp_error (\"percpu context (size %lu) allocation failed\", sizeof (struct context));";
+  o->newline() << "rc = -ENOMEM;";
   o->newline() << "goto out;";
   o->newline(-1) << "}";
 
@@ -1724,6 +1725,25 @@ c_unparser::visit_if_statement (if_statement *s)
 }
 
 
+void
+c_tmpcounter::visit_block (block *s)
+{
+  // Key insight: individual statements of a block can reuse
+  // temporary variable slots, since temporaries don't survive
+  // statement boundaries.  So we use gcc's anonymous union/struct
+  // facility to explicitly overlay the temporaries.
+  parent->o->newline() << "union {";
+  parent->o->indent(1);
+  for (unsigned i=0; i<s->statements.size(); i++)
+    {
+      parent->o->newline() << "struct {";
+      parent->o->indent(1);
+      s->statements[i]->visit (this);
+      parent->o->newline(-1) << "};";
+    }
+  parent->o->newline(-1) << "};";
+}
+
 void
 c_tmpcounter::visit_for_loop (for_loop *s)
 {
This page took 0.048312 seconds and 5 git commands to generate.