diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 5cd20d109d..109d8891f8 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -114,6 +114,9 @@ class Compiler { ir::Type truncateType, ir::Value* src) = 0; + virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) + = 0; + virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; virtual ir::Value* load(ir::SignExtendMode signExtend, ir::Type srcType, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 319809d774..6e6452b60d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2515,12 +2515,12 @@ class MyCompiler: public Compiler { return result; } - virtual void return_(ir::Type type, ir::Value* value) + virtual void return_(ir::Type type, ir::Value* a) { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. - // assert(&c, static_cast(value)->type == type); - appendReturn(&c, type.size(), static_cast(value)); + // assert(&c, a->type == type); + appendReturn(&c, type.size(), static_cast(a)); } virtual void return_() @@ -2614,6 +2614,19 @@ class MyCompiler: public Compiler { static_cast(index), handler); } + virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) + { + Value* dst = value(&c, type); + appendMove(&c, + lir::Move, + srcType.size(), + srcType.size(), + static_cast(src), + type.size(), + dst); + return dst; + } + virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend, ir::Type extendType, ir::Type truncateType, diff --git a/src/compile.cpp b/src/compile.cpp index 0a8684afeb..b506b9f990 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1760,6 +1760,7 @@ class Frame { void pushLongQuiet(ir::Value* o) { + // assert(t, o->type == types.i8); pushQuiet(types.i8, o); } @@ -4357,7 +4358,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case areturn: { handleExit(t, frame); - c->return_(types.address, frame->popObject()); + c->return_(types.object, frame->popObject()); } goto next; case arraylength: { @@ -5329,8 +5330,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt( - c->load(ir::SignExtend, types.i8, frame->popLong(), types.address)); + frame->pushInt(c->truncate(types.i4, types.i8, frame->popLong())); break; case ladd: @@ -5366,11 +5366,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lconst_0: - frame->pushLong(c->constant(0, types.i4)); + frame->pushLong(c->constant(0, types.i8)); break; case lconst_1: - frame->pushLong(c->constant(1, types.i4)); + frame->pushLong(c->constant(1, types.i8)); break; case ldc: @@ -5388,7 +5388,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (singletonIsObject(t, pool, index - 1)) { object v = singletonObject(t, pool, index - 1); - loadMemoryBarrier(); + loadMemoryBarrier(); if (objectClass(t, v) == type(t, Machine::ReferenceType)) { object reference = v; @@ -5809,7 +5809,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: c->store( - types.address, + types.i4, value, c->memory(table, types.i1, targetFieldOffset(context, field))); break; @@ -5817,7 +5817,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case CharField: case ShortField: c->store( - types.address, + types.i4, value, c->memory(table, types.i2, targetFieldOffset(context, field))); break; @@ -5831,7 +5831,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case IntField: c->store( - types.address, + types.i4, value, c->memory(table, types.i4, targetFieldOffset(context, field))); break;