LCOV - code coverage report
Current view: top level - lib/ExecutionEngine/Interpreter - Interpreter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 35 74.3 %
Date: 2017-09-14 15:23:50 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Interpreter.cpp - Top-Level LLVM Interpreter Implementation --------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the top-level functionality for the LLVM interpreter.
      11             : // This interpreter is designed to be a very simple, portable, inefficient
      12             : // interpreter.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #include "Interpreter.h"
      17             : #include "llvm/CodeGen/IntrinsicLowering.h"
      18             : #include "llvm/IR/DerivedTypes.h"
      19             : #include "llvm/IR/Module.h"
      20             : #include <cstring>
      21             : using namespace llvm;
      22             : 
      23             : namespace {
      24             : 
      25             : static struct RegisterInterp {
      26             :   RegisterInterp() { Interpreter::Register(); }
      27       72306 : } InterpRegistrator;
      28             : 
      29             : }
      30             : 
      31         192 : extern "C" void LLVMLinkInInterpreter() { }
      32             : 
      33             : /// Create a new interpreter object.
      34             : ///
      35          22 : ExecutionEngine *Interpreter::create(std::unique_ptr<Module> M,
      36             :                                      std::string *ErrStr) {
      37             :   // Tell this Module to materialize everything and release the GVMaterializer.
      38          66 :   if (Error Err = M->materializeAll()) {
      39           0 :     std::string Msg;
      40           0 :     handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
      41           0 :       Msg = EIB.message();
      42           0 :     });
      43           0 :     if (ErrStr)
      44             :       *ErrStr = Msg;
      45             :     // We got an error, just return 0
      46           0 :     return nullptr;
      47             :   }
      48             : 
      49          44 :   return new Interpreter(std::move(M));
      50             : }
      51             : 
      52             : //===----------------------------------------------------------------------===//
      53             : // Interpreter ctor - Initialize stuff
      54             : //
      55          22 : Interpreter::Interpreter(std::unique_ptr<Module> M)
      56         110 :     : ExecutionEngine(std::move(M)) {
      57             : 
      58          22 :   memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped));
      59             :   // Initialize the "backend"
      60          22 :   initializeExecutionEngine();
      61          22 :   initializeExternalFunctions();
      62          22 :   emitGlobals();
      63             : 
      64          66 :   IL = new IntrinsicLowering(getDataLayout());
      65          22 : }
      66             : 
      67          20 : Interpreter::~Interpreter() {
      68           5 :   delete IL;
      69          10 : }
      70             : 
      71          17 : void Interpreter::runAtExitHandlers () {
      72          34 :   while (!AtExitHandlers.empty()) {
      73           0 :     callFunction(AtExitHandlers.back(), None);
      74           0 :     AtExitHandlers.pop_back();
      75           0 :     run();
      76             :   }
      77          17 : }
      78             : 
      79             : /// run - Start execution with the specified function and arguments.
      80             : ///
      81          34 : GenericValue Interpreter::runFunction(Function *F,
      82             :                                       ArrayRef<GenericValue> ArgValues) {
      83             :   assert (F && "Function *F was null at entry to run()");
      84             : 
      85             :   // Try extra hard not to pass extra args to a function that isn't
      86             :   // expecting them.  C programmers frequently bend the rules and
      87             :   // declare main() with fewer parameters than it actually gets
      88             :   // passed, and the interpreter barfs if you pass a function more
      89             :   // parameters than it is declared to take. This does not attempt to
      90             :   // take into account gratuitous differences in declared types,
      91             :   // though.
      92          68 :   const size_t ArgCount = F->getFunctionType()->getNumParams();
      93             :   ArrayRef<GenericValue> ActualArgs =
      94         102 :       ArgValues.slice(0, std::min(ArgValues.size(), ArgCount));
      95             : 
      96             :   // Set up the function call.
      97          34 :   callFunction(F, ActualArgs);
      98             : 
      99             :   // Start executing the function.
     100          17 :   run();
     101             : 
     102          17 :   return ExitValue;
     103      144612 : }

Generated by: LCOV version 1.13