Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 673:37a7688a7494

Show
Ignore:
Timestamp:
10/11/08 05:07:53 (3 months ago)
Author:
Christian Kamm <kamm incasoftware de>
branch:
default
Message:

Add basics for direct assembly output.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gen/toobj.cpp

    r663 r673  
    1515#include "llvm/Analysis/Verifier.h" 
    1616#include "llvm/Bitcode/ReaderWriter.h" 
     17#include "llvm/Target/SubtargetFeature.h" 
    1718#include "llvm/Target/TargetMachine.h" 
    1819#include "llvm/Target/TargetMachineRegistry.h" 
     20#include "llvm/Module.h" 
     21#include "llvm/ModuleProvider.h" 
     22#include "llvm/PassManager.h" 
    1923#include "llvm/System/Path.h" 
     24#include "llvm/Support/raw_ostream.h" 
    2025 
    2126#include "mars.h" 
     
    191196    } 
    192197 
     198 
     199    //TODO: Move all of this into a helper function? 
     200    if(false) 
     201    { 
     202        using namespace llvm; 
     203 
     204    //FIXME: Proper out file name. 
     205        std::string Err; 
     206        raw_fd_ostream Out("test.s", Err); 
     207        if(!Err.empty()) {} 
     208 
     209        const TargetMachineRegistry::entry* MArch; 
     210        MArch = TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, Err); 
     211        if (MArch == 0) { 
     212            error("error auto-selecting target for module '%s'", Err.c_str()); 
     213            fatal(); 
     214        } 
     215  
     216        SubtargetFeatures Features; 
     217    //TODO: Features? 
     218    //    Features.setCPU(MCPU); 
     219    //    for (unsigned i = 0; i != MAttrs.size(); ++i) 
     220    //      Features.AddFeature(MAttrs[i]); 
     221 
     222    //TODO: Set PIC if shared (or just do it always?) 
     223    //  TargetMachine::setRelocationModel(...); 
     224 
     225        std::auto_ptr<TargetMachine> target(MArch->CtorFn(*ir.module, Features.getString())); 
     226        assert(target.get() && "Could not allocate target machine!"); 
     227        TargetMachine &Target = *target.get(); 
     228 
     229        // Build up all of the passes that we want to do to the module. 
     230        ExistingModuleProvider Provider(ir.module); 
     231        FunctionPassManager Passes(&Provider); 
     232    //FIXME does this TargetData match gTargetData? 
     233        Passes.add(new TargetData(*Target.getTargetData())); 
     234 
     235        // Ask the target to add backend passes as necessary. 
     236        MachineCodeEmitter *MCE = 0; 
     237 
     238    //TODO: May want to switch it on for -O0? 
     239        bool Fast = false; 
     240        FileModel::Model mod = Target.addPassesToEmitFile(Passes, Out, TargetMachine::AssemblyFile, Fast); 
     241        assert(mod == FileModel::AsmFile); 
     242 
     243        bool err = Target.addPassesToEmitFileFinish(Passes, MCE, Fast); 
     244        assert(!err); 
     245 
     246        Passes.doInitialization(); 
     247 
     248        // Run our queue of passes all at once now, efficiently. 
     249        for (llvm::Module::iterator I = ir.module->begin(), E = ir.module->end(); I != E; ++I) 
     250        if (!I->isDeclaration()) 
     251            Passes.run(*I); 
     252 
     253        Passes.doFinalization(); 
     254 
     255        // release module from module provider so we can delete it ourselves 
     256        llvm::Module* rmod = Provider.releaseModule(&Err); 
     257        assert(rmod); 
     258    } 
     259 
    193260    delete ir.module; 
    194261    gTargetData = 0; 
  • premake.lua

    r663 r673  
    5656package.linkoptions = { 
    5757    -- long but it's faster than just 'all' 
    58     "`llvm-config --libs bitwriter linker ipo instrumentation`", 
     58    "`llvm-config --libs bitwriter linker ipo instrumentation backend`", 
    5959    "`llvm-config --ldflags`", 
    6060} 
Copyright © 2008, LDC Development Team.