1 //===-- DisassemblerHelper.cpp ----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "DisassemblerHelper.h"
11 #include "llvm/MC/TargetRegistry.h"
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(TM
.getTarget().createMCAsmInfo(State_
.getRegInfo(),
21 Triple
.str(), MCOptions
));
22 InstPrinter_
.reset(TM
.getTarget().createMCInstPrinter(
23 Triple
, 0 /*default variant*/, *AsmInfo_
, State_
.getInstrInfo(),
24 State_
.getRegInfo()));
26 Context_
= std::make_unique
<MCContext
>(
27 Triple
, AsmInfo_
.get(), &State_
.getRegInfo(), &State_
.getSubtargetInfo());
28 Disasm_
.reset(TM
.getTarget().createMCDisassembler(State_
.getSubtargetInfo(),
30 assert(Disasm_
&& "cannot create MCDisassembler. missing call to "
31 "InitializeXXXTargetDisassembler ?");
34 } // namespace exegesis