|
30 | 30 | #include <llvm/IR/IRBuilder.h> |
31 | 31 | #include <remill/BC/InstructionLifter.h> |
32 | 32 | #include <remill/BC/IntrinsicTable.h> |
| 33 | +#include <remill/Arch/Context.h> |
33 | 34 |
|
34 | 35 | #pragma clang diagnostic pop |
35 | 36 |
|
@@ -170,6 +171,9 @@ class Arch { |
170 | 171 |
|
171 | 172 | virtual ~Arch(void); |
172 | 173 |
|
| 174 | + |
| 175 | + virtual DecodingContext CreateInitialContext(void) const = 0; |
| 176 | + |
173 | 177 | // Factory method for loading the correct architecture class for a given |
174 | 178 | // operating system and architecture class. |
175 | 179 | static auto Get(llvm::LLVMContext &context, std::string_view os, |
@@ -281,14 +285,23 @@ class Arch { |
281 | 285 | // walk up, one byte at a time, to `MaxInstructionSize(false)` |
282 | 286 | // bytes being passed to the decoder, until you successfully decode |
283 | 287 | // or ultimately fail. |
284 | | - virtual bool DecodeInstruction(uint64_t address, std::string_view instr_bytes, |
285 | | - Instruction &inst) const = 0; |
| 288 | + |
| 289 | + // The decoder takes contextual information in the form of a DecodingContext, making a copy to produce a ContextMap which is a function that maps |
| 290 | + // a successor to a new context that updates the old context. |
| 291 | + |
| 292 | + using DecodingResult = std::optional<DecodingContext::ContextMap>; |
| 293 | + |
| 294 | + virtual DecodingResult |
| 295 | + DecodeInstruction(uint64_t address, std::string_view instr_bytes, |
| 296 | + Instruction &inst, DecodingContext context) const = 0; |
286 | 297 |
|
287 | 298 | // Decode an instruction that is within a delay slot. |
288 | | - bool DecodeDelayedInstruction(uint64_t address, std::string_view instr_bytes, |
289 | | - Instruction &inst) const { |
| 299 | + DecodingResult |
| 300 | + DecodeDelayedInstruction(uint64_t address, std::string_view instr_bytes, |
| 301 | + Instruction &inst, DecodingContext context) const { |
290 | 302 | inst.in_delay_slot = true; |
291 | | - return this->DecodeInstruction(address, instr_bytes, inst); |
| 303 | + return this->DecodeInstruction(address, instr_bytes, inst, |
| 304 | + std::move(context)); |
292 | 305 | } |
293 | 306 |
|
294 | 307 | // Minimum alignment of an instruction for this particular architecture. |
|
0 commit comments