def lookup(arch, cpu='', features='', opt=2, cm=CM_DEFAULT, reloc=RELOC_DEFAULT): '''create a targetmachine given an architecture name For a list of architectures, use: `llc -help` For a list of available CPUs, use: `llvm-as < /dev/null | llc -march=xyz -mcpu=help` For a list of available attributes (features), use: `llvm-as < /dev/null | llc -march=xyz -mattr=help` ''' triple = api.llvm.Triple.new() with contextlib.closing(BytesIO()) as error: target = api.llvm.TargetRegistry.lookupTarget(arch, triple, error) if not target: raise llvm.LLVMException(error.getvalue()) if not target.hasTargetMachine(): raise llvm.LLVMException(target, "No target machine.") target_options = api.llvm.TargetOptions.new() tm = target.createTargetMachine(str(triple), cpu, features, target_options, reloc, cm, opt) if not tm: raise llvm.LLVMException("Cannot create target machine") return TargetMachine(tm)
def remove_module(self, module): core.check_is_module(module) if module.owner != self: raise llvm.LLVMException("module is not owned by self") ret = _core.LLVMRemoveModule2(self.ptr, module.ptr) if isinstance(ret, str): raise llvm.LLVMException(ret) return core.Module(ret)
def _add_pass(self, pass_name): passreg = api.llvm.PassRegistry.getPassRegistry() a_pass = passreg.getPassInfo(pass_name).createPass() if not a_pass: assert pass_name not in PASSES, "Registered but not found?" raise llvm.LLVMException('Invalid pass name "%s"' % pass_name) self._ptr.add(a_pass)
def instr_analysis(self): if not getattr(self, '_mia', False): self._mia = self.target.createMCInstrAnalysis(self.instr_info) if not self._mia: raise llvm.LLVMException("no instr analysis for this machine") return self._mia
def add(self, tgt_data_or_pass_name): if isinstance(tgt_data_or_pass_name, ee.TargetData): self._add_target_data(tgt_data_or_pass_name) elif _util.isstring(tgt_data_or_pass_name): self._add_pass(tgt_data_or_pass_name) else: raise llvm.LLVMException("invalid pass_id (%s)" % tgt_data_or_pass_name)
def disassembler(self): if not getattr(self, '_dasm', False): self._dasm = self.target.createMCDisassembler(self.subtarget_info) if not self._dasm: raise llvm.LLVMException("no disassembler for this machine") return self._dasm
def new(module, force_interpreter=False): core.check_is_module(module) _util.check_is_unowned(module) ret = _core.LLVMCreateExecutionEngine(module.ptr, int(force_interpreter)) if isinstance(ret, str): raise llvm.LLVMException(ret) return ExecutionEngine(ret, module)
def inst_printer(self): if not getattr(self, '_mip', False): self._mip = self.target.createMCInstPrinter( self.asm_info.getAssemblerDialect(), self.asm_info, self.instr_info, self.reg_info, self.subtarget_info) if not self._mip: raise llvm.LLVMException("no instr printer for this machine") return self._mip
def new(triple='', cpu='', features='', opt=2, cm=CM_DEFAULT, reloc=RELOC_DEFAULT): if not triple: triple = get_default_triple() if not cpu: cpu = get_host_cpu_name() with contextlib.closing(BytesIO()) as error: target = api.llvm.TargetRegistry.lookupTarget(triple, error) if not target: raise llvm.LLVMException(error.getvalue()) if not target.hasTargetMachine(): raise llvm.LLVMException(target, "No target machine.") target_options = api.llvm.TargetOptions.new() tm = target.createTargetMachine(triple, cpu, features, target_options, reloc, cm, opt) if not tm: raise llvm.LLVMException("Cannot create target machine") return TargetMachine(tm)
def __init__(self, mcoperand, target_machine): ''' @mcoperand: an MCOperand object @target_machine: an llvm.target.TargetMachine object ''' self.op = mcoperand if not self.op: raise llvm.LLVMException("null MCOperand argument") self.tm = target_machine
def __init__(self, mcinst, target_machine): ''' @mcinst: an MCInst object @target_machine: an llvm.target.TargetMachine object ''' self.mcinst = mcinst if not self.mcinst: raise llvm.LLVMException("null MCInst argument") self.tm = target_machine
def check_is_unowned(ownable): if ownable.owner: raise llvm.LLVMException("object is already owned")
def _add_pass(self, pass_name): status = _core.LLVMAddPassByName(self.ptr, pass_name) if not status: assert pass_name not in PASSES, "Registered but not found?" raise llvm.LLVMException('Invalid pass name "%s"' % pass_name)
def instr_info(self): ii = self._ptr.getInstrInfo() if not ii: raise llvm.LLVMException("no instr info for this machine") return ii
def asm_info(self): ai = self._ptr.getMCAsmInfo() if not ai: raise llvm.LLVMException("no asm info for this machine") return ai
def subtarget_info(self): sti = self._ptr.getSubtargetImpl() if not sti: raise llvm.LLVMException("no subtarget info for this machine") return sti
def reg_info(self): mri = self._ptr.getRegisterInfo() if not mri: raise llvm.LLVMException("no reg info for this machine") return mri
def create(self): ret = _core.LLVMEngineBuilderCreate(self.ptr) if isinstance(ret, str): raise llvm.LLVMException(ret) return ExecutionEngine(ret, self._module)