From d8914a9646bf44f587257733c30ee70a6f39b449 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 21:35:08 -0600 Subject: [PATCH] use ir::Type in Compiler::initLocal --- include/avian/codegen/compiler.h | 2 +- include/avian/codegen/ir.h | 8 +++++++- src/codegen/compiler.cpp | 12 ++++++++---- src/compile.cpp | 18 +++++++++--------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 88b87886e3..e43edb75b1 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -108,7 +108,7 @@ class Compiler { virtual void return_(ir::Type type, Operand* value) = 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 storeLocal(unsigned footprint, Operand* src, unsigned index) = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index e3c6f0ed13..8ed577b91c 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -23,7 +23,13 @@ class Type { // GC-invisible types Integer, - Float + Float, + Address, + + // Represents individual halves of two-word types + // (double/long on 32-bit systems) + // TODO: remove when possible + Half, }; private: diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d1052c0ff0..af0ce8abdc 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2118,6 +2118,8 @@ unsigned typeFootprint(Context* c, ir::Type type) case ir::Type::Integer: return type.size() / 4; case ir::Type::Object: + case ir::Type::Address: + case ir::Type::Half: return 1; default: abort(c); @@ -2274,7 +2276,7 @@ class MyCompiler: public Compiler { for (unsigned li = 0; li < c.localFootprint; ++li) { Local* local = c.locals + li; 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); } - 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); - Value* v = value(&c, valueType(&c, type)); + Value* v = value(&c, type); if (footprint > 1) { assert(&c, footprint == 2); @@ -2564,7 +2568,7 @@ class MyCompiler: public Compiler { for (int i = 0; i < static_cast(c.localFootprint); ++i) { Local* local = e->locals() + i; if (local->value) { - initLocal(1, i, isGeneralValue(local->value) ? IntegerType : FloatType); + initLocal(1, i, local->value->type); } } diff --git a/src/compile.cpp b/src/compile.cpp index b86cf25589..50f52507f4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7153,7 +7153,7 @@ compile(MyThread* t, Context* context) unsigned index = methodParameterFootprint(t, context->method); if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { frame.set(--index, Frame::Object); - c->initLocal(1, index, Compiler::ObjectType); + c->initLocal(1, index, frame.types.object); } for (MethodSpecIterator it @@ -7165,29 +7165,29 @@ compile(MyThread* t, Context* context) case 'L': case '[': frame.set(--index, Frame::Object); - c->initLocal(1, index, Compiler::ObjectType); + c->initLocal(1, index, frame.types.object); break; - + case 'J': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, Compiler::IntegerType); + c->initLocal(2, index, frame.types.i8); break; case 'D': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, Compiler::FloatType); + c->initLocal(2, index, frame.types.f8); break; - + case 'F': frame.set(--index, Frame::Integer); - c->initLocal(1, index, Compiler::FloatType); + c->initLocal(1, index, frame.types.f4); break; - + default: frame.set(--index, Frame::Integer); - c->initLocal(1, index, Compiler::IntegerType); + c->initLocal(1, index, frame.types.i4); break; } }