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_call.c


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ./ChangeLog engine/jitc_call.c
Date: Thu, 05 Jan 2006 20:15:06 +0000

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

Modified files:
        .              : ChangeLog 
        engine         : jitc_call.c 

Log message:
        Add constructor-, normal- and virtual calls. (thanks krokas)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnet/ChangeLog.diff?tr1=1.3267&tr2=1.3268&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/dotgnu-pnet/pnet/engine/jitc_call.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: pnet/ChangeLog
diff -u pnet/ChangeLog:1.3267 pnet/ChangeLog:1.3268
--- pnet/ChangeLog:1.3267       Wed Jan  4 18:54:38 2006
+++ pnet/ChangeLog      Thu Jan  5 20:15:06 2006
@@ -3,7 +3,10 @@
        * engine/jitc.c, engine/jitc.h, engine/jitc_branch.c, 
engine/jitc_conv.c,
        engine/jitc_ptr.c: Implement the type conversion opcodes, the array 
stuff
        and some other pointer related opcodes.
-.
+
+       * engine/jitc_call.c: Add constructor-, normal- and virtual calls.
+       (thanks krokas).
+
 2006-01-02  Klaus Treichel  <address@hidden>
 
        * engine/jitc_stack.c: Implement JITCoder_StackRefresh.
Index: pnet/engine/jitc_call.c
diff -u pnet/engine/jitc_call.c:1.3 pnet/engine/jitc_call.c:1.4
--- pnet/engine/jitc_call.c:1.3 Sat Dec 31 09:16:04 2005
+++ pnet/engine/jitc_call.c     Thu Jan  5 20:15:06 2006
@@ -73,6 +73,23 @@
 }
 
 /*
+ * Fill the argument array for the methodcall with the args on the stack.
+ * This function pops the arguments off the stack too.
+ */
+static void _ILJitFillArguments(ILJITCoder *coder, ILJitValue *args,
+                                                               
ILCoderMethodInfo *info)
+{
+       int argCount = info->numBaseArgs + info->numVarArgs;
+       int current = 0;
+       
+       JITC_ADJUST(coder, -argCount);
+       for(current = 0; current < argCount; current++)
+       {
+               args[current] = coder->jitStack[coder->stackTop + current];
+       }
+}
+
+/*
  * Create a new object and push it on the stack.
  */
 static void _ILJitNewObj(ILJITCoder *coder, ILClass *info, ILJitValue *newArg)
@@ -94,12 +111,33 @@
        *newArg = newObj;
 }
 
