include function prologue and epilogue when compiling

This commit is contained in:
Joel Dice 2008-02-12 08:21:51 -07:00
parent fa513beb2f
commit 6271f878e8
3 changed files with 46 additions and 6 deletions

View File

@ -15,6 +15,7 @@ const unsigned OperationCount = Return + 1;
enum UnaryOperation { enum UnaryOperation {
Call, Call,
Push, Push,
Pop,
JumpIfLess, JumpIfLess,
JumpIfGreater, JumpIfGreater,
JumpIfLessOrEqual, JumpIfLessOrEqual,

View File

@ -534,6 +534,10 @@ class ReturnEvent: public Event {
} }
} }
Assembler::Register base(c->assembler->base());
Assembler::Register stack(c->assembler->stack());
c->assembler->apply(Move, BytesPerWord, Register, &base, Register, &stack);
c->assembler->apply(Pop, BytesPerWord, Register, &base);
c->assembler->apply(Return); c->assembler->apply(Return);
} }
@ -1156,6 +1160,13 @@ updateJunctions(Context* c)
void void
compile(Context* c) compile(Context* c)
{ {
Assembler* a = c->assembler;
Assembler::Register base(a->base());
Assembler::Register stack(a->stack());
a->apply(Push, BytesPerWord, Register, &base);
a->apply(Move, BytesPerWord, Register, &stack, Register, &base);
for (unsigned i = 0; i < c->logicalCodeLength; ++ i) { for (unsigned i = 0; i < c->logicalCodeLength; ++ i) {
fprintf(stderr, "compile ip %d\n", i); fprintf(stderr, "compile ip %d\n", i);
for (Event* e = c->logicalCode[i].firstEvent; e; e = e->next) { for (Event* e = c->logicalCode[i].firstEvent; e; e = e->next) {

View File

@ -281,6 +281,32 @@ jumpR(Context* c, unsigned size UNUSED, Assembler::Register* a)
c->code.append(0xd0 | a->low); c->code.append(0xd0 | a->low);
} }
void
pushR(Context* c, unsigned size, Assembler::Register* a)
{
if (BytesPerWord == 4 and size == 8) {
Assembler::Register ah(a->high);
pushR(c, 4, &ah);
pushR(c, 4, a);
} else {
c->code.append(0x50 | a->low);
}
}
void
popR(Context* c, unsigned size, Assembler::Register* a)
{
if (BytesPerWord == 4 and size == 8) {
Assembler::Register ah(a->high);
popR(c, 4, a);
popR(c, 4, &ah);
} else {
c->code.append(0x50 | a->low);
}
}
void void
moveCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, moveCR(Context* c, unsigned size UNUSED, Assembler::Constant* a,
Assembler::Register* b) Assembler::Register* b)
@ -307,10 +333,10 @@ void
moveRM(Context* c, unsigned size, Assembler::Register* a, Assembler::Memory* b) moveRM(Context* c, unsigned size, Assembler::Register* a, Assembler::Memory* b)
{ {
if (BytesPerWord == 4 and size == 8) { if (BytesPerWord == 4 and size == 8) {
moveRM(c, 4, a, b);
Assembler::Register ah(a->high); Assembler::Register ah(a->high);
Assembler::Memory bh(b->base, b->offset + 4, b->index, b->scale); Assembler::Memory bh(b->base, b->offset + 4, b->index, b->scale);
moveRM(c, 4, a, b);
moveRM(c, 4, &ah, &bh); moveRM(c, 4, &ah, &bh);
} else if (BytesPerWord == 8 and size == 4) { } else if (BytesPerWord == 8 and size == 4) {
encode(c, 0x89, a->low, b, false); encode(c, 0x89, a->low, b, false);
@ -324,10 +350,10 @@ moveRR(Context* c, unsigned size, Assembler::Register* a,
Assembler::Register* b) Assembler::Register* b)
{ {
if (BytesPerWord == 4 and size == 8) { if (BytesPerWord == 4 and size == 8) {
moveRR(c, 4, a, b);
Assembler::Register ah(a->low); Assembler::Register ah(a->low);
Assembler::Register bh(b->low); Assembler::Register bh(b->low);
moveRR(c, 4, a, b);
moveRR(c, 4, &ah, &bh); moveRR(c, 4, &ah, &bh);
} else { } else {
rex(c); rex(c);
@ -351,10 +377,10 @@ moveMR(Context* c, unsigned size, Assembler::Memory* a, Assembler::Register* b)
case 4: case 4:
case 8: case 8:
if (BytesPerWord == 4 and size == 8) { if (BytesPerWord == 4 and size == 8) {
moveMR(c, 4, a, b);
Assembler::Memory ah(a->base, a->offset + 4, a->index, a->scale); Assembler::Memory ah(a->base, a->offset + 4, a->index, a->scale);
Assembler::Register bh(b->high); Assembler::Register bh(b->high);
moveMR(c, 4, a, b);
moveMR(c, 4, &ah, &bh); moveMR(c, 4, &ah, &bh);
} else if (BytesPerWord == 8 and size == 4) { } else if (BytesPerWord == 8 and size == 4) {
encode(c, 0x63, b->low, a, true); encode(c, 0x63, b->low, a, true);
@ -393,6 +419,8 @@ populateTables()
UnaryOperations[INDEX1(Call, Constant)] = CAST1(callC); UnaryOperations[INDEX1(Call, Constant)] = CAST1(callC);
UnaryOperations[INDEX1(Jump, Register)] = CAST1(jumpR); UnaryOperations[INDEX1(Jump, Register)] = CAST1(jumpR);
UnaryOperations[INDEX1(Push, Register)] = CAST1(pushR);
UnaryOperations[INDEX1(Pop, Register)] = CAST1(popR);
BinaryOperations[INDEX2(Move, Constant, Register)] = CAST2(moveCR); BinaryOperations[INDEX2(Move, Constant, Register)] = CAST2(moveCR);
BinaryOperations[INDEX2(Move, Constant, Memory)] = CAST2(moveCM); BinaryOperations[INDEX2(Move, Constant, Memory)] = CAST2(moveCM);