[macruby-changes] [2121] MacRuby/branches/experimental/compiler.cpp

source_changes at macosforge.org source_changes at macosforge.org
Fri Jul 31 05:20:02 PDT 2009


Revision: 2121
          http://trac.macosforge.org/projects/ruby/changeset/2121
Author:   vincent.isambart at gmail.com
Date:     2009-07-31 05:20:00 -0700 (Fri, 31 Jul 2009)
Log Message:
-----------
Fixes the bug reported in
http://lists.macosforge.org/pipermail/macruby-devel/2009-July/002112.html
Notes:
- rake spec:ci was not run successfully because it crashes on my
  computer (but it's not related to my change)
- this change is not very DRY but C++ is such a nice language that when
  I tried to do the same thing DRY the code was much longer and more
complicated...
- we need a tool to do automatic testing of the AOT compiler

Modified Paths:
--------------
    MacRuby/branches/experimental/compiler.cpp

Modified: MacRuby/branches/experimental/compiler.cpp
===================================================================
--- MacRuby/branches/experimental/compiler.cpp	2009-07-31 06:48:25 UTC (rev 2120)
+++ MacRuby/branches/experimental/compiler.cpp	2009-07-31 12:20:00 UTC (rev 2121)
@@ -2895,8 +2895,6 @@
 			    (module->getOrInsertFunction("rb_vm_keep_vars", ft));
 		    }
 
-		    std::vector<Value *> params;
-
 		    // searches all ReturnInst in the function we just created and add before
 		    // a call to the function to save the local variables if necessary
 		    // (we can't do this before finishing compiling the whole function
@@ -2908,29 +2906,28 @@
 			     inst_it != block_it->end();
 			     ++inst_it) {
 			    if (dyn_cast<ReturnInst>(inst_it)) {
-				if (params.empty()) {
-				    params.push_back(NULL);
-				    params.push_back(NULL);
-				    int vars_count = 0;
-				    for (std::map<ID, Value *>::iterator iter = lvars.begin();
-					    iter != lvars.end(); ++iter) {
-					ID name = iter->first;
-					Value *slot = iter->second;
-					if (std::find(dvars.begin(), dvars.end(), name) == dvars.end()) {
-					    Value *id_val = compile_id(name);
-					    if (Instruction::classof(id_val)) {
-						cast<Instruction>(id_val)->moveBefore(inst_it);
-					    }
-					    params.push_back(id_val);
-					    params.push_back(slot);
-					    vars_count++;
+				// params must be filled each time because in AOT mode it contains instructions
+				std::vector<Value *> params;
+
+				params.push_back(new LoadInst(current_var_uses, "", inst_it));
+				params.push_back(NULL);
+				int vars_count = 0;
+				for (std::map<ID, Value *>::iterator iter = lvars.begin();
+					iter != lvars.end(); ++iter) {
+				    ID name = iter->first;
+				    Value *slot = iter->second;
+				    if (std::find(dvars.begin(), dvars.end(), name) == dvars.end()) {
+					Value *id_val = compile_id(name);
+					if (Instruction::classof(id_val)) {
+					    cast<Instruction>(id_val)->moveBefore(inst_it);
 					}
+					params.push_back(id_val);
+					params.push_back(slot);
+					vars_count++;
 				    }
-				    params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
 				}
+				params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
 
-				params[0] = new LoadInst(current_var_uses, "", inst_it);
-
 				// TODO: only call the function if current_use is not NULL
 				CallInst::Create(keepVarsFunc, params.begin(), params.end(), "",
 					inst_it);
@@ -2942,7 +2939,6 @@
 			rescue_bb->eraseFromParent();
 		    }
 		    else {
-			assert(params.size() > 0);
 			bb = new_rescue_bb;
 			compile_landing_pad_header();
 
@@ -2953,7 +2949,25 @@
 			Value *notNullCond = new ICmpInst(ICmpInst::ICMP_NE, usesVal, compile_const_pointer(NULL), "", bb);
 			BranchInst::Create(notNullBB, mergeBB, notNullCond, bb);
 			bb = notNullBB;
-			params[0] = new LoadInst(current_var_uses, "", bb);
+
+			// params must be filled again because in AOT mode it contains instructions
+			std::vector<Value *> params;
+			params.push_back(new LoadInst(current_var_uses, "", bb));
+			params.push_back(NULL);
+			int vars_count = 0;
+			for (std::map<ID, Value *>::iterator iter = lvars.begin();
+				iter != lvars.end(); ++iter) {
+			    ID name = iter->first;
+			    Value *slot = iter->second;
+			    if (std::find(dvars.begin(), dvars.end(), name) == dvars.end()) {
+				Value *id_val = compile_id(name);
+				params.push_back(id_val);
+				params.push_back(slot);
+				vars_count++;
+			    }
+			}
+			params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
+
 			CallInst::Create(keepVarsFunc, params.begin(), params.end(), "", bb);
 			BranchInst::Create(mergeBB, bb);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090731/a99ec249/attachment.html>


More information about the macruby-changes mailing list