File tree Expand file tree Collapse file tree 7 files changed +125
-0
lines changed
Expand file tree Collapse file tree 7 files changed +125
-0
lines changed Original file line number Diff line number Diff line change @@ -28,3 +28,5 @@ target_sources(scratchcpp
2828 llvmexecutioncontext.cpp
2929 llvmexecutioncontext.h
3030)
31+
32+ add_subdirectory (instructions)
Original file line number Diff line number Diff line change 1+ target_sources (scratchcpp
2+ PRIVATE
3+ instructionbuilder.cpp
4+ instructionbuilder.h
5+ instructiongroup.cpp
6+ instructiongroup.h
7+ processresult.h
8+ )
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " instructionbuilder.h"
4+
5+ using namespace libscratchcpp ;
6+ using namespace libscratchcpp ::llvmins;
7+
8+ InstructionBuilder::InstructionBuilder (LLVMBuildUtils &utils)
9+ {
10+ // Create groups
11+ }
12+
13+ LLVMInstruction *InstructionBuilder::process (LLVMInstruction *ins)
14+ {
15+ // Process all groups
16+ for (const auto &group : m_groups) {
17+ ProcessResult result = group->process (ins);
18+
19+ if (result.match )
20+ return result.next ;
21+ }
22+
23+ assert (false ); // instruction not found
24+ return ins;
25+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include " instructiongroup.h"
6+
7+ namespace libscratchcpp ::llvmins
8+ {
9+
10+ class InstructionBuilder
11+ {
12+ public:
13+ InstructionBuilder (LLVMBuildUtils &utils);
14+
15+ LLVMInstruction *process (LLVMInstruction *ins);
16+
17+ private:
18+ std::vector<std::unique_ptr<InstructionGroup>> m_groups;
19+ };
20+
21+ } // namespace libscratchcpp::llvmins
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " instructiongroup.h"
4+ #include " ../llvmbuildutils.h"
5+
6+ using namespace libscratchcpp ::llvmins;
7+
8+ InstructionGroup::InstructionGroup (LLVMBuildUtils &utils) :
9+ m_utils(utils),
10+ m_builder(utils.builder())
11+ {
12+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include < llvm/IR/IRBuilder.h>
6+
7+ #include " processresult.h"
8+
9+ namespace libscratchcpp
10+ {
11+
12+ class LLVMBuildUtils ;
13+
14+ namespace llvmins
15+ {
16+
17+ class InstructionGroup
18+ {
19+ public:
20+ InstructionGroup (LLVMBuildUtils &utils);
21+
22+ virtual ProcessResult process (LLVMInstruction *ins) = 0;
23+
24+ protected:
25+ LLVMBuildUtils &m_utils;
26+ llvm::IRBuilder<> &m_builder;
27+ };
28+
29+ } // namespace llvmins
30+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ namespace libscratchcpp
6+ {
7+
8+ class LLVMInstruction ;
9+
10+ namespace llvmins
11+ {
12+
13+ // Result of group processing
14+ struct ProcessResult
15+ {
16+ ProcessResult (bool match, LLVMInstruction *next) :
17+ match (match),
18+ next (next)
19+ {
20+ }
21+
22+ bool match = false ; // whether the desired instruction was found
23+ LLVMInstruction *next = nullptr ; // next instruction (state)
24+ };
25+
26+ } // namespace llvmins
27+ } // namespace libscratchcpp
You can’t perform that action at this time.
0 commit comments