From 49a5a9f39871374b59fdf1525de4fa95711492c1 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:11:54 -0600 Subject: [PATCH] use ir::Type in Compiler::push --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 22 +++++- src/compile.cpp | 112 ++++++++++++++++--------------- 3 files changed, 79 insertions(+), 57 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c9692be59d..0c70db57e1 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -83,7 +83,7 @@ class Compiler { virtual Operand* register_(int number) = 0; virtual void push(unsigned footprint) = 0; - virtual void push(unsigned footprint, Operand* value) = 0; + virtual void push(ir::Type type, Operand* value) = 0; virtual void save(unsigned footprint, Operand* value) = 0; virtual Operand* pop(unsigned footprint) = 0; virtual void pushed() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 4e5cf2462d..5083b8acc6 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2110,6 +2110,20 @@ class Client: public Assembler::Client { Context* c; }; +unsigned typeFootprint(Context* c, ir::Type type) +{ + // TODO: this function is very Java-specific in nature. Generalize. + switch (type.flavor()) { + case ir::Type::Float: + case ir::Type::Integer: + return type.size() / 4; + case ir::Type::Object: + return 1; + default: + abort(c); + } +} + class MyCompiler: public Compiler { public: MyCompiler(System* s, Assembler* assembler, Zone* zone, @@ -2335,8 +2349,12 @@ class MyCompiler: public Compiler { c.stack = s; } - virtual void push(unsigned footprint, Operand* value) { - compiler::push(&c, footprint, static_cast(value)); + virtual void push(ir::Type type, Operand* value) + { + // 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); + compiler::push(&c, typeFootprint(&c, type), static_cast(value)); } virtual void save(unsigned footprint, Operand* value) { diff --git a/src/compile.cpp b/src/compile.cpp index 3a74746262..500543ed5a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1358,28 +1358,30 @@ class Frame { typedef Compiler::Operand* Value; - Frame(Context* context, uint8_t* stackMap): - context(context), - t(context->thread), - c(context->compiler), - subroutine(0), - stackMap(stackMap), - ip(0), - sp(localSize()), - level(0) + Frame(Context* context, uint8_t* stackMap) + : context(context), + t(context->thread), + c(context->compiler), + subroutine(0), + stackMap(stackMap), + ip(0), + sp(localSize()), + level(0), + types(TargetBytesPerWord) { memset(stackMap, 0, codeMaxStack(t, methodCode(t, context->method))); } - Frame(Frame* f, uint8_t* stackMap): - context(f->context), - t(context->thread), - c(context->compiler), - subroutine(f->subroutine), - stackMap(stackMap), - ip(f->ip), - sp(f->sp), - level(f->level + 1) + Frame(Frame* f, uint8_t* stackMap) + : context(f->context), + t(context->thread), + c(context->compiler), + subroutine(f->subroutine), + stackMap(stackMap), + ip(f->ip), + sp(f->sp), + level(f->level + 1), + types(TargetBytesPerWord) { memcpy(stackMap, f->stackMap, codeMaxStack (t, methodCode(t, context->method))); @@ -1677,12 +1679,13 @@ class Frame { this->ip = ip; } - void pushQuiet(unsigned footprint, Value o) { - c->push(footprint, o); + void pushQuiet(ir::Type type, Value o) + { + c->push(type, o); } void pushLongQuiet(Value o) { - pushQuiet(2, o); + pushQuiet(types.i8, o); } Value popQuiet(unsigned footprint) { @@ -1694,17 +1697,17 @@ class Frame { } void pushInt(Value o) { - pushQuiet(1, o); + pushQuiet(types.i4, o); pushedInt(); } void pushAddress(Value o) { - pushQuiet(1, o); + pushQuiet(types.i4, o); pushedInt(); } void pushObject(Value o) { - pushQuiet(1, o); + pushQuiet(types.object, o); pushedObject(); } @@ -1784,7 +1787,7 @@ class Frame { } void dup() { - pushQuiet(1, c->peek(1, 0)); + pushQuiet(types.i4, c->peek(1, 0)); dupped(); } @@ -1793,9 +1796,9 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); duppedX1(); } @@ -1806,17 +1809,17 @@ class Frame { if (get(sp - 2) == Long) { Value s1 = popLongQuiet(); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); pushLongQuiet(s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); } else { Value s1 = popQuiet(1); Value s2 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } duppedX2(); @@ -1829,10 +1832,10 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2(); @@ -1844,18 +1847,18 @@ class Frame { Value s1 = popQuiet(1); pushLongQuiet(s0); - pushQuiet(1, s1); + pushQuiet(types.i4, s1); pushLongQuiet(s0); } else { Value s0 = popQuiet(1); Value s1 = popQuiet(1); Value s2 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2X1(); @@ -1876,8 +1879,8 @@ class Frame { Value s2 = popQuiet(1); pushLongQuiet(s0); - pushQuiet(1, s2); - pushQuiet(1, s1); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); pushLongQuiet(s0); } } else { @@ -1886,12 +1889,12 @@ class Frame { Value s2 = popQuiet(1); Value s3 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s3); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s3); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2X2(); @@ -1901,8 +1904,8 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); swapped(); } @@ -1996,6 +1999,7 @@ class Frame { unsigned ip; unsigned sp; unsigned level; + ir::Types types; }; unsigned