1 | //===-- DisassemblerHelper.cpp ----------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "DisassemblerHelper.h" |
10 | |
11 | #include "llvm/MC/TargetRegistry.h" |
12 | |
13 | namespace llvm { |
14 | namespace exegesis { |
15 | |
16 | DisassemblerHelper::DisassemblerHelper(const LLVMState &State) : State_(State) { |
17 | MCTargetOptions MCOptions; |
18 | const auto &TM = State.getTargetMachine(); |
19 | const auto &Triple = TM.getTargetTriple(); |
20 | AsmInfo_.reset(p: TM.getTarget().createMCAsmInfo(MRI: State_.getRegInfo(), |
21 | TheTriple: Triple.str(), Options: MCOptions)); |
22 | InstPrinter_.reset(p: TM.getTarget().createMCInstPrinter( |
23 | T: Triple, SyntaxVariant: 0 /*default variant*/, MAI: *AsmInfo_, MII: State_.getInstrInfo(), |
24 | MRI: State_.getRegInfo())); |
25 | |
26 | Context_ = std::make_unique<MCContext>( |
27 | args: Triple, args: AsmInfo_.get(), args: &State_.getRegInfo(), args: &State_.getSubtargetInfo()); |
28 | Disasm_.reset(p: TM.getTarget().createMCDisassembler(STI: State_.getSubtargetInfo(), |
29 | Ctx&: *Context_)); |
30 | assert(Disasm_ && "cannot create MCDisassembler. missing call to " |
31 | "InitializeXXXTargetDisassembler ?" ); |
32 | } |
33 | |
34 | } // namespace exegesis |
35 | } // namespace llvm |
36 | |