Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
        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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
        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
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
        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
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
def check_is_unowned(ownable):
    if ownable.owner:
        raise llvm.LLVMException("object is already owned")
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
        def instr_info(self):
            ii = self._ptr.getInstrInfo()
            if not ii:
                raise llvm.LLVMException("no instr info for this machine")

            return ii
Ejemplo n.º 15
0
        def asm_info(self):
            ai = self._ptr.getMCAsmInfo()
            if not ai:
                raise llvm.LLVMException("no asm info for this machine")

            return ai
Ejemplo n.º 16
0
        def subtarget_info(self):
            sti = self._ptr.getSubtargetImpl()
            if not sti:
                raise llvm.LLVMException("no subtarget info for this machine")

            return sti
Ejemplo n.º 17
0
        def reg_info(self):
            mri = self._ptr.getRegisterInfo()
            if not mri:
                raise llvm.LLVMException("no reg info for this machine")

            return mri
Ejemplo n.º 18
0
 def create(self):
     ret = _core.LLVMEngineBuilderCreate(self.ptr)
     if isinstance(ret, str):
         raise llvm.LLVMException(ret)
     return ExecutionEngine(ret, self._module)