Initial implementation of a flow-graph builder for Dart's AST.
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
2012-02-22 15:20:13 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// 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/assembler.h"
|
|
|
|
#include "vm/instructions.h"
|
2014-02-10 12:18:06 +00:00
|
|
|
#include "vm/object.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/stub_code.h"
|
|
|
|
#include "vm/unit_test.h"
|
2014-02-10 12:18:06 +00:00
|
|
|
#include "vm/virtual_memory.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
#define __ assembler->
|
|
|
|
|
|
|
|
ASSEMBLER_TEST_GENERATE(Call, assembler) {
|
2014-07-07 21:25:00 +00:00
|
|
|
StubCode* stub_code = Isolate::Current()->stub_code();
|
|
|
|
__ call(&stub_code->InvokeDartCodeLabel());
|
2011-10-05 05:20:07 +00:00
|
|
|
__ ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 23:55:31 +00:00
|
|
|
ASSEMBLER_TEST_RUN(Call, test) {
|
2014-07-07 21:25:00 +00:00
|
|
|
StubCode* stub_code = Isolate::Current()->stub_code();
|
2013-02-15 23:55:31 +00:00
|
|
|
CallPattern call(test->entry());
|
2014-07-07 21:25:00 +00:00
|
|
|
EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(),
|
2012-08-10 23:33:37 +00:00
|
|
|
call.TargetAddress());
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASSEMBLER_TEST_GENERATE(Jump, assembler) {
|
2014-07-07 21:25:00 +00:00
|
|
|
StubCode* stub_code = Isolate::Current()->stub_code();
|
|
|
|
__ jmp(&stub_code->InvokeDartCodeLabel());
|
|
|
|
__ jmp(&stub_code->AllocateArrayLabel());
|
2011-10-05 05:20:07 +00:00
|
|
|
__ ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 23:55:31 +00:00
|
|
|
ASSEMBLER_TEST_RUN(Jump, test) {
|
2014-02-10 12:18:06 +00:00
|
|
|
const Code& code = test->code();
|
|
|
|
const Instructions& instrs = Instructions::Handle(code.instructions());
|
2014-07-07 21:25:00 +00:00
|
|
|
StubCode* stub_code = Isolate::Current()->stub_code();
|
2014-02-10 12:18:06 +00:00
|
|
|
bool status =
|
|
|
|
VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()),
|
|
|
|
instrs.size(),
|
|
|
|
VirtualMemory::kReadWrite);
|
|
|
|
EXPECT(status);
|
2013-09-09 15:39:26 +00:00
|
|
|
JumpPattern jump1(test->entry(), test->code());
|
2014-07-07 21:25:00 +00:00
|
|
|
EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(),
|
2011-10-05 05:20:07 +00:00
|
|
|
jump1.TargetAddress());
|
2013-09-09 15:39:26 +00:00
|
|
|
JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(),
|
|
|
|
test->code());
|
2014-07-07 21:25:00 +00:00
|
|
|
EXPECT_EQ(stub_code->AllocateArrayLabel().address(),
|
2011-10-05 05:20:07 +00:00
|
|
|
jump2.TargetAddress());
|
|
|
|
uword target1 = jump1.TargetAddress();
|
|
|
|
uword target2 = jump2.TargetAddress();
|
|
|
|
jump1.SetTargetAddress(target2);
|
|
|
|
jump2.SetTargetAddress(target1);
|
2014-07-07 21:25:00 +00:00
|
|
|
EXPECT_EQ(stub_code->AllocateArrayLabel().address(),
|
2011-10-05 05:20:07 +00:00
|
|
|
jump1.TargetAddress());
|
2014-07-07 21:25:00 +00:00
|
|
|
EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(),
|
2011-10-05 05:20:07 +00:00
|
|
|
jump2.TargetAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
|
|
|
#endif // defined TARGET_ARCH_IA32
|