3 #include "jitcs_instructionstream.h"
4 #include "jitcs_dumper.h"
5 #include "jitcs_memmgr.h"
6 #include "jitcs_x86_32.h"
10 void Dump(IDumper
& d
, Slice
<u8
> mem
) {
11 size_t n
= mem
.size();
12 while (n
> 0 && mem
[n
- 1] == 0) --n
;
13 for (size_t i
= 0; i
< n
; ++i
) {
14 d
.writef("%02x", mem
[i
]);
17 d
.writef("%s00 * %d", n
> 0 ? " + " : "", mem
.size() - n
);
19 void Dump(IDumper
& d
, MemoryMgr::CodeAndData code
) {
20 d
.writef("Data %db: ", code
.data
.size());
23 d
.writef("Code %db: ", code
.code
.size());
28 static void test(UnitTest
& t
) {
29 typedef int (__cdecl
*FT0_c
)(int, int);
30 RefCounter
<IMachineInfo
> mi
= GetX86_32WinMachineInfo();
31 RefCounter
<TempAllocator
> alloc(new TempAllocator
);
32 RefCounter
<MemoryMgr
> mgr
= MemoryMgr::Create();
34 std::unique_ptr
<Function
> fn
= mi
->createFnc
<FT0_c
>(alloc
);
35 InstructionStreamBuffer
<256> ibuf
;
37 Ref
<BasicBlock
> bb1
= fn
->getStartBlock();
40 x86_32::MOV_WI(ibuf
, x86_32::EAX
, 0);
41 x86_32::ADD_WI(ibuf
, x86_32::EAX
, 1);
45 MemoryMgr::CodeAndData code
= fn
->generate(mgr
, Function::Direct_Code_Gen
);
49 std::string dumpresult
= dumper
.takeResult();
51 std::string expected
=
53 "Code 64b: b80000000083c001c3 + 00 * 55\n";
55 t
.check("x86_32/1", dumpresult
== expected
);
59 static UnitTestRun
_("SimpleCodeGen", test
);