mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4789 91177308-0d34-0410-b5e6-96231b3b80d8
35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
//===- ExtractFunction.cpp - Extract a function from Program --------------===//
|
|
//
|
|
// This file implements a method that extracts a function from program, cleans
|
|
// it up, and returns it as a new module.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "BugDriver.h"
|
|
#include "llvm/Module.h"
|
|
#include "llvm/PassManager.h"
|
|
#include "llvm/Transforms/IPO.h"
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
|
|
|
/// extractFunctionFromModule - This method is used to extract the specified
|
|
/// (non-external) function from the current program, slim down the module, and
|
|
/// then return it. This does not modify Program at all, it modifies a copy,
|
|
/// which it returns.
|
|
Module *BugDriver::extractFunctionFromModule(Function *F) const {
|
|
Module *Result = CloneModule(Program);
|
|
|
|
// Translate from the old module to the new copied module...
|
|
F = Result->getFunction(F->getName(), F->getFunctionType());
|
|
|
|
// In addition to just parsing the input from GCC, we also want to spiff it up
|
|
// a little bit. Do this now.
|
|
//
|
|
PassManager Passes;
|
|
Passes.add(createFunctionExtractionPass(F)); // Extract the function
|
|
Passes.add(createGlobalDCEPass()); // Delete unreachable globals
|
|
Passes.add(createFunctionResolvingPass()); // Delete prototypes
|
|
Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
|
|
Passes.run(*Result);
|
|
return Result;
|
|
}
|