mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 17:43:57 +00:00
Driver and options for the llc compiler.
llvm-svn: 234
This commit is contained in:
parent
656823944e
commit
2d94a344f0
125
llvm/tools/llc/LLCOptions.cpp
Normal file
125
llvm/tools/llc/LLCOptions.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
// $Id$
|
||||||
|
//**************************************************************************/
|
||||||
|
// File:
|
||||||
|
// LLCOptions.cpp
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// Options for the llc compiler.
|
||||||
|
//
|
||||||
|
// History:
|
||||||
|
// 7/15/01 - Vikram Adve - Created
|
||||||
|
//
|
||||||
|
//**************************************************************************/
|
||||||
|
|
||||||
|
//************************** System Include Files **************************/
|
||||||
|
|
||||||
|
#include <iostream.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
//*************************** User Include Files ***************************/
|
||||||
|
|
||||||
|
#include "llvm/Support/ProgramOptions.h"
|
||||||
|
#include "llvm/Support/ProgramOption.h"
|
||||||
|
#include "llvm/LLC/LLCOptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// class LLCOptions
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*ctor*/
|
||||||
|
LLCOptions::LLCOptions (int _argc,
|
||||||
|
const char* _argv[],
|
||||||
|
const char* _envp[])
|
||||||
|
: ProgramOptions(_argc, _argv, _envp)
|
||||||
|
{
|
||||||
|
InitializeOptions();
|
||||||
|
ParseArgs(argc, argv, envp);
|
||||||
|
CheckParse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*dtor*/
|
||||||
|
LLCOptions::~LLCOptions()
|
||||||
|
{}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// Initialize all our compiler options
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
void
|
||||||
|
LLCOptions::InitializeOptions()
|
||||||
|
{
|
||||||
|
Register(new FlagOption(HELP_OPT,
|
||||||
|
"print usage message",
|
||||||
|
false /*initValue*/));
|
||||||
|
|
||||||
|
Register(new FlagOption(DEBUG_OPT,
|
||||||
|
"turn on default debugging options",
|
||||||
|
false /*initValue*/));
|
||||||
|
|
||||||
|
Register(new FlagOption(DEBUG_OPT,
|
||||||
|
"turn off all diagnostic messages",
|
||||||
|
false /*initValue*/));
|
||||||
|
|
||||||
|
Register(new StringOption(OUTFILENAME_OPT,
|
||||||
|
"output file name",
|
||||||
|
"" /*initValue*/));
|
||||||
|
|
||||||
|
Register(new IntegerValuedOption(DEBUG_INSTR_SELECT_OPT,
|
||||||
|
"control amount of debugging information for instruction selection",
|
||||||
|
0 /*initValue*/));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LLCOptions::ParseExtraArgs()
|
||||||
|
{
|
||||||
|
if (argsConsumed != argc-1)
|
||||||
|
Usage();
|
||||||
|
|
||||||
|
// input file name should be the last argument
|
||||||
|
inputFileName = argv[argc-1];
|
||||||
|
|
||||||
|
// output file name may be specified with -o option;
|
||||||
|
// otherwise create it from the input file name by replace ".ll" with ".o"
|
||||||
|
const char* outfilenameOpt = this->StringOptionValue(OUTFILENAME_OPT);
|
||||||
|
if (outfilenameOpt)
|
||||||
|
{// "-o" option was used
|
||||||
|
outputFileName = outfilenameOpt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outputFileName = inputFileName;
|
||||||
|
unsigned int suffixPos = outputFileName.rfind(".bc");
|
||||||
|
|
||||||
|
if (suffixPos >= outputFileName.length())
|
||||||
|
suffixPos = outputFileName.rfind(".ll");
|
||||||
|
|
||||||
|
if (suffixPos >= outputFileName.length())
|
||||||
|
{
|
||||||
|
cerr << "Unrecognized suffix in file name " << inputFileName << endl;
|
||||||
|
Usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
outputFileName.replace(suffixPos, 3, ".o");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// Functions that must be overridden in subclass of ProgramOptions
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
void
|
||||||
|
LLCOptions::CheckParse()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
LLCOptions::PrintUsage(ostream& stream) const
|
||||||
|
{
|
||||||
|
stream << "\nUSAGE:\n\t" << ProgramName() << " [options] "
|
||||||
|
<< "llvm-file" << endl << endl;
|
||||||
|
PrintOptions(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
23
llvm/tools/llc/Makefile
Normal file
23
llvm/tools/llc/Makefile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
LEVEL = ../..
|
||||||
|
|
||||||
|
DIRS =
|
||||||
|
|
||||||
|
LIBRARYNAME = llc
|
||||||
|
|
||||||
|
## List source files in link order
|
||||||
|
Source = \
|
||||||
|
llc.o \
|
||||||
|
LLCOptions.o
|
||||||
|
|
||||||
|
include $(LEVEL)/Makefile.common
|
||||||
|
|
||||||
|
all:: llc
|
||||||
|
|
||||||
|
clean::
|
||||||
|
rm -f llc
|
||||||
|
|
||||||
|
llc : $(ObjectsG) $(LibsG)
|
||||||
|
$(LinkG) -o $@ -static \
|
||||||
|
-lllc -lselect -lsparc -ltarget \
|
||||||
|
-lopt -lbcreader -lbcwriter \
|
||||||
|
-lvmcore -lasmwriter -lanalysis -lsupport
|
103
llvm/tools/llc/llc.cpp
Normal file
103
llvm/tools/llc/llc.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// $Id$
|
||||||
|
//***************************************************************************
|
||||||
|
// File:
|
||||||
|
// llc.cpp
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// Driver for llc compiler.
|
||||||
|
//
|
||||||
|
// History:
|
||||||
|
// 7/15/01 - Vikram Adve - Created
|
||||||
|
//
|
||||||
|
//**************************************************************************/
|
||||||
|
|
||||||
|
//************************** System Include Files **************************/
|
||||||
|
|
||||||
|
//*************************** User Include Files ***************************/
|
||||||
|
|
||||||
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Method.h"
|
||||||
|
#include "llvm/Bytecode/Reader.h"
|
||||||
|
#include "llvm/Bytecode/Writer.h"
|
||||||
|
#include "llvm/Codegen/InstrForest.h"
|
||||||
|
#include "llvm/Codegen/InstrSelection.h"
|
||||||
|
#include "llvm/LLC/LLCOptions.h"
|
||||||
|
#include "llvm/LLC/CompileContext.h"
|
||||||
|
|
||||||
|
//************************** Forward Declarations **************************/
|
||||||
|
|
||||||
|
class Module;
|
||||||
|
class CompileContext;
|
||||||
|
|
||||||
|
|
||||||
|
static bool CompileModule (Module *module,
|
||||||
|
CompileContext& compileContext);
|
||||||
|
|
||||||
|
int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// Function main()
|
||||||
|
//
|
||||||
|
// Entry point for the driver.
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, const char** argv, const char** envp)
|
||||||
|
{
|
||||||
|
CompileContext compileContext(argc, argv, envp);
|
||||||
|
|
||||||
|
Module *module =
|
||||||
|
ParseBytecodeFile(compileContext.getOptions().getInputFileName());
|
||||||
|
|
||||||
|
if (module == 0) {
|
||||||
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool failure = CompileModule(module, compileContext);
|
||||||
|
|
||||||
|
if (failure)
|
||||||
|
{
|
||||||
|
cerr << "Error compiling "
|
||||||
|
<< compileContext.getOptions().getInputFileName() << "!\n";
|
||||||
|
delete module;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Okay, we're done now... write out result...
|
||||||
|
// WriteBytecodeToFile(module,
|
||||||
|
// compileContext.getOptions().getOutputFileName);
|
||||||
|
|
||||||
|
// Clean up and exit
|
||||||
|
delete module;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
CompileModule(Module *module,
|
||||||
|
CompileContext& ccontext)
|
||||||
|
{
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
for (Module::MethodListType::const_iterator
|
||||||
|
methodIter = module->getMethodList().begin();
|
||||||
|
methodIter != module->getMethodList().end();
|
||||||
|
++methodIter)
|
||||||
|
{
|
||||||
|
Method* method = *methodIter;
|
||||||
|
|
||||||
|
if (SelectInstructionsForMethod(method, ccontext))
|
||||||
|
{
|
||||||
|
failed = true;
|
||||||
|
cerr << "Instruction selection failed for method "
|
||||||
|
<< (method->hasName()? method->getName() : "")
|
||||||
|
<< endl << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return failed;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user