[LLVMdev] Asm output while executing

Álvaro Castro Castilla alvaro.castro.castilla at gmail.com
Wed May 28 13:21:29 PDT 2008


Hello,

I'm trying to catch assembly output and do some formatting for its
presentation while being executed.
I face a problem, which is clear from the error, although I have no
clue on how to do it otherwise.
If generating the code for its asm output and then for jit execution I get:

**********
static llvm::MachineFunction& llvm::MachineFunction::construct(const
llvm::Function*, const llvm::TargetMachine&): Assertion
`Fn->getAnnotation(MF_AID) == 0 && "Object already exists for this
function!"' failed.
**********

The code I use:


      /// The asm code output

      std::string Err;
      const llvm::TargetMachineRegistry::entry* MArch =
          llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*_module,Err);


      std::string FeaturesStr;
      std::auto_ptr<llvm::TargetMachine>target(MArch->CtorFn(*_module,FeaturesStr));
      assert(target.get() && "Could not allocate target machine!");
      llvm::TargetMachine &Target = *target.get();

      llvm::FunctionPassManager Passes(new
llvm::ExistingModuleProvider(_module));
      Passes.add(new llvm::TargetData(*Target.getTargetData()));

      std::ostringstream os;
      Target.addPassesToEmitFile(Passes,os,llvm::TargetMachine::AssemblyFile,
true);

      Passes.doInitialization();
      for (llvm::Module::iterator I = _module->begin(),
E=_module->end(); I != E; ++I)
        if (!I->isDeclaration())
        {
          Passes.run(*I);
        }
      Passes.doFinalization();

      /// The execution

      llvm::Function *inputFunction = _module->getFunction("function");
      std::vector<llvm::GenericValue> args(0);
      llvm::GenericValue result;
      result = _executionEngine->runFunction( inputFunction, args );

****

Thanks,


--

.alvaro.castro.castilla.



More information about the llvm-dev mailing list