[macruby-changes] [2397] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 27 00:49:00 PDT 2009


Revision: 2397
          http://trac.macosforge.org/projects/ruby/changeset/2397
Author:   lsansonetti at apple.com
Date:     2009-08-27 00:48:56 -0700 (Thu, 27 Aug 2009)
Log Message:
-----------
added support for AOT compilation of literal regexs

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/compiler.h

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2009-08-27 02:17:28 UTC (rev 2396)
+++ MacRuby/trunk/compiler.cpp	2009-08-27 07:48:56 UTC (rev 2397)
@@ -11,6 +11,7 @@
 #include "llvm.h"
 #include "ruby/ruby.h"
 #include "ruby/node.h"
+#include "ruby/re.h"
 #include "id.h"
 #include "vm.h"
 #include "compiler.h"
@@ -161,6 +162,7 @@
 {
     cObject_gvar = NULL;
     name2symFunc = NULL;
+    newRegexp2Func = NULL;
 }
 
 inline SEL
@@ -5078,6 +5080,44 @@
 	GlobalVariable *gvar = i->second;
 
 	switch (TYPE(val)) {
+	    case T_REGEXP:
+		{
+		    if (newRegexp2Func == NULL) {
+			newRegexp2Func =
+			    cast<Function>(module->getOrInsertFunction(
+					"rb_reg_new",
+					RubyObjTy, PtrTy, Type::Int32Ty,
+					Type::Int32Ty, NULL));
+		    }
+
+		    struct RRegexp *re = (struct RRegexp *)val;
+
+		    GlobalVariable *rename_gvar =
+			compile_const_global_string(re->str, re->len);
+
+		    std::vector<Value *> idxs;
+		    idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
+		    idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
+		    Instruction *load = GetElementPtrInst::Create(rename_gvar,
+			    idxs.begin(), idxs.end(), "");
+
+		    std::vector<Value *> params;
+		    params.push_back(load);
+		    params.push_back(ConstantInt::get(Type::Int32Ty, re->len));
+		    params.push_back(ConstantInt::get(Type::Int32Ty,
+				re->ptr->options));
+
+		    Instruction *call = CallInst::Create(newRegexp2Func,
+			    params.begin(), params.end(), "");
+
+		    Instruction *assign = new StoreInst(call, gvar, "");
+
+		    list.insert(list.begin(), assign);
+		    list.insert(list.begin(), call);
+		    list.insert(list.begin(), load);
+		}
+		break;
+
 	    case T_SYMBOL:
 		{
 		    if (name2symFunc == NULL) {
@@ -5088,7 +5128,7 @@
 		    }
 
 		    const char *symname = rb_id2name(SYM2ID(val));
-		    			 
+
 		    GlobalVariable *symname_gvar =
 			compile_const_global_string(symname);
 

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2009-08-27 02:17:28 UTC (rev 2396)
+++ MacRuby/trunk/compiler.h	2009-08-27 07:48:56 UTC (rev 2397)
@@ -342,6 +342,7 @@
 	GlobalVariable *cObject_gvar;
 
 	Function *name2symFunc;
+	Function *newRegexp2Func;
 
 	Value *compile_mcache(SEL sel, bool super);
 	Value *compile_ccache(ID id);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090827/c441ba81/attachment-0001.html>


More information about the macruby-changes mailing list