aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2001-07-21 12:42:29 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2001-07-21 12:42:29 +0000
commitcb465fc71ecb64d3d168a0cf754fa442abb0f6f9 (patch)
tree1be408a04686f3b870a79d2f213a2d21ae2dae2f /tools
parenta21cf20411c595c81598a53b560a757d9daf299a (diff)
downloadexternal_llvm-cb465fc71ecb64d3d168a0cf754fa442abb0f6f9.zip
external_llvm-cb465fc71ecb64d3d168a0cf754fa442abb0f6f9.tar.gz
external_llvm-cb465fc71ecb64d3d168a0cf754fa442abb0f6f9.tar.bz2
Driver and options for the llc compiler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llc/LLCOptions.cpp125
-rw-r--r--tools/llc/Makefile23
-rw-r--r--tools/llc/llc.cpp103
3 files changed, 251 insertions, 0 deletions
diff --git a/tools/llc/LLCOptions.cpp b/tools/llc/LLCOptions.cpp
new file mode 100644
index 0000000..b3d2688
--- /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 <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);
+}
+
+
diff --git a/tools/llc/Makefile b/tools/llc/Makefile
new file mode 100644
index 0000000..6b69a5c
--- /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 0000000..c8cefdb
--- /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;
+}
+