3 #include "jitcs_instructionstream.h"
9 static void test(UnitTest
& t
) {
10 typedef int (__cdecl
*FT0_c
)(int, int);
11 RefCounter
<IMachineInfo
> mi
= host::GetMachineInfo();
12 RefCounter
<TempAllocator
> alloc(new TempAllocator
);
14 std::unique_ptr
<Function
> fn
= mi
->createFnc
<FT0_c
>(alloc
);
15 InstructionStreamBuffer
<256> ibuf
;
16 Ref
<VirtualRegister
> param0
= fn
->getArgumentRegister(0, host::RCL_GR
);
17 Ref
<VirtualRegister
> param1
= fn
->getArgumentRegister(1, host::RCL_GR
);
18 Ref
<VirtualRegister
> result0
= fn
->getResultRegister(0, host::RCL_GR
);
19 Ref
<BasicBlock
> bb1
= fn
->getStartBlock();
20 Ref
<BasicBlock
> bb2
= fn
->createBasicBlock();
21 Ref
<BasicBlock
> bb3
= fn
->createBasicBlock();
23 host::CMP_RR(ibuf
, param0
, param1
);
24 host::JGE_BB_FT(ibuf
, bb2
, bb3
);
28 host::MOV_RR(ibuf
, result0
, param0
);
33 host::MOV_RR(ibuf
, result0
, param1
);
38 Enumerator
<const BasicBlock
> enumbb
= fn
->enumerateBasicBlocks();
39 size_t c
= 0, c1
= 0, c2
= 0, c3
= 0;
40 while (!enumbb
.empty()) {
41 const BasicBlock
& bb
= enumbb
.front();
43 if (&bb
== bb1
._ptr
) ++c1
;
44 if (&bb
== bb2
._ptr
) ++c2
;
45 if (&bb
== bb3
._ptr
) ++c3
;
47 t
.check("Build/Enumerate basic blocks", c1
== 1 && c2
== 1 && c3
== 1 && c
== 3);
50 Enumerator
<const Instruction
> enumins
= bb1
->instructions();
52 ok
= !enumins
.empty();
54 const Instruction
& ins
= enumins
.front();
55 ok
= ok
&& (ins
.getInsId() == host::I_CMP_RR
);
57 t
.check("Build/Enumerate instructions on BB1/1", ok
);
58 ok
= ok
&& !enumins
.empty();
60 const Instruction
& ins
= enumins
.front();
61 ok
= ok
&& (ins
.getInsId() == host::I_JGE_BB_FT
);
63 t
.check("Build/Enumerate instructions on BB1/2", ok
);
64 ok
= ok
&& enumins
.empty();
65 t
.check("Build/Enumerate instructions on BB1/3", ok
);
68 Enumerator
<const BasicBlock
> predbb
= bb1
->predecessors();
69 Enumerator
<const BasicBlock
> succbb
= bb1
->successors();
70 t
.check("Build/Pred+succ are empty before CFG fix", predbb
.empty() && succbb
.empty());
72 t
.check("Fixing CFG not implemented", false);
73 t
.check("Generating code not implemented", false);
74 t
.check("Running function not implemented", false);
78 static UnitTestRun
_("SimpleFunction", test
);