Added DF annotation to final RET of as files. Also, skipped labels when
[jitcs.git] / tests / test_asm.h
blob1a05413c8b9465506c4c3bdd5b2f62987fb746fe
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"
8 #include "unittest.h"
9 #include "jitcs_tmpalloc.h"
10 #include "jitcs_memref.h"
11 #include <vector>
12 #include <string>
13 #include <map>
14 #include <memory>
15 #include <unordered_set>
17 namespace jitcs {
18 class IMachineInfo;
19 class MemoryMgr;
20 class Function;
21 class BasicBlock;
22 class TempAllocator;
23 struct VirtualRegister;
26 struct TestAssembler {
27 bool setup;
28 std::string filename, funcname;
29 size_t lineno;
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();
50 void clear();
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;
60 protected:
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);
67 #endif
68 // _JITCS_TESTS_TESTASM_H_