Lib/Source/Interpreter.cpp
/**
 * Run the interpreter
 *
 * The interpreter parses the CFG ('source code') directly.
 *
 * The interpreter works in a similar way to the emulator.  The
 * difference is that the interpreter operates on source code and the
 * emulator on target code.
 *
 * @param numCores  Number of cores active
 * @param stmt      Source code
 * @param numVars   Max var id used in source
 * @param uniforms  Kernel parameters
 * @param heap
 * @param output    Output from print statements (if NULL, stdout is used)
 */
Run the interpreter
The interpreter parses the CFG ('source code') directly.

The interpreter works in a similar way to the emulator.  The
difference is that the interpreter operates on source code and the
emulator on target code.


Run the interpreter The interpreter parses the CFG ( ' source code ' ) directly . The interpreter works in a similar way to the emulator . The difference is that the interpreter operates on source code and the emulator on target code .
void interpreter(
  int numCores,
  Stmts const &stmts,
  int numVars,
  IntList &uniforms,
  BufferObject &heap
) {
  InterpreterState state(numCores, uniforms);
  for (int i = 0; i < numCores; i++) {
    CoreState &s = state.core[i];
    s.id          = i;
    s.init_env(numVars);
    s.emuHeap.heap_view(heap);
  }
  for (int i = 0; i < numCores; i++) {
    auto &stack = state.core[i].stack;
    stack = stmts;
    std::reverse(stack.begin(), stack.end());
  }
  CoreState::reset_count();
  bool running = true;
  while (running) {
    running = false;
    for (int i = 0; i < numCores; i++) {
      if (state.core[i].stack.size() > 0) {
        running = true;
        exec(state, i);
      }
    }
  }
}
void interpreter ( int numCores , Stmts const & stmts , int numVars , IntList & uniforms , BufferObject & heap ) { InterpreterState state ( numCores , uniforms ) ; for ( int i = 0 ; i < numCores ; i ++ ) { CoreState & s = state . core [ i ] ; s . id = i ; s . init_env ( numVars ) ; s . emuHeap . heap_view ( heap ) ; } for ( int i = 0 ; i < numCores ; i ++ ) { auto & stack = state . core [ i ] . stack ; stack = stmts ; std :: reverse ( stack . begin ( ) , stack . end ( ) ) ; } CoreState :: reset_count ( ) ; bool running = true ; while ( running ) { running = false ; for ( int i = 0 ; i < numCores ; i ++ ) { if ( state . core [ i ] . stack . size ( ) > 0 ) { running = true ; exec ( state , i ) ; } } } }
Run the interpreter
 The interpreter parses the CFG ('source code') directly.
Run the interpreter The interpreter parses the CFG ( ' source code ' ) directly .
// Initialise state // Put statement on each core's control stack // Note the reversal, to use it as an actual stack // Run code