const wasm_module::Instruction* InterpreterThread::callFunction(
            const std::string& moduleName, const std::string& functionName,
            std::vector<wasm_module::Variable> parameters) {

        if (functionStack_.size() >= functionStackLimit)
            throw StackLimitReached(std::to_string(functionStack_.size()));

        const wasm_module::Function* func = nullptr;

        wasm_module::Module& module = env_.getModule(moduleName);

        func = &env_.getFunction(moduleName, functionName);

        if (func->variadic()) {
            std::vector<const wasm_module::Type*> types;
            for (auto& parameter : parameters) {
                types.push_back(&parameter.type());
            }
            functionStack_.push_back(FunctionState(*func, types));
        } else {
            // We push the new locals to the functionStack_ before entering.
            functionStack_.push_back(FunctionState(*func));
        }

        for (uint32_t i = 0; i < parameters.size(); i++) {
            variable(i) = parameters.at(i);
        }

        return func->mainInstruction();
    }
Exemple #2
0
    void Thread::enterFunction(wasm_module::Function& function) {
        if (stack.size() >= stackLimit)
            throw StackLimitReached(std::to_string(stack.size()));

        // We push the new locals to the stack before entering.

        stack.push(FunctionState(function));
    }
gmCodeGenPrivate::FunctionState * gmCodeGenPrivate::PushFunction()
{
  if(m_currentFunction)
  {
    if(m_currentFunction != m_functionStack.GetLast())
    {
      m_currentFunction = m_functionStack.GetNext(m_currentFunction);
    }
    else
    {
      m_currentFunction = GM_NEW( FunctionState() );
      m_functionStack.InsertLast(m_currentFunction);
    }
  }
  else
  {
    if(m_functionStack.IsEmpty())
    {
      m_currentFunction = GM_NEW( FunctionState() );
      m_functionStack.InsertLast(m_currentFunction);
    }
    else
    {
      m_currentFunction = m_functionStack.GetFirst();
    }  
  }

  m_currentFunction->Reset();

  m_currentFunction->m_byteCode.SetSwapEndianOnWrite(m_hooks->SwapEndian());

  // if we are debugging, set up some line number debugging.
  if(m_debug)
  {
    m_currentFunction->m_byteCode.m_emitCallback = gmLineNumberCallback;
  }

  return m_currentFunction;
}