41e77a0a9e
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.
The flow graph for the simple function:
main() {
var f = 1;
var n = 5;
while (n > 0) {
f = f * n;
n = n - 1;
}
print(f);
}
is:
1: StoreLocal(f, #1)
2: StoreLocal(n, #5)
3: [join]
4: t0 <-LoadLocal(n)
5: t0 <-InstanceCall(>, t0, #0)
6: if t0 goto(7, 15)
7: [target]
8: t0 <-LoadLocal(f)
9: t1 <-LoadLocal(n)
10: t0 <-InstanceCall(*, t0, t1)
11: StoreLocal(f, t0)
12: t0 <-LoadLocal(n)
13: t0 <-InstanceCall(-, t0, #1)
14: StoreLocal(n, t0) goto 3
15: [target]
16: t0 <-LoadLocal(f)
17: StaticCall(print, t0)
18: return #null
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com//9414003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/globals.h"
|
|
#if defined(TARGET_ARCH_IA32)
|
|
|
|
#include "vm/instructions.h"
|
|
#include "vm/isolate.h"
|
|
#include "vm/stack_frame.h"
|
|
|
|
namespace dart {
|
|
|
|
// The constant kExitLinkOffsetInEntryFrame must be kept in sync with the
|
|
// code in the InvokeDartCode stub.
|
|
static const int kExitLinkOffsetInEntryFrame = -4 * kWordSize;
|
|
static const int kPcAddressOffsetFromSp = -1 * kWordSize;
|
|
static const int kSpOffsetFromPreviousFp = 2 * kWordSize;
|
|
|
|
|
|
static bool ExitedFromStub(uword exit_marker) {
|
|
if (exit_marker != 0) {
|
|
uword caller_pc = *reinterpret_cast<uword*>(exit_marker + kWordSize);
|
|
uword call_instr_pc = caller_pc - CallPattern::InstructionLength();
|
|
uword call_target = CallPattern(call_instr_pc).TargetAddress();
|
|
return StubCode::InStubCallToRuntimeStubCode(call_target);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
intptr_t StackFrame::PcAddressOffsetFromSp() {
|
|
return kPcAddressOffsetFromSp;
|
|
}
|
|
|
|
|
|
uword StackFrame::GetCallerSp() const {
|
|
return fp() + kSpOffsetFromPreviousFp;
|
|
}
|
|
|
|
|
|
uword StackFrame::GetCallerFp() const {
|
|
return *(reinterpret_cast<uword*>(fp()));
|
|
}
|
|
|
|
|
|
intptr_t EntryFrame::ExitLinkOffset() {
|
|
return kExitLinkOffsetInEntryFrame;
|
|
}
|
|
|
|
|
|
void StackFrameIterator::SetupLastExitFrameData() {
|
|
Isolate* current = Isolate::Current();
|
|
uword exit_marker = current->top_exit_frame_info();
|
|
frames_.fp_ = exit_marker;
|
|
frames_.from_stub_exitframe_ = ExitedFromStub(exit_marker);
|
|
}
|
|
|
|
|
|
void StackFrameIterator::SetupNextExitFrameData() {
|
|
uword exit_address = entry_.fp() + kExitLinkOffsetInEntryFrame;
|
|
uword exit_marker = *reinterpret_cast<uword*>(exit_address);
|
|
frames_.fp_ = exit_marker;
|
|
frames_.from_stub_exitframe_ = ExitedFromStub(exit_marker);
|
|
frames_.sp_ = 0;
|
|
}
|
|
|
|
} // namespace dart
|
|
|
|
#endif // defined TARGET_ARCH_IA32
|