Permalink
Browse files

2002-05-29 Dietmar Maurer <dietmar@ximian.com>

	* jit.c (mono_analyze_stack): fixed SIZEOF

	* x86.brg: impl. LOCALLOC, INITBLK

svn path=/trunk/mono/; revision=4999
  • Loading branch information...
1 parent 5690333 commit d888f55b42da954cf1b44e343c796295b42f570a Dietmar Maurer committed May 29, 2002
@@ -1,3 +1,6 @@
+2002-05-29 Dietmar Maurer <dietmar@ximian.com>
+
+ * interp.c (ves_exec_method): free type in CEE_SIZEOF
Tue May 28 16:10:49 CEST 2002 Paolo Molaro <lupus@ximian.com>
@@ -3865,6 +3865,7 @@ ves_exec_method (MonoInvocation *frame)
if (mono_metadata_token_table (token) == MONO_TABLE_TYPESPEC) {
MonoType *type = mono_type_create_from_typespec (image, token);
sp->data.i = mono_type_size (type, &align);
+ mono_metadata_free_type (type);
} else {
MonoClass *szclass = mono_class_get (image, token);
mono_class_init (szclass);
View
@@ -1,3 +1,9 @@
+2002-05-29 Dietmar Maurer <dietmar@ximian.com>
+
+ * jit.c (mono_analyze_stack): fixed SIZEOF
+
+ * x86.brg: impl. LOCALLOC, INITBLK
+
2002-05-28 Dietmar Maurer <dietmar@ximian.com>
* x86.brg: impl. CKFINITE
View
@@ -1905,8 +1905,10 @@ mono_analyze_stack (MonoFlowGraph *cfg)
this->data.m = cm;
} else {
if (cm->klass->valuetype) {
- this = mono_ctree_new_leaf (mp, MB_TERM_NEWSTRUCT);
- this->data.i = mono_class_value_size (cm->klass, NULL);
+ t1 = mono_ctree_new_leaf (mp, MB_TERM_CONST_I4);
+ t1->data.i = mono_class_value_size (cm->klass, NULL);
+ this = mono_ctree_new (mp, MB_TERM_LOCALLOC, t1, NULL);
+ this->data.i = TRUE;
} else if (cfg->share_code) {
this = mono_ctree_new_leaf (mp, MB_TERM_NEWOBJ);
this->data.klass = cm->klass;
@@ -3155,15 +3157,23 @@ mono_analyze_stack (MonoFlowGraph *cfg)
}
case CEE_SIZEOF: {
guint32 token;
- MonoType *type;
int align;
++ip;
token = read32 (ip);
ip += 4;
- type = mono_type_create_from_typespec (image, token);
+
t1 = mono_ctree_new_leaf (mp, MB_TERM_CONST_I4);
- t1->data.i = mono_type_size (type, &align);
- mono_metadata_free_type (type);
+ if (mono_metadata_token_table (token) == MONO_TABLE_TYPESPEC) {
+ MonoType *type = mono_type_create_from_typespec (image, token);
+ t1->data.i = mono_type_size (type, &align);
+ mono_metadata_free_type (type);
+ } else {
+ MonoClass *szclass = mono_class_get (image, token);
+ mono_class_init (szclass);
+ g_assert (szclass->valuetype);
+ t1->data.i = mono_class_value_size (szclass, &align);
+ }
+
PUSH_TREE (t1, VAL_I32);
break;
}
@@ -3186,6 +3196,24 @@ mono_analyze_stack (MonoFlowGraph *cfg)
// fixme: implement me
break;
}
+ case CEE_LOCALLOC: {
+ ++ip;
+ --sp;
+
+ t1 = mono_ctree_new (mp, MB_TERM_LOCALLOC, *sp, NULL);
+ t1->data.i = header->init_locals;
+ PUSH_TREE (t1, VAL_POINTER);
+ break;
+ }
+ case CEE_INITBLK: {
+ ++ip;
+ sp -= 3;
+
+ t1 = mono_ctree_new (mp, MB_TERM_CPSRC, sp [1], sp [2]);
+ t1 = mono_ctree_new (mp, MB_TERM_INITBLK, sp [0], t1);
+ ADD_TREE (t1, cli_addr);
+ break;
+ }
default:
g_error ("Unimplemented opcode at IL_%04x "
"0xFE %02x", ip - header->code, *ip);
View
@@ -223,7 +223,8 @@ debug_memcopy (void *dest, const void *src, size_t n);
%term DIV DIV_UN REM REM_UN AND OR XOR SHL SHR SHR_UN NEG NOT CKFINITE
%term COMPARE CBRANCH BRTRUE BRFALSE CSET
%term CONV_I4 CONV_I1 CONV_I2 CONV_I8 CONV_U1 CONV_U2 CONV_U4 CONV_U8 CONV_R4 CONV_R8 CONV_R_UN
-%term INTF_ADDR VFUNC_ADDR NOP NEWARR NEWARR_SPEC NEWOBJ NEWOBJ_SPEC NEWSTRUCT CPBLK CPSRC POP INITOBJ
+%term INTF_ADDR VFUNC_ADDR NOP NEWARR NEWARR_SPEC NEWOBJ NEWOBJ_SPEC
+%term INITBLK CPBLK CPSRC POP INITOBJ LOCALLOC
%term ISINST CASTCLASS UNBOX
%term CONV_OVF_I1 CONV_OVF_U1 CONV_OVF_I2 CONV_OVF_U2 CONV_OVF_U4 CONV_OVF_U8 CONV_OVF_I4
%term CONV_OVF_I4_UN CONV_OVF_U1_UN CONV_OVF_U2_UN
@@ -1711,16 +1712,37 @@ reg: NEWOBJ_SPEC {
PRINT_REG ("NEWOBJ_SPEC", tree->reg1);
}
-reg: NEWSTRUCT {
- int size = tree->data.i;
- int sa;
-
- mono_assert (size > 0);
+reg: LOCALLOC (reg) {
- sa = size + 3;
- sa &= ~3;
+ /* size must be aligne to 4 bytes */
+ x86_alu_reg_imm (s->code, X86_ADD, tree->left->reg1, 3);
+ x86_alu_reg_imm (s->code, X86_AND, tree->left->reg1, ~3);
+
+ /* allocate space on stack */
+ x86_alu_reg_reg (s->code, X86_SUB, X86_ESP, tree->left->reg1);
+
+ if (tree->data.i) {
+ /* initialize with zero */
+
+ if (tree->reg1 != X86_EAX && tree->left->reg1 != X86_EAX)
+ x86_push_reg (s->code, X86_EAX);
+ if (tree->reg1 != X86_ECX && tree->left->reg1 != X86_ECX)
+ x86_push_reg (s->code, X86_ECX);
+
+ x86_shift_reg_imm (s->code, X86_SHR, tree->left->reg1, 2);
+ if (tree->left->reg1 != X86_ECX)
+ x86_mov_reg_imm (s->code, X86_ECX, tree->left->reg1);
+ x86_alu_reg_reg (s->code, X86_XOR, X86_EAX, X86_EAX);
+ x86_cld (s->code);
+ x86_prefix (s->code, X86_REP_PREFIX);
+ x86_stosl (s->code);
+
+ if (tree->reg1 != X86_ECX && tree->left->reg1 != X86_ECX)
+ x86_pop_reg (s->code, X86_ECX);
+ if (tree->reg1 != X86_EAX && tree->left->reg1 != X86_EAX)
+ x86_pop_reg (s->code, X86_EAX);
+ }
- x86_alu_reg_imm (s->code, X86_SUB, X86_ESP, sa);
x86_mov_reg_reg (s->code, tree->reg1, X86_ESP, 4);
}
@@ -1931,6 +1953,19 @@ stmt: CPBLK (reg, CPSRC (reg, reg)) {
x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, 12);
}
+stmt: INITBLK (reg, CPSRC (reg, reg)) {
+ int dest_reg = tree->left->reg1;
+ int source_reg = tree->right->left->reg1;
+ int size_reg = tree->right->right->reg1;
+
+ x86_push_reg (s->code, size_reg);
+ x86_push_reg (s->code, source_reg);
+ x86_push_reg (s->code, dest_reg);
+ mono_add_jump_info (s, s->code, MONO_JUMP_INFO_ABS, memset);
+ x86_call_code (s->code, 0);
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, 12);
+}
+
stmt: NOP
stmt: POP (reg)
View
@@ -113,7 +113,9 @@ TESTSRC= \
cpblkTest.il \
jmpTest.il \
calliTest.il \
- ckfiniteTest.il
+ ckfiniteTest.il \
+ locallocTest.il \
+ initblkTest.il
TESTSI_TMP=$(TESTSRC:.cs=.exe)
View
@@ -0,0 +1,54 @@
+//tests initblk by allocating and initializing and checking an initialized area
+//Prints PASS or FAIL
+.assembly extern mscorlib{}
+.assembly someTest{}
+.module someTest
+
+.class private auto ansi someTest
+ extends [mscorlib]System.Object {
+
+ .method public static void go() cil managed {
+ .entrypoint
+
+ .locals init (native int)
+
+//allocate memory
+ldc.i4.s 10
+localloc
+stloc.0
+
+//init memory offset 3 indirectly
+ldloc.0
+ldc.i4.0
+add //addr
+ldc.i4.0 //value
+stind.i1
+
+//initblk
+ldloc.0 //addr
+ldc.i4.7 //value
+ldc.i4.s 10 //size
+initblk
+
+//load number from offset 3
+ldloc.0
+ldc.i4.3
+add
+ldind.u1
+
+//compare
+ldc.i4.7
+beq PASS
+
+FAIL: ldstr "FAIL"
+ call void [mscorlib]System.Console::WriteLine(string)
+ br END
+
+PASS: ldstr "PASS"
+ call void [mscorlib]System.Console::WriteLine(string)
+
+END: ret
+ }
+
+
+}
View
@@ -0,0 +1,43 @@
+//tests localloc by allocating 4 bytes, storing a value, and loading it
+.assembly extern mscorlib{}
+.assembly someTest{}
+.module someTest
+
+.class private auto ansi someTest
+ extends [mscorlib]System.Object {
+
+ .method public static void go() cil managed {
+ .entrypoint
+
+ .locals init (native int)
+
+//allocate
+ldc.i4.4
+localloc
+stloc.0
+
+//store number
+ldloc.0
+ldc.i4 7777777
+stind.i4
+
+//load number
+ldloc.0
+ldind.i4
+
+//compare
+ldc.i4 7777777
+beq PASS
+
+FAIL: ldstr "FAIL"
+ call void [mscorlib]System.Console::WriteLine(string)
+ br END
+
+PASS: ldstr "PASS"
+ call void [mscorlib]System.Console::WriteLine(string)
+
+END: ret
+ }
+
+
+}

0 comments on commit d888f55

Please sign in to comment.