[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_cast.tc codegen/cg_co...
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_cast.tc codegen/cg_co... |
Date: |
Tue, 09 Dec 2008 21:18:24 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 08/12/09 21:18:23
Modified files:
. : ChangeLog
codegen : cg_cast.tc cg_coerce.c cg_misc.tc cg_nodes.tc
jv_misc.tc
cscc/c : c_name.tc c_oper.tc
cscc/csharp : cs_oper.tc
engine : layout.c verify_conv.c
Log message:
Add support for casts from String to char *. Do some code generation
optimization.
Fix segfault in ilverify if built with jit.
Allow conversion from object reference to intptr in unsafe contexts.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3588&r2=1.3589
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_cast.tc?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_coerce.c?cvsroot=dotgnu-pnet&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_misc.tc?cvsroot=dotgnu-pnet&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_nodes.tc?cvsroot=dotgnu-pnet&r1=1.92&r2=1.93
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/jv_misc.tc?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_name.tc?cvsroot=dotgnu-pnet&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/c/c_oper.tc?cvsroot=dotgnu-pnet&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/pnet/cscc/csharp/cs_oper.tc?cvsroot=dotgnu-pnet&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/layout.c?cvsroot=dotgnu-pnet&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_conv.c?cvsroot=dotgnu-pnet&r1=1.3&r2=1.4
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3588
retrieving revision 1.3589
diff -u -b -r1.3588 -r1.3589
--- ChangeLog 6 Dec 2008 19:13:36 -0000 1.3588
+++ ChangeLog 9 Dec 2008 21:18:19 -0000 1.3589
@@ -1,3 +1,32 @@
+2008-12-09 Klaus Treichel <address@hidden>
+
+ * codegen/cg_cast.tc: Replace the code generated for casts to bool with
+ branchless alternatives.
+
+ * codegen/cg_coerce.c (GetUnsafeConvertRules): Add Check for casts from
+ System.String to a pointer to char.
+ (ApplyRules): Handle the cast from string to char *.
+
+ * codegen/cg_misc.tc: Add code genereration for the new nodetype
+ ILNode_CastStringToCharPtr.
+ (ILNode_GenValue(ILNode_Is)): Replace the code with branches with a
+ branchless alternative.
+
+ * codegen/cg_nodes.tc: Add the new node type ILNode_CastStringToCharPtr
+ for casts from string to char *.
+
+ * codegen/jv_misc.tc: Add dummy code genereration for the new nodetype
+ ILNode_CastStringToCharPtr.
+
+ * cscc/c/c_name.tc, cscc/c/c_oper.tc, cscc/csharp/cs_oper.tc: Add the
+ functions needed for the new node type ILNode_CastStringToCharPtr.
+
+ * engine/layout.c (LayoutClass): Generate jit functions only if not
+ executed from ILVerify if built with jit.
+
+ * engine/verify_conv.c (VERIFY_CONV): Allow casting an object reference
+ to NativeInt in unsafe contexts.
+
2008-12-06 Klaus Treichel <address@hidden>
* cscc/csharp/cs_grammar.y; Fix cast to pointer to pointer (char **).
Index: codegen/cg_cast.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_cast.tc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- codegen/cg_cast.tc 21 Jun 2003 08:48:50 -0000 1.14
+++ codegen/cg_cast.tc 9 Dec 2008 21:18:20 -0000 1.15
@@ -131,48 +131,32 @@
ILGenCast(ILMachineType_TransientPtr, ILMachineType_Boolean)
{
/* Note: this would be a lot easier if there was a
- "cne" opcode in the instruction set */
- ILLabel label1 = ILLabel_Undefined;
- ILLabel label2 = ILLabel_Undefined;
- ILGenJump(info, IL_OP_BRFALSE, &label1);
- ILGenSimple(info, IL_OP_LDC_I4_1);
- ILGenJump(info, IL_OP_BR, &label2);
- ILGenLabel(info, &label1);
+ "cne" opcode in the instruction set.
+ So We have to use ceq and not instead */
ILGenSimple(info, IL_OP_LDC_I4_0);
- ILGenLabel(info, &label2);
+ ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CEQ);
+ ILGenSimple(info, IL_OP_LDC_I4_1);
+ ILGenSimple(info, IL_OP_XOR);
+ ILGenExtend(info, 1);
}
ILGenCast(ILMachineType_Int64, ILMachineType_Boolean),
ILGenCast(ILMachineType_UInt64, ILMachineType_Boolean)
{
- /* Note: we can probably do this with "brfalse", but the
- documentation is a little vague. It provides information
- for types "I" and "O", but not "I8" or "F". Therefore,
- we will be paranoid and do it the long way */
- ILLabel label1 = ILLabel_Undefined;
- ILLabel label2 = ILLabel_Undefined;
ILGenSimple(info, IL_OP_LDC_I4_0);
ILGenSimple(info, IL_OP_CONV_I8);
- ILGenJump(info, IL_OP_BEQ, &label1);
+ ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CEQ);
ILGenSimple(info, IL_OP_LDC_I4_1);
- ILGenJump(info, IL_OP_BR, &label2);
- ILGenLabel(info, &label1);
- ILGenSimple(info, IL_OP_LDC_I4_0);
- ILGenLabel(info, &label2);
+ ILGenSimple(info, IL_OP_XOR);
ILGenExtend(info, 1);
}
ILGenCast(ILMachineType_Float32, ILMachineType_Boolean),
ILGenCast(ILMachineType_Float64, ILMachineType_Boolean),
ILGenCast(ILMachineType_NativeFloat, ILMachineType_Boolean)
{
- ILLabel label1 = ILLabel_Undefined;
- ILLabel label2 = ILLabel_Undefined;
ILGenLoadFloat32(info, (ILFloat)0.0);
- ILGenJump(info, IL_OP_BEQ, &label1);
+ ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CEQ);
ILGenSimple(info, IL_OP_LDC_I4_1);
- ILGenJump(info, IL_OP_BR, &label2);
- ILGenLabel(info, &label1);
- ILGenSimple(info, IL_OP_LDC_I4_0);
- ILGenLabel(info, &label2);
+ ILGenSimple(info, IL_OP_XOR);
ILGenExtend(info, 1);
}
ILGenCast(ILMachineType_Decimal, ILMachineType_Boolean)
Index: codegen/cg_coerce.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_coerce.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- codegen/cg_coerce.c 18 Nov 2008 20:06:03 -0000 1.28
+++ codegen/cg_coerce.c 9 Dec 2008 21:18:20 -0000 1.29
@@ -48,6 +48,8 @@
/* Coerce "null" to a pointer type */
int pointerNull;
+ /* Explicit cast from System.String to a pointer to System.Char */
+ int stringCharPtr;
} ConvertRules;
/*
@@ -385,7 +387,7 @@
}
}
- /* Numberic to pointer conversion */
+ /* Numeric to pointer conversion */
if(ILType_IsPointer(toType) && ILIsBuiltinNumeric(fromType))
{
conv = ILFindConversion(fromType, toType, explicit, 1);
@@ -395,6 +397,15 @@
return 1;
}
}
+
+ /* String to char * conversion */
+ if((ILTypeToMachineType(fromType) == ILMachineType_String) &&
+ (ILType_IsPointer(toType) &&
+ ILTypeToMachineType(ILType_Ref(toType)) ==
ILMachineType_Char))
+ {
+ rules->stringCharPtr = 1;
+ return 1;
+ }
}
/* Could not find an appropriate conversion */
@@ -420,6 +431,7 @@
rules->castType = 0;
rules->builtin = 0;
rules->pointerNull = 0;
+ rules->stringCharPtr = 0;
/* Strip type prefixes before we start */
fromType = ILTypeStripPrefixes(fromType);
@@ -930,6 +942,14 @@
yysetfilename(*parent, yygetfilename(node));
yysetlinenum(*parent, yygetlinenum(node));
}
+
+ /* Convert from System.String to a pointer to System.Char */
+ if(rules->stringCharPtr)
+ {
+ *parent = ILNode_CastStringToCharPtr_create(node);
+ yysetfilename(*parent, yygetfilename(node));
+ yysetlinenum(*parent, yygetlinenum(node));
+ }
}
/*
@@ -1361,8 +1381,8 @@
/* TODO : Figure out the actual conversion rules before using
* this in the rest of the code . But it's a reasonably
- * good approximation of what I understand about the spec */
-
+ * good approximation of what I understand about the spec
+ */
int ILBetterConversionFrom(ILGenInfo *info, ILType *s1Type,
ILType *s2Type, ILType *tType)
{
Index: codegen/cg_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_misc.tc,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- codegen/cg_misc.tc 1 Jun 2007 11:08:50 -0000 1.50
+++ codegen/cg_misc.tc 9 Dec 2008 21:18:20 -0000 1.51
@@ -105,6 +105,10 @@
{
return ILTypeToMachineType(node->type);
}
+ILNode_GetType(ILNode_CastStringToCharPtr)
+{
+ return ILMachineType_UnmanagedPtr;
+}
/*
* Get the type associated with a user-defined conversion.
@@ -673,6 +677,19 @@
ILGenTypeToken(info, IL_OP_CASTCLASS, node->type);
return ILTypeToMachineType(node->type);
}
+ILNode_GenValue(ILNode_CastStringToCharPtr)
+{
+ ILNode_GenValue(node->expr, info);
+ ILGenSimple(info, IL_OP_CONV_I);
+ ILGenCallByName(info, "int32 "
+
"[.library]System.Runtime.CompilerServices.RuntimeHelpers"
+ "::get_OffsetToStringData()");
+ ILGenAdjust(info, 1);
+ ILGenSimple(info, IL_OP_CONV_I);
+ ILGenSimple(info, IL_OP_ADD);
+ ILGenAdjust(info, -1);
+ return ILMachineType_UnmanagedPtr;
+}
/*
* Generate value code for a user conversion expression.
@@ -1516,19 +1533,15 @@
*/
ILNode_GenValue(ILNode_Is)
{
- ILLabel label1 = ILLabel_Undefined;
- ILLabel label2 = ILLabel_Undefined;
-
/* Compute the "as" version of the expression */
As_GenValue((ILNode_As *)node, info);
/* Compare the result against "null" to get the result */
- ILGenJump(info, IL_OP_BRFALSE, &label1);
+ ILGenSimple(info, IL_OP_LDNULL);
+ ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CEQ);
ILGenSimple(info, IL_OP_LDC_I4_1);
- ILGenJump(info, IL_OP_BR, &label2);
- ILGenLabel(info, &label1);
- ILGenSimple(info, IL_OP_LDC_I4_0);
- ILGenLabel(info, &label2);
+ ILGenSimple(info, IL_OP_XOR);
+ ILGenExtend(info, 1);
return ILMachineType_Boolean;
}
Index: codegen/cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -b -r1.92 -r1.93
--- codegen/cg_nodes.tc 19 Oct 2008 16:45:17 -0000 1.92
+++ codegen/cg_nodes.tc 9 Dec 2008 21:18:21 -0000 1.93
@@ -405,6 +405,9 @@
ILMachineType machineType;
ILMethod *method;
}
+%node ILNode_CastStringToCharPtr ILNode_UnaryExpression =
+{
+}
%node ILNode_Conditional ILNode_TernaryExpression
%node ILNode_Deref ILNode_LValueNoRef =
{
Index: codegen/jv_misc.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/jv_misc.tc,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- codegen/jv_misc.tc 1 Jun 2007 11:08:50 -0000 1.31
+++ codegen/jv_misc.tc 9 Dec 2008 21:18:21 -0000 1.32
@@ -285,6 +285,13 @@
JavaGenAdjust(info, JavaGenTypeSize(type));
return type;
}
+JavaGenValue(ILNode_CastStringToCharPtr)
+{
+ JavaGenValue(node->expr, info);
+ JavaGenSimple(info, JAVA_OP_POP);
+ JavaGenSimple(info, JAVA_OP_ICONST_0);
+ return ILMachineType_UnmanagedPtr;
+}
/*
* Generate value code for a user conversion expression.
Index: cscc/c/c_name.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_name.tc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cscc/c/c_name.tc 19 Oct 2008 16:45:18 -0000 1.2
+++ cscc/c/c_name.tc 9 Dec 2008 21:18:21 -0000 1.3
@@ -502,6 +502,11 @@
(CTypeToName(&CCCodeGen, node->type),
ILNode_CName(node->expr), C_PREC_UNARY);
}
+ILNode_CName(ILNode_CastStringToCharPtr)
+{
+ return CNameCreateUnaryBracketed
+ ("(__wchar__ *)", ILNode_CName(node->expr), C_PREC_UNARY);
+}
ILNode_CName(ILNode_Conditional)
{
CName name1 = ILNode_CName(node->expr1);
Index: cscc/c/c_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_oper.tc,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- cscc/c/c_oper.tc 1 Jun 2007 11:08:51 -0000 1.44
+++ cscc/c/c_oper.tc 9 Dec 2008 21:18:22 -0000 1.45
@@ -2166,6 +2166,15 @@
}
/*
+ * Perform semantic analysis for the cast from C# String to C# char pointer.
+ */
+ILNode_CSemAnalysis(ILNode_CastStringToCharPtr)
+{
+ /* This will never be called, as the grammar uses "CastType" instead */
+ return CSemValueError;
+}
+
+/*
* Perform semantic analysis for C to C# string conversion.
*/
ILNode_CSemAnalysis(ILNode_CToCSharpString)
Index: cscc/csharp/cs_oper.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_oper.tc,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- cscc/csharp/cs_oper.tc 1 Jun 2007 11:08:52 -0000 1.51
+++ cscc/csharp/cs_oper.tc 9 Dec 2008 21:18:22 -0000 1.52
@@ -2636,6 +2636,10 @@
{
return CSSemValueDefault;
}
+ILNode_SemAnalysis(ILNode_CastStringToCharPtr)
+{
+ return CSSemValueDefault;
+}
/*
* Perform semantic analysis for the user-defined logical AND operator.
Index: engine/layout.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/layout.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- engine/layout.c 26 Nov 2008 20:15:22 -0000 1.50
+++ engine/layout.c 9 Dec 2008 21:18:23 -0000 1.51
@@ -1521,11 +1521,14 @@
{
vtable[method->index] = method;
#ifdef IL_USE_JIT
+ if(isJitCoder)
+ {
/* NOTE: Here still exists the slight possibility that
a type is
layouted whose parent type's vtable is not complete
yet.
Maybe we'll have to loop over the whole vtable again
to build the
jitvtable */
jitVtable[method->index] =
ILJitGetVtablePointer(process->coder, method);
+ }
#endif
}
}
Index: engine/verify_conv.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/verify_conv.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- engine/verify_conv.c 12 Aug 2002 07:33:02 -0000 1.3
+++ engine/verify_conv.c 9 Dec 2008 21:18:23 -0000 1.4
@@ -39,10 +39,13 @@
STK_UNARY_TYPEINFO = 0; \
} \
else if(unsafeAllowed && \
- (STK_UNARY == ILEngineType_M ||
\
- STK_UNARY == ILEngineType_T)) \
+ ((STK_UNARY == ILEngineType_M
|| \
+ STK_UNARY == ILEngineType_O ||
\
+ STK_UNARY == ILEngineType_T)
&& \
+ (((resultType) ==
ILEngineType_I8) || \
+ ((resultType) ==
ILEngineType_I)))) \
{ \
- ILCoderConv(coder, opcode,
ILEngineType_I); \
+ ILCoderConv(coder, opcode, resultType);
\
STK_UNARY = resultType; \
STK_UNARY_TYPEINFO = 0; \
} \
- [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_cast.tc codegen/cg_co...,
Klaus Treichel <=