MAke sure that LLI properly configures align_of(double)
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / Interpreter.cpp
1 //===- Interpreter.cpp - Top-Level LLVM Interpreter Implementation --------===//
2 //
3 // This file implements the top-level functionality for the LLVM interpreter.
4 // This interpreter is designed to be a very simple, portable, inefficient
5 // interpreter.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "Interpreter.h"
10 #include "llvm/Target/TargetMachineImpls.h"
11
12 /// createInterpreter - Create a new interpreter object.  This can never fail.
13 ///
14 ExecutionEngine *ExecutionEngine::createInterpreter(Module *M,
15                                                     unsigned Config,
16                                                     bool DebugMode,
17                                                     bool TraceMode) {
18   return new Interpreter(M, Config, DebugMode, TraceMode);
19 }
20
21 //===----------------------------------------------------------------------===//
22 // Interpreter ctor - Initialize stuff
23 //
24 Interpreter::Interpreter(Module *M, unsigned Config,
25                          bool DebugMode, bool TraceMode)
26   : ExecutionEngine(M), ExitCode(0), Debug(DebugMode), Trace(TraceMode),
27     CurFrame(-1), TD("lli", (Config & TM::EndianMask) == TM::LittleEndian,
28                      1, 4,
29                      (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
30                      (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
31                      (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4) {
32
33   setTargetData(TD);
34   // Initialize the "backend"
35   initializeExecutionEngine();
36   initializeExternalMethods();
37   CW.setModule(M);  // Update Writer
38 }
39
40 /// run - Start execution with the specified function and arguments.
41 ///
42 int Interpreter::run(const std::string &MainFunction,
43                      const std::vector<std::string> &Args) {
44   // Start interpreter into the main function...
45   //
46   if (!callMainMethod(MainFunction, Args) && !Debug) {
47     // If not in debug mode and if the call succeeded, run the code now...
48     run();
49   }
50
51   // If debug mode, allow the user to interact... also, if the user pressed 
52   // ctrl-c or execution hit an error, enter the event loop...
53   if (Debug || isStopped())
54     handleUserInput();
55   return ExitCode;
56 }
57