From cb465fc71ecb64d3d168a0cf754fa442abb0f6f9 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Sat, 21 Jul 2001 12:42:29 +0000 Subject: Driver and options for the llc compiler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llc/LLCOptions.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++++++ tools/llc/Makefile | 23 +++++++++ tools/llc/llc.cpp | 103 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 tools/llc/LLCOptions.cpp create mode 100644 tools/llc/Makefile create mode 100644 tools/llc/llc.cpp (limited to 'tools') diff --git a/tools/llc/LLCOptions.cpp b/tools/llc/LLCOptions.cpp new file mode 100644 index 00000000000..b3d26885ebc --- /dev/null +++ b/tools/llc/LLCOptions.cpp @@ -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 +#include + + +//*************************** 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); +} + + diff --git a/tools/llc/Makefile b/tools/llc/Makefile new file mode 100644 index 00000000000..6b69a5cf1ad --- /dev/null +++ b/tools/llc/Makefile @@ -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 diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp new file mode 100644 index 00000000000..c8cefdb992e --- /dev/null +++ b/tools/llc/llc.cpp @@ -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; +} + -- cgit v1.2.3