+
+static int _ILJitIsStringClass(ILClass *info)
+{
+       ILImage *systemImage;
+       if(!strcmp(info->className->name, "String") &&
+           info->className->namespace &&
+           !strcmp(info->className->namespace, "System"))
+       {
+               /* Check that it is within the system image, to prevent
+                  applications from fooling us into believeing that their
+                  own class is the system's string class */
+               
+               info = ILClassResolve(info);
+               systemImage = info->programItem.image->context->systemImage;
+               if(!systemImage || systemImage == info->programItem.image)
+               {
+                       return 1;
+               }
+       }       
+       return 0;
+}
+
 /*
  * Call a Method.
  */
 static void _ILJitCallMethod(ILJITCoder *coder, ILJitValue *stackTop, int 
isCtor)
 {
-
 }
 
 static void JITCoder_UpConvertArg(ILCoder *coder, ILEngineStackItem *args,
@@ -133,6 +171,33 @@
                                                                
ILEngineStackItem *returnItem,
                                                                ILMethod 
*methodInfo)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitFunction jitFunction = ILJitFunctionFromILMethod(methodInfo);
+       int argCount = info->numBaseArgs + info->numVarArgs;
+       ILJitValue jitParams[argCount + 1];
+       ILJitValue returnValue;
+
+       /* Set the ILExecThread argument. */
+       jitParams[0] = jit_value_get_param(jitCoder->jitFunction, 0);
+
+       _ILJitFillArguments(jitCoder, &(jitParams[1]), info);
+       /* TODO: create call signature for vararg calls. */     
+               
+       if(info->tailCall == 1)
+       {
+               returnValue = jit_insn_call(jitCoder->jitFunction, 0, 
jitFunction, 0,
+                                                                       
jitParams, argCount + 1, JIT_CALL_TAIL);
+       }
+       else
+       {               
+               returnValue = jit_insn_call(jitCoder->jitFunction, 0, 
jitFunction, 0,
+                                                                       
jitParams, argCount + 1, 0);
+               if(returnItem->engineType != ILEngineType_Invalid)
+               {
+                       jitCoder->jitStack[jitCoder->stackTop] = returnValue;
+                       JITC_ADJUST(jitCoder, 1);
+               }
+       }
 }
 
 static void JITCoder_CallIndirect(ILCoder *coder, ILCoderMethodInfo *info,
@@ -143,12 +208,85 @@
 static void JITCoder_CallCtor(ILCoder *coder, ILCoderMethodInfo *info,
                                                          ILMethod *methodInfo)
 {
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitFunction jitFunction = ILJitFunctionFromILMethod(methodInfo);
+       int argCount = info->numBaseArgs + info->numVarArgs;
+       ILJitValue jitParams[argCount + 2];
+       ILJitValue returnValue;
+       
+       /* Output a call to the constructor */
+       jitParams[0] = jit_value_get_param(jitCoder->jitFunction, 0); // we add 
the current function thread as the first param
+               
+       if(_ILJitIsStringClass(ILMethod_Owner(methodInfo)))
+       {
+               _ILJitFillArguments(jitCoder, &(jitParams[1]), info);
+               // call the constructor with jitParams as input
+               returnValue = jit_insn_call(jitCoder->jitFunction, 0, 
jitFunction, 0,
+                                                                       
jitParams, argCount + 1, 0);
+               jitCoder->jitStack[jitCoder->stackTop] = returnValue;
+       }
+       else
+       {
+               _ILJitNewObj(jitCoder, ILMethod_Owner(methodInfo), 
&jitParams[1]); // create a newobj and add it to the jitParams[1]
+               _ILJitFillArguments(jitCoder, &(jitParams[2]), info);
+
+               // call the constructor with jitParams as input
+               returnValue = jit_insn_call(jitCoder->jitFunction, 0, 
jitFunction, 0,
+                                                                       
jitParams, argCount + 2, 0);
+               jitCoder->jitStack[jitCoder->stackTop] = jitParams[1];
+       }       
+       JITC_ADJUST(jitCoder, 1);
 }
 
 static void JITCoder_CallVirtual(ILCoder *coder, ILCoderMethodInfo *info,
                                                                 
ILEngineStackItem *returnItem,
                                                                 ILMethod 
*methodInfo)
 {
+
+       ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       int argCount = info->numBaseArgs + info->numVarArgs;
+       ILJitValue jitParams[argCount + 2];
+       ILJitValue returnValue;
+       ILJitValue classPrivate;
+       ILJitValue vtable;
+       ILJitValue vtableIndex;
+       ILJitValue method;
+       ILJitValue jitFunction;
+
+       jitParams[0] = jit_value_get_param(jitCoder->jitFunction, 0);
+       _ILJitFillArguments(jitCoder, &(jitParams[1]), info);
+       jit_insn_check_null(jitCoder->jitFunction, jitParams[1]);
+       classPrivate = _ILJitGetObjectClassPrivate(jitCoder->jitFunction, 
jitParams[1]);
+       vtable = jit_insn_load_relative(jitCoder->jitFunction, classPrivate, 
+                                                                       
offsetof(ILClassPrivate, vtable), 
+                                                                       
_IL_JIT_TYPE_VPTR);
+       vtableIndex = jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
                 _IL_JIT_TYPE_INT32,
+                                                                               
                 (jit_nint)methodInfo->index);
+       method = jit_insn_load_elem(jitCoder->jitFunction, vtable,
+                                                                        
vtableIndex, _IL_JIT_TYPE_VPTR);
+       jitFunction = jit_insn_load_relative(jitCoder->jitFunction, method, 
+                                                                       
offsetof(ILClassPrivate, vtable), 
+                                                                       
_IL_JIT_TYPE_VPTR);
+       if(info->tailCall == 1)
+       {
+               returnValue = jit_insn_call_indirect(jitCoder->jitFunction,
+                                                                               
         jitFunction, 0,
+                                                                               
         jitParams, argCount,
+                                                                               
         JIT_CALL_TAIL);
+       }
+       else
+       {
+               returnValue = jit_insn_call_indirect(jitCoder->jitFunction,
+                                                                               
         jitFunction, 0,
+                                                                               
         jitParams, argCount,
+                                                                               
         0);
+               if(returnItem->engineType != ILEngineType_Invalid)
+               {
+                       jitCoder->jitStack[jitCoder->stackTop] = returnValue;
+                       JITC_ADJUST(jitCoder, 1);
+               }
+       }
 }
 
 static void JITCoder_CallInterface(ILCoder *coder, ILCoderMethodInfo *info,
@@ -160,6 +298,7 @@
 static int JITCoder_CallInlineable(ILCoder *coder, int inlineType,
                                                                   ILMethod 
*methodInfo)
 {
+       /* If we get here, then we don't know how to inline the method */
        return 0;
 }
 




reply via email to

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