dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ./ChangeLog engine/jitc.c engine/jitc_obj.c


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ./ChangeLog engine/jitc.c engine/jitc_obj.c
Date: Sun, 15 Jan 2006 17:42:13 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Branch:         
Changes by:     Klaus Treichel <address@hidden> 06/01/15 17:42:12

Modified files:
        .              : ChangeLog 
        engine         : jitc.c jitc_obj.c 

Log message:
        Implement boxing and the opcodes for typed references (krokas).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnet/ChangeLog.diff?tr1=1.3276&tr2=1.3277&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnet/engine/jitc.c.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnet/engine/jitc_obj.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: pnet/ChangeLog
diff -u pnet/ChangeLog:1.3276 pnet/ChangeLog:1.3277
--- pnet/ChangeLog:1.3276       Sun Jan 15 06:06:12 2006
+++ pnet/ChangeLog      Sun Jan 15 17:42:12 2006
@@ -1,3 +1,8 @@
+2006-01-15  Kirill Kononenko  <address@hidden>
+
+       * engine/jitc.c: Add jit type for typed references.
+
+       * engine/jitc_obj.c: Implement boxing and the typed reference opcodes.
 
 2006-01-15  Rhys Weatherley  <address@hidden>
 
Index: pnet/engine/jitc.c
diff -u pnet/engine/jitc.c:1.13 pnet/engine/jitc.c:1.14
--- pnet/engine/jitc.c:1.13     Mon Jan  9 20:49:47 2006
+++ pnet/engine/jitc.c  Sun Jan 15 17:42:12 2006
@@ -58,6 +58,11 @@
 static struct _tagILJitTypes _ILJitType_VPTR;
 
 /*
+ * Jit type for typed references.
+ */
+static ILJitType _ILJitTypedRef = 0;
+
+/*
  * Definition of signatures of internal functions used by jitted code.
  * They have to be kept in sync wirh the corresponding engine funcions.
  */
@@ -644,6 +649,7 @@
 {
        ILJitType       returnType;
        ILJitType       args[3];
+       ILJitType       fields[2];
 
        /* Initialize libjit */
        jit_init();
@@ -679,10 +685,19 @@
        _ILJitTypesInitBase(&_ILJitType_U8, jit_type_ulong);
        _ILJitTypesInitBase(&_ILJitType_VPTR, jit_type_void_ptr);
 
+
+       // Initialize the TypedRef type in its jit representation.      
+       fields[0] = _IL_JIT_TYPE_VPTR;
+       fields[1] = _IL_JIT_TYPE_VPTR;
+       if(!(_ILJitTypedRef = jit_type_create_struct(fields, 2, 1)))
+       {
+               return 0;
+       }
+
        /* Initialize the native method signatures. */
        args[0] = _IL_JIT_TYPE_VPTR;
        args[1] = _IL_JIT_TYPE_VPTR;
-       args[2] = jit_type_int;
+       args[2] = _IL_JIT_TYPE_UINT32;
        returnType = _IL_JIT_TYPE_VPTR;
        if(!(_ILJitSignature_ILEngineAlloc = 
                jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType, 
args, 3, 1)))
Index: pnet/engine/jitc_obj.c
diff -u pnet/engine/jitc_obj.c:1.4 pnet/engine/jitc_obj.c:1.5
--- pnet/engine/jitc_obj.c:1.4  Thu Jan 12 20:23:07 2006
+++ pnet/engine/jitc_obj.c      Sun Jan 15 17:42:12 2006
@@ -60,6 +60,38 @@
        return staticData;
 }
 
+/*
+ * Get the value pointer from a typed reference.
+ * A check is made if the type of typed reference matches the given classInfo.
+ * If they don't match an InvalidCastEWxception is thrown.
+ */
+static ILJitValue _ILJitGetValFromRef(ILJITCoder *jitCoder, ILJitValue 
refValue,
+                                                                         
ILClass *classInfo)
+{
+       jit_label_t label1 = jit_label_undefined;
+       jit_nuint typeOffset = jit_type_get_offset(_ILJitTypedRef, 0);
+       jit_nuint valueOffset = jit_type_get_offset(_ILJitTypedRef, 1);
+       ILJitValue info = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
                 _IL_JIT_TYPE_VPTR,
+                                                                               
                 (jit_nint)classInfo);
+       ILJitValue ptr = jit_insn_address_of(jitCoder->jitFunction, refValue);;
+       ILJitValue type = jit_insn_load_relative(jitCoder->jitFunction,
+                                                                               
         ptr,
+                                                                               
         typeOffset,
+                                                                               
         _IL_JIT_TYPE_VPTR);
