summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Assembler/GekkoIRGen.h
blob: 00bf9dbdb530f9382bcda61e0543e51f955f537a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string_view>
#include <vector>

#include "Common/Assembler/AssemblerShared.h"
#include "Common/CommonTypes.h"

namespace Common::GekkoAssembler::detail
{
struct GekkoInstruction
{
  // Combination of a mnemonic index and variant:
  // (<GekkoMnemonic> << 2) | (<variant bits>)
  size_t mnemonic_index = 0;
  // Below refers to GekkoParseResult::operand_pool
  Interval op_interval = Interval{0, 0};
  // Literal text of this instruction
  std::string_view raw_text;
  size_t line_number = 0;
  bool is_extended = false;
};

using InstChunk = std::vector<GekkoInstruction>;
using ByteChunk = std::vector<u8>;
using PadChunk = size_t;
using ChunkVariant = std::variant<InstChunk, ByteChunk, PadChunk>;

struct IRBlock
{
  explicit IRBlock(u32 address) : block_address(address) {}

  u32 BlockEndAddress() const;

  std::vector<ChunkVariant> chunks;
  u32 block_address;
};

struct GekkoIR
{
  std::vector<IRBlock> blocks;
  std::vector<Tagged<Interval, u32>> operand_pool;
};

FailureOr<GekkoIR> ParseToIR(std::string_view assembly, u32 base_virtual_address);
}  // namespace Common::GekkoAssembler::detail