[macruby-changes] [4891] MacRuby/trunk/compiler.cpp

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 5 18:44:43 PDT 2010


Revision: 4891
          http://trac.macosforge.org/projects/ruby/changeset/4891
Author:   lsansonetti at apple.com
Date:     2010-11-05 18:44:41 -0700 (Fri, 05 Nov 2010)
Log Message:
-----------
additional fixes for the C array support, when embedded in C structs

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

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-11-06 01:36:51 UTC (rev 4890)
+++ MacRuby/trunk/compiler.cpp	2010-11-06 01:44:41 UTC (rev 4891)
@@ -5560,8 +5560,11 @@
 		    val,
 		    elem_count_val	
 		};
-		val = CallInst::Create(checkArrayFunc, args, args + 2, "", bb); 	
-		Value *ary = new AllocaInst(elem_type, elem_count_val, "", bb);
+		val = CallInst::Create(checkArrayFunc, args, args + 2, "", bb);
+
+		slot = new BitCastInst(slot, PointerType::getUnqual(elem_type),
+			"", bb);
+
 		for (unsigned i = 0; i < elem_count; i++) {
 		    Value *idx = ConstantInt::get(Int32Ty, i);
 		    Value *args[] = {
@@ -5570,11 +5573,12 @@
 		    };
 		    Value *elem = CallInst::Create(entryArrayFunc,
 			    args, args + 2, "", bb);
-		    Value *slot = GetElementPtrInst::Create(ary, idx, "", bb);
-		    compile_conversion_to_c(elem_c_type, elem, slot);
+		    Value *elem_slot = GetElementPtrInst::Create(slot, idx,
+			    "", bb);
+		    compile_conversion_to_c(elem_c_type, elem, elem_slot);
 		}
 
-		return new BitCastInst(ary, PointerType::getUnqual(ary_type),
+		return new BitCastInst(slot, PointerType::getUnqual(ary_type),
 			"", bb);
 	    }
 	    break;
@@ -5827,15 +5831,25 @@
 			sizeof elem_c_type);
 		const Type *elem_type = convert_type(elem_c_type);
 
-		val = new BitCastInst(val, PointerType::getUnqual(elem_type),
-			"", bb);
+		const bool is_ary = ArrayType::classof(val->getType());
+		if (!is_ary) {
+		    val = new BitCastInst(val,
+			    PointerType::getUnqual(elem_type), "", bb);
+		}
 
 		Value *ary = CallInst::Create(newArrayFunc,
 			ConstantInt::get(Int32Ty, elem_count), "", bb);
 		for (long i = 0; i < elem_count; i++) {
 		    Value *idx = ConstantInt::get(Int32Ty, i);
-		    Value *slot = GetElementPtrInst::Create(val, idx, "", bb);
-		    Value *elem = new LoadInst(slot, "", bb);
+		    Value *elem;
+		    if (is_ary) {
+			elem = ExtractValueInst::Create(val, i, "", bb);
+		    }
+		    else {
+			Value *slot = GetElementPtrInst::Create(val, idx, "",
+				bb);
+			elem = new LoadInst(slot, "", bb);
+		    }
 		    Value *args[] = {
 			ary,
 			idx,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101105/784c78b0/attachment.html>


More information about the macruby-changes mailing list