blob: 3dfa534ae2cf19607a9eb78761c8b48c82fabf67 (
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
|
// SPDX-License-Identifier: GPL-3.0-or-later
#include "TableGenBackends.h"
#include <algorithm>
#include <ranges>
#include <sstream>
#include <string>
namespace rcc::targetgen {
std::string emitSearchableTables(const NormalizedTargetModel &Model) {
std::ostringstream Output;
const auto AssemblyInstructionCount =
std::ranges::count_if(Model.Instructions, [](const NormalizedInstruction &Instruction) {
return !Instruction.AssemblyMnemonic.empty();
});
Output << "constexpr std::array<AssemblyInstructionInfo, " << AssemblyInstructionCount
<< "> GeneratedAssemblyInstructions = {{\n";
for (const NormalizedInstruction &Instruction : Model.Instructions) {
if (Instruction.AssemblyMnemonic.empty())
continue;
Output << " {Opcode::fromValue(" << Instruction.ID << "), ";
appendQuoted(Output, Instruction.AssemblyMnemonic);
Output << ", AssemblyFormatID::fromValue(" << Instruction.AssemblyFormat << "), "
<< Instruction.BinaryEncoding << "},\n";
}
Output << "}};\n\n";
return Output.str();
}
} // namespace rcc::targetgen
|