File tree Expand file tree Collapse file tree
src/engine/internal/codegen Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ target_sources(scratchcpp
55 codebuilderfactory.cpp
66 codebuilderfactory.h
77 instruction.h
8+ instructionlist.h
89)
910
1011add_subdirectory (llvm )
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include < memory>
6+ #include < functional>
7+
8+ #include " test_export.h"
9+
10+ namespace libscratchcpp
11+ {
12+
13+ template <typename TInstruction>
14+ class LIBSCRATCHCPP_TEST_EXPORT InstructionList
15+ {
16+ public:
17+ InstructionList () = default ;
18+ InstructionList (const InstructionList &) = delete ;
19+
20+ inline TInstruction *first () const { return m_first.get (); }
21+
22+ inline TInstruction *last () const { return m_last.get (); }
23+
24+ inline bool empty () const { return !first (); }
25+
26+ inline bool containsInstruction (TInstruction *ins) const
27+ {
28+ TInstruction *ptr = m_first.get ();
29+
30+ while (ptr) {
31+ if (ptr == ins)
32+ return true ;
33+
34+ ptr = ptr->next ;
35+ }
36+
37+ return false ;
38+ }
39+
40+ inline bool containsInstruction (std::function<bool (const TInstruction *)> func) const
41+ {
42+ TInstruction *ptr = m_first.get ();
43+
44+ while (ptr) {
45+ if (func (ptr))
46+ return true ;
47+
48+ ptr = ptr->next ;
49+ }
50+
51+ return false ;
52+ }
53+
54+ inline void addInstruction (std::shared_ptr<TInstruction> ins)
55+ {
56+ if (!(m_first && m_last)) {
57+ assert (!m_first && !m_last);
58+
59+ m_first = ins;
60+ m_last = ins;
61+
62+ ins->previous = nullptr ;
63+ ins->next = nullptr ;
64+ ins->_next = nullptr ;
65+ } else {
66+ m_last->next = ins.get ();
67+ m_last->_next = ins;
68+ ins->previous = m_last.get ();
69+ m_last = ins;
70+ }
71+ }
72+
73+ private:
74+ std::shared_ptr<TInstruction> m_first;
75+ std::shared_ptr<TInstruction> m_last;
76+ };
77+
78+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ target_sources(scratchcpp
99 llvmregister.h
1010 llvmconstantregister.h
1111 llvminstruction.h
12- llvminstructionlist.cpp
1312 llvminstructionlist.h
1413 llvmifstatement.h
1514 llvmloop.h
Original file line number Diff line number Diff line change 66#include < unordered_map>
77
88#include " test_export.h"
9+ #include " llvminstructionlist.h"
910
1011namespace libscratchcpp
1112{
1213
1314class LLVMBuildUtils ;
14- class LLVMInstructionList ;
1515class LLVMInstruction ;
1616
1717class LIBSCRATCHCPP_TEST_EXPORT LLVMCodeAnalyzer
Load diff This file was deleted.
Original file line number Diff line number Diff line change 22
33#pragma once
44
5- #include < memory>
6- #include < functional>
7-
8- #include " test_export.h"
5+ #include " ../instructionlist.h"
96
107namespace libscratchcpp
118{
129
1310struct LLVMInstruction ;
1411
15- class LIBSCRATCHCPP_TEST_EXPORT LLVMInstructionList
16- {
17- public:
18- LLVMInstructionList () = default ;
19- LLVMInstructionList (const LLVMInstructionList &) = delete ;
20-
21- LLVMInstruction *first () const ;
22- LLVMInstruction *last () const ;
23-
24- bool empty () const { return !first (); }
25-
26- bool containsInstruction (LLVMInstruction *ins) const ;
27- bool containsInstruction (std::function<bool (const LLVMInstruction *)> func) const ;
28-
29- void addInstruction (std::shared_ptr<LLVMInstruction> ins);
30-
31- private:
32- std::shared_ptr<LLVMInstruction> m_first;
33- std::shared_ptr<LLVMInstruction> m_last;
34- };
12+ using LLVMInstructionList = InstructionList<LLVMInstruction>;
3513
3614} // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ add_executable(
1919 codebuilder_test.cpp
2020 codegentestutils.cpp
2121 codegentestutils.h
22+ instructionlist_test.cpp
2223 operators/equal_comparison_test.cpp
2324 operators/greater_than_test.cpp
2425 operators/less_than_test.cpp
You can’t perform that action at this time.
0 commit comments