1 #ifndef _JITCS_TESTS_TESTASM_H_
2 #define _JITCS_TESTS_TESTASM_H_
4 #include "jitcs_base.h"
5 #include "jitcs_adt_ref.h"
6 #include "jitcs_adt_refcounter.h"
7 #include "jitcs_instructionstream.h"
9 #include "jitcs_tmpalloc.h"
10 #include "jitcs_memref.h"
15 #include <unordered_set>
23 struct VirtualRegister
;
26 struct TestAssembler
{
28 std::string filename
, funcname
;
30 std::vector
<jitcs::u8
> outbytes
;
31 jitcs::RefCounter
<jitcs::IMachineInfo
> mi
;
32 jitcs::RefCounter
<jitcs::MemoryMgr
> mem
;
33 jitcs::RefCounter
<jitcs::TempAllocator
> alloc
;
34 std::unique_ptr
<jitcs::Function
> fnc
;
35 jitcs::RefOrNull
<jitcs::BasicBlock
> curbb
;
36 jitcs::InstructionStreamBuffer
<256> ibuf
;
37 std::map
<std::string
, jitcs::BasicBlock
*> bbnames
;
38 std::map
<std::string
, const jitcs::VirtualRegister
*> vrnames
;
39 jitcs::StreamAllocator
<jitcs::MemoryReference
>* memstream
;
41 std::map
<std::string
, jitcs::u32
> constinsnames
;
42 std::map
<std::string
, jitcs::u32
> constrcnames
;
43 std::map
<std::string
, const jitcs::VirtualRegister
*> constvrnames
;
45 TestAssembler(jitcs::RefCounter
<jitcs::MemoryMgr
> m
,
46 jitcs::RefCounter
<jitcs::TempAllocator
> a
,
47 jitcs::RefCounter
<jitcs::IMachineInfo
> mi
);
48 virtual ~TestAssembler();
51 const jitcs::VirtualRegister
* findReg(std::string
const& n
);
52 void checkFile(jitcs::UnitTest
&, std::string
const& filename
,
53 std::unordered_set
<jitcs::u32
>* used_insids
= nullptr,
54 std::string
const& outputfile
= "");
56 virtual void setupInstructionNames(std::map
<std::string
, jitcs::u32
>&) = 0;
57 virtual void setupRegisterClassNames(std::map
<std::string
, jitcs::u32
>&) = 0;
58 virtual void setupFixedRegisterNames(std::map
<std::string
, const jitcs::VirtualRegister
*>&) = 0;
59 virtual const char* addInstruction(jitcs::u32 insid
, std::vector
<std::string
> const& parms
) = 0;
61 bool _runTest(jitcs::UnitTest
& t
, std::string
const& outputfile
);
62 void _error(jitcs::UnitTest
& t
, std::string
const& msg
);
63 static std::string
toLower(std::string
const& z
);
64 static void split(std::string
const& line
, std::string
const& splitter
, std::string
& pin
, std::string
& pout
);
65 static void split(std::string
const& line
, std::string
const& splitter
, std::vector
<std::string
>& parts
);
68 // _JITCS_TESTS_TESTASM_H_