mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 04:29:21 +00:00
Convert jello to use PassManager
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4414 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
055c965bff
commit
083ee69349
@ -9,10 +9,10 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/CodeGen/MFunction.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "../lib/Target/X86/X86.h" // FIXME: become generic eventually
|
#include "llvm/Target/TargetMachineImpls.h"
|
||||||
#include "../lib/Target/X86/X86InstructionInfo.h"
|
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
|
|
||||||
@ -25,52 +25,39 @@ namespace {
|
|||||||
cl::value_desc("function name"));
|
cl::value_desc("function name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// ExecuteFunction - Compile the specified function to machine code, and
|
|
||||||
/// execute it.
|
|
||||||
///
|
|
||||||
static void ExecuteFunction(Function &F) {
|
|
||||||
X86InstructionInfo II;
|
|
||||||
|
|
||||||
// Perform instruction selection to turn the function into an x86 SSA form
|
|
||||||
MFunction *MF = X86SimpleInstructionSelection(F);
|
|
||||||
|
|
||||||
// TODO: optional optimizations go here
|
|
||||||
|
|
||||||
// If -debug is specified, output selected code to stderr
|
|
||||||
/*DEBUG*/(MF->print(std::cerr, II));
|
|
||||||
|
|
||||||
// Perform register allocation to convert to a concrete x86 representation
|
|
||||||
X86SimpleRegisterAllocation(MF);
|
|
||||||
|
|
||||||
// If -debug is specified, output compiled code to stderr
|
|
||||||
/*DEBUG*/(X86PrintCode(MF, std::cerr));
|
|
||||||
|
|
||||||
// Emit register allocated X86 code now...
|
|
||||||
void *PFun = X86EmitCodeToMemory(MF);
|
|
||||||
|
|
||||||
// We don't need the machine specific representation for this function anymore
|
|
||||||
delete MF;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// main Driver function
|
// main Driver function
|
||||||
//
|
//
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
|
||||||
|
|
||||||
std::string ErrorMsg;
|
// Allocate a target... in the future this will be controllable on the
|
||||||
if (Module *M = ParseBytecodeFile(InputFile, &ErrorMsg)) {
|
// command line.
|
||||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
std::auto_ptr<TargetMachine> target(allocateX86TargetMachine());
|
||||||
if (I->getName() == MainFunction)
|
assert(target.get() && "Could not allocate target machine!");
|
||||||
ExecuteFunction(*I);
|
|
||||||
|
|
||||||
delete M;
|
TargetMachine &Target = *target.get();
|
||||||
return 0;
|
|
||||||
|
// Parse the input bytecode file...
|
||||||
|
std::string ErrorMsg;
|
||||||
|
std::auto_ptr<Module> M(ParseBytecodeFile(InputFile, &ErrorMsg));
|
||||||
|
if (M.get() == 0) {
|
||||||
|
std::cerr << argv[0] << ": bytecode '" << InputFile
|
||||||
|
<< "' didn't read correctly: << " << ErrorMsg << "\n";
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PassManager Passes;
|
||||||
|
if (Target.addPassesToJITCompile(Passes)) {
|
||||||
|
std::cerr << argv[0] << ": target '" << Target.TargetName
|
||||||
|
<< "' doesn't support JIT compilation!\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// JIT all of the methods in the module. Eventually this will JIT functions
|
||||||
|
// on demand.
|
||||||
|
Passes.run(*M.get());
|
||||||
|
|
||||||
std::cerr << "Error parsing '" << InputFile << "': " << ErrorMsg << "\n";
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user