1 /* This file is part of the dynarmic project.
2  * Copyright (c) 2016 MerryMage
3  * SPDX-License-Identifier: 0BSD
4  */
5 #pragma once
6 
7 #include "common/common_types.h"
8 
9 namespace Dynarmic::IR {
10 class Block;
11 } // namespace Dynarmic::IR
12 
13 namespace Dynarmic::A32 {
14 
15 class LocationDescriptor;
16 
17 using MemoryReadCodeFuncType = std::function<u32(u32 vaddr)>;
18 
19 struct TranslationOptions {
20     /// This changes what IR we emit when we translate an unpredictable instruction.
21     /// If this is false, the ExceptionRaised IR instruction is emitted.
22     /// If this is true, we define some behaviour for some instructions.
23     bool define_unpredictable_behaviour = false;
24 
25     /// This changes what IR we emit when we translate a hint instruction.
26     /// If this is false, we treat the instruction as a NOP.
27     /// If this is true, we emit an ExceptionRaised instruction.
28     bool hook_hint_instructions = true;
29 };
30 
31 /**
32  * This function translates instructions in memory into our intermediate representation.
33  * @param descriptor The starting location of the basic block. Includes information like PC, Thumb state, &c.
34  * @param memory_read_code The function we should use to read emulated memory.
35  * @param options Configures how certain instructions are translated.
36  * @return A translated basic block in the intermediate representation.
37  */
38 IR::Block Translate(LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code, const TranslationOptions& options);
39 
40 /**
41  * This function translates a single provided instruction into our intermediate representation.
42  * @param block The block to append the IR for the instruction to.
43  * @param descriptor The location of the instruction. Includes information like PC, Thumb state, &c.
44  * @param instruction The instruction to translate.
45  * @return The translated instruction translated to the intermediate representation.
46  */
47 bool TranslateSingleInstruction(IR::Block& block, LocationDescriptor descriptor, u32 instruction);
48 
49 } // namespace Dynarmic::A32
50