+       ILJitValue temp;
+       ILJitValue valuePtr;
+
+       temp = jit_insn_eq(jitCoder->jitFunction, type, info);
+       jit_insn_branch_if(jitCoder->jitFunction, temp, &label1);
+       /* TODO: Throw System.InvalidCastException */
+
+       jit_insn_label(jitCoder->jitFunction, &label1);
+       valuePtr = jit_insn_load_relative(jitCoder->jitFunction, ptr, 
valueOffset,
+                                                                         
_IL_JIT_TYPE_VPTR);
+       return valuePtr;
+}
+
 static void JITCoder_CastClass(ILCoder *coder, ILClass *classInfo,
                                                           int throwException)
 {
@@ -178,27 +210,134 @@
 static void JITCoder_Box(ILCoder *coder, ILClass *boxClass,
                                             ILEngineType valueType, ILUInt32 
size)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+
+       ILJitValue value = jitCoder->jitStack[jitCoder->stackTop - 1];
+       ILJitValue newObj;
+       ILJitValue args[3];
+       ILType *type = ILClassToType(boxClass);
+       ILJitType jitType = _ILJitGetReturnType(type, jitCoder->process);
+       jit_label_t label1 = jit_label_undefined;
+
+       if(valueType == ILEngineType_TypedRef)
+       {
+               /* We have to unpack the value first. */        
+               ILJitValue ptr = _ILJitGetValFromRef(jitCoder, value, boxClass);
+               value = jit_insn_load_relative(jitCoder->jitFunction, ptr, 0, 
jitType);
+       }
+
+       /* Allocate the object. */
+       args[0] = jit_value_get_param(jitCoder->jitFunction, 0);
+       args[1] = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                       _IL_JIT_TYPE_VPTR, 
(jit_nint)boxClass);
+
+       args[2] = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                       jit_type_int, size);
+
+       newObj = jit_insn_call_native(jitCoder->jitFunction, 0, _ILEngineAlloc,
+                                       _ILJitSignature_ILEngineAlloc, args, 3, 
0);
+
+       jit_insn_branch_if(jitCoder->jitFunction, newObj, &label1);
+       _ILJitThrowCurrentException(jitCoder);
+       jit_insn_label(jitCoder->jitFunction, &label1);
+
+       if(jit_value_get_type(value)!=jitType)
+       {
+               value = jit_insn_convert(jitCoder->jitFunction, value, jitType, 
1);
+       }
+       /* Box a managed value */
+       jit_insn_store_relative(jitCoder->jitFunction, newObj, 0, value);
+       jitCoder->jitStack[jitCoder->stackTop - 1] = newObj;
 }
 
 static void JITCoder_BoxSmaller(ILCoder *coder, ILClass *boxClass,
                                                            ILEngineType 
valueType, ILType *smallerType)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitValue value = jitCoder->jitStack[jitCoder->stackTop - 1];
+       ILJitType jitType = _ILJitGetReturnType(smallerType, jitCoder->process);
+
+       ILJitValue newObj;
+       ILJitValue args[3];
+
+       jit_label_t label1 = jit_label_undefined;
+
+       /* Allocate memory */
+       args[0] = jit_value_get_param(jitCoder->jitFunction, 0);
+       args[1] = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
         _IL_JIT_TYPE_VPTR,
+                                                                               
         (jit_nint)boxClass);
+       args[2] = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
         _IL_JIT_TYPE_UINT32,
+                                                                               
         jit_type_get_size(jitType));
+                                                       
+       newObj = jit_insn_call_native(jitCoder->jitFunction, 0, _ILEngineAlloc,
+                                                                 
_ILJitSignature_ILEngineAlloc, args, 3, 0);
+                                       
+       jit_insn_branch_if(jitCoder->jitFunction, newObj, &label1);
+       _ILJitThrowCurrentException(jitCoder);
+       jit_insn_label(jitCoder->jitFunction, &label1);
+
+       
+       /* If the smallerType is smaller then the initiale type then convert to 
it. */
+       if(jit_value_get_type(value) != jitType)
+       {
+               value = jit_insn_convert(jitCoder->jitFunction, value, jitType, 
0);
+       }
+       
+       jit_insn_store_relative(jitCoder->jitFunction, newObj, 0, value);
+       jitCoder->jitStack[jitCoder->stackTop - 1] = newObj;
 }
 
 static void JITCoder_Unbox(ILCoder *coder, ILClass *boxClass)
 {
+       /* We don't have to do anything here: the object reference
+          points at the start of the object's fields, which is
+          exactly the pointer that we need for the unboxed value */
 }
 
 static void JITCoder_MakeTypedRef(ILCoder *coder, ILClass *classInfo)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       jit_nuint typeOffset = jit_type_get_offset(_ILJitTypedRef, 0);
+       jit_nuint valueOffset = jit_type_get_offset(_ILJitTypedRef, 1);
+       /* Create the structure */
+       ILJitValue value = jit_value_create(jitCoder->jitFunction, 
_ILJitTypedRef);
+       ILJitValue ptr = jit_insn_address_of(jitCoder->jitFunction, value);
+                               
+       ILJitValue typeConst = 
jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
                                  _IL_JIT_TYPE_VPTR,
+                                                                               
                                  (jit_nint)classInfo);
+       
+       jit_insn_store_relative(jitCoder->jitFunction, ptr, typeOffset, 
typeConst);
+                               
+       jit_insn_store_relative(jitCoder->jitFunction, ptr, valueOffset,
+                                                       
jitCoder->jitStack[jitCoder->stackTop - 1]);
+
+       jitCoder->jitStack[jitCoder->stackTop - 1] = value;
 }
 
 static void JITCoder_RefAnyVal(ILCoder *coder, ILClass *classInfo)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitValue value = jitCoder->jitStack[jitCoder->stackTop - 1];
+
+       jitCoder->jitStack[jitCoder->stackTop - 1] =
+                                       _ILJitGetValFromRef(jitCoder, value, 
classInfo);
 }
 
 static void JITCoder_RefAnyType(ILCoder *coder)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitValue ptr =
+                               jit_insn_address_of(jitCoder->jitFunction,
+                                                                       
jitCoder->jitStack[jitCoder->stackTop - 1]);
+       jit_nuint typeOffset = jit_type_get_offset(_ILJitTypedRef, 0);
+       jitCoder->jitStack[jitCoder->stackTop - 1] =
+                                                               
jit_insn_load_relative(jitCoder->jitFunction,
+                                                                               
                           ptr,
+                                                                               
                           typeOffset,
+                                                                               
                           _IL_JIT_TYPE_VPTR);
 }
 
 static void JITCoder_PushToken(ILCoder *coder, ILProgramItem *item)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]