use ir::Type in Compiler::initLocal

This commit is contained in:
Joshua Warner 2014-04-30 21:35:08 -06:00 committed by Joshua Warner
parent 4bfb359cdd
commit d8914a9646
4 changed files with 25 additions and 15 deletions

View File

@ -108,7 +108,7 @@ class Compiler {
virtual void return_(ir::Type type, Operand* value) = 0; virtual void return_(ir::Type type, Operand* value) = 0;
virtual void return_() = 0; virtual void return_() = 0;
virtual void initLocal(unsigned size, unsigned index, OperandType type) = 0; virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0;
virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0;
virtual void storeLocal(unsigned footprint, Operand* src, virtual void storeLocal(unsigned footprint, Operand* src,
unsigned index) = 0; unsigned index) = 0;

View File

@ -23,7 +23,13 @@ class Type {
// GC-invisible types // GC-invisible types
Integer, Integer,
Float Float,
Address,
// Represents individual halves of two-word types
// (double/long on 32-bit systems)
// TODO: remove when possible
Half,
}; };
private: private:

View File

@ -2118,6 +2118,8 @@ unsigned typeFootprint(Context* c, ir::Type type)
case ir::Type::Integer: case ir::Type::Integer:
return type.size() / 4; return type.size() / 4;
case ir::Type::Object: case ir::Type::Object:
case ir::Type::Address:
case ir::Type::Half:
return 1; return 1;
default: default:
abort(c); abort(c);
@ -2274,7 +2276,7 @@ class MyCompiler: public Compiler {
for (unsigned li = 0; li < c.localFootprint; ++li) { for (unsigned li = 0; li < c.localFootprint; ++li) {
Local* local = c.locals + li; Local* local = c.locals + li;
if (local->value == 0) { if (local->value == 0) {
initLocal(1, li, IntegerType); initLocal(1, li, ir::Type(ir::Type::Address, TargetBytesPerWord));
} }
} }
} }
@ -2510,11 +2512,13 @@ class MyCompiler: public Compiler {
appendReturn(&c, 0, 0); appendReturn(&c, 0, 0);
} }
virtual void initLocal(unsigned footprint, unsigned index, OperandType type) virtual void initLocal(unsigned footprint, unsigned index, ir::Type type)
{ {
// TODO: enable the following assertion when possible:
// assert(&c, footprint == typeFootprint(type));
assert(&c, index + footprint <= c.localFootprint); assert(&c, index + footprint <= c.localFootprint);
Value* v = value(&c, valueType(&c, type)); Value* v = value(&c, type);
if (footprint > 1) { if (footprint > 1) {
assert(&c, footprint == 2); assert(&c, footprint == 2);
@ -2564,7 +2568,7 @@ class MyCompiler: public Compiler {
for (int i = 0; i < static_cast<int>(c.localFootprint); ++i) { for (int i = 0; i < static_cast<int>(c.localFootprint); ++i) {
Local* local = e->locals() + i; Local* local = e->locals() + i;
if (local->value) { if (local->value) {
initLocal(1, i, isGeneralValue(local->value) ? IntegerType : FloatType); initLocal(1, i, local->value->type);
} }
} }

View File

@ -7153,7 +7153,7 @@ compile(MyThread* t, Context* context)
unsigned index = methodParameterFootprint(t, context->method); unsigned index = methodParameterFootprint(t, context->method);
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
frame.set(--index, Frame::Object); frame.set(--index, Frame::Object);
c->initLocal(1, index, Compiler::ObjectType); c->initLocal(1, index, frame.types.object);
} }
for (MethodSpecIterator it for (MethodSpecIterator it
@ -7165,29 +7165,29 @@ compile(MyThread* t, Context* context)
case 'L': case 'L':
case '[': case '[':
frame.set(--index, Frame::Object); frame.set(--index, Frame::Object);
c->initLocal(1, index, Compiler::ObjectType); c->initLocal(1, index, frame.types.object);
break; break;
case 'J': case 'J':
frame.set(--index, Frame::Long); frame.set(--index, Frame::Long);
frame.set(--index, Frame::Long); frame.set(--index, Frame::Long);
c->initLocal(2, index, Compiler::IntegerType); c->initLocal(2, index, frame.types.i8);
break; break;
case 'D': case 'D':
frame.set(--index, Frame::Long); frame.set(--index, Frame::Long);
frame.set(--index, Frame::Long); frame.set(--index, Frame::Long);
c->initLocal(2, index, Compiler::FloatType); c->initLocal(2, index, frame.types.f8);
break; break;
case 'F': case 'F':
frame.set(--index, Frame::Integer); frame.set(--index, Frame::Integer);
c->initLocal(1, index, Compiler::FloatType); c->initLocal(1, index, frame.types.f4);
break; break;
default: default:
frame.set(--index, Frame::Integer); frame.set(--index, Frame::Integer);
c->initLocal(1, index, Compiler::IntegerType); c->initLocal(1, index, frame.types.i4);
break; break;
} }
} }