1 //===-- CodeTemplate.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "CodeTemplate.h" 11 12 namespace exegesis { 13 14 CodeTemplate::CodeTemplate(CodeTemplate &&) = default; 15 16 CodeTemplate &CodeTemplate::operator=(CodeTemplate &&) = default; 17 18 InstructionTemplate::InstructionTemplate(const Instruction &Instr) 19 : Instr(Instr), VariableValues(Instr.Variables.size()) {} 20 21 InstructionTemplate::InstructionTemplate(InstructionTemplate &&) = default; 22 23 InstructionTemplate &InstructionTemplate:: 24 operator=(InstructionTemplate &&) = default; 25 26 InstructionTemplate::InstructionTemplate(const InstructionTemplate &) = default; 27 28 InstructionTemplate &InstructionTemplate:: 29 operator=(const InstructionTemplate &) = default; 30 31 unsigned InstructionTemplate::getOpcode() const { 32 return Instr.Description->getOpcode(); 33 } 34 35 llvm::MCOperand &InstructionTemplate::getValueFor(const Variable &Var) { 36 return VariableValues[Var.getIndex()]; 37 } 38 39 const llvm::MCOperand & 40 InstructionTemplate::getValueFor(const Variable &Var) const { 41 return VariableValues[Var.getIndex()]; 42 } 43 44 llvm::MCOperand &InstructionTemplate::getValueFor(const Operand &Op) { 45 return getValueFor(Instr.Variables[Op.getVariableIndex()]); 46 } 47 48 const llvm::MCOperand & 49 InstructionTemplate::getValueFor(const Operand &Op) const { 50 return getValueFor(Instr.Variables[Op.getVariableIndex()]); 51 } 52 53 bool InstructionTemplate::hasImmediateVariables() const { 54 return llvm::any_of(Instr.Variables, [this](const Variable &Var) { 55 return Instr.getPrimaryOperand(Var).isImmediate(); 56 }); 57 } 58 59 llvm::MCInst InstructionTemplate::build() const { 60 llvm::MCInst Result; 61 Result.setOpcode(Instr.Description->Opcode); 62 for (const auto &Op : Instr.Operands) 63 if (Op.isExplicit()) 64 Result.addOperand(getValueFor(Op)); 65 return Result; 66 } 67 68 } // namespace exegesis 69