コード例 #1
0
ファイル: dispatcher.c プロジェクト: chrispe92/Alpha-Compiler
void execute_instr(instr_s * instr){
	switch(instr->opcode){
		case assign_v: execute_assign(instr); break;
		case call_v: execute_call(instr); break;
		case funcenter_v: execute_funcenter(instr); break;
		case funcexit_v: execute_funcexit(instr); break;
		case pusharg_v: execute_pusharg(instr); break;
		case add_v: execute_arithmetic(instr); break;
		case sub_v: execute_arithmetic(instr); break;
		case mul_v: execute_arithmetic(instr); break;
		case div_v: execute_arithmetic(instr); break;
		case mod_v: execute_arithmetic(instr); break;
		case jump_v: execute_jump(instr); break;
		case jeq_v: execute_jeq(instr); break;
		case jne_v:execute_jeq(instr); break;
		case jgt_v:execute_cmp(instr); break;
		case jge_v:execute_cmp(instr); break;
		case jlt_v:execute_cmp(instr); break;
		case jle_v:execute_cmp(instr); break;
		case newtable_v: execute_newtable(instr); break;
		case tablegetelem_v: execute_tablegetelem(instr); break;
		case tablesetelem_v: execute_tablesetelem(instr); break;
		default: return;
	}
}
コード例 #2
0
ファイル: ec_filter.c プロジェクト: bonsaiviking/ettercap
/*
 * JIT interpreter for binary filters.
 * it process the filter_ops and apply the instructions
 * on the given packet object
 */
static int filter_engine(struct filter_op *fop, struct packet_object *po)
{
   u_int32 eip = 0;
   u_int32 flags = 0;
      #define FLAG_FALSE   0
      #define FLAG_TRUE    1
  
   /* sanity check */
   BUG_IF(fop == NULL);

   FILTERS_LOCK;

   /* loop until EXIT */
   while (fop[eip].opcode != FOP_EXIT) {

      switch (fop[eip].opcode) {
         case FOP_TEST:
            if (execute_test(&fop[eip], po) == FLAG_TRUE)
               flags |= FLAG_TRUE;
            else
               flags &= ~(FLAG_TRUE);
            
            break;
            
         case FOP_ASSIGN:
            execute_assign(&fop[eip], po);
            /* assignment always returns true */
            flags |= FLAG_TRUE;
            
            break;
            
         case FOP_INC:
         case FOP_DEC:
            execute_incdec(&fop[eip], po);
            /* inc/dec always return true */
            flags |= FLAG_TRUE;
            
            break;
            
         case FOP_FUNC:
            if (execute_func(&fop[eip], po) == FLAG_TRUE)
               flags |= FLAG_TRUE;
            else
               flags &= ~(FLAG_TRUE);

            break;
            
         case FOP_JMP:
            /* jump the the next eip */
            eip = fop[eip].op.jmp;
            continue;

            break;
            
         case FOP_JTRUE:
            /* jump the the next eip if the TRUE FLAG is set*/
            if (flags & FLAG_TRUE) {
               eip = fop[eip].op.jmp;
               continue;
            }
            break;
            
         case FOP_JFALSE:
            /* jump the the next eip if the TRUE FLAG is NOT set */
            if (!(flags & FLAG_TRUE)) {
               eip = fop[eip].op.jmp;
               continue;
            }
            break;
            
         default:
            FILTERS_UNLOCK;
            JIT_FAULT("unsupported opcode [%d] (execution interrupted)", fop[eip].opcode);
            break;
      }
    
      /* autoincrement the instruction pointer */
      eip++;
   }
   
   FILTERS_UNLOCK;

   return 0;
}
コード例 #3
0
ファイル: interpreter.cpp プロジェクト: sarnold/cbmc
void interpretert::step()
{
  if(PC==function->second.body.instructions.end())
  {
    if(call_stack.empty())
      done=true;
    else
    {
      PC=call_stack.top().return_PC;
      function=call_stack.top().return_function;
      stack_pointer=call_stack.top().old_stack_pointer;
      call_stack.pop();
    }

    return;
  }
  
  next_PC=PC;
  next_PC++;  

  switch(PC->type)
  {
  case GOTO:
    execute_goto();
    break;
  
  case ASSUME:
    execute_assume();
    break;
  
  case ASSERT:
    execute_assert();
    break;
  
  case OTHER:
    execute_other();
    break;
  
  case DECL:
    execute_decl();
    break;
  
  case SKIP:
  case LOCATION:
  case END_FUNCTION:
    break;
  
  case RETURN:
    if(call_stack.empty())
      throw "RETURN without call";

    if(PC->code.operands().size()==1 &&
       call_stack.top().return_value_address!=0)
    {
      std::vector<mp_integer> rhs;
      evaluate(PC->code.op0(), rhs);
      assign(call_stack.top().return_value_address, rhs);
    }

    next_PC=function->second.body.instructions.end();
    break;
    
  case ASSIGN:
    execute_assign();
    break;
    
  case FUNCTION_CALL:
    execute_function_call();
    break;
  
  case START_THREAD:
    throw "START_THREAD not yet implemented";
  
  case END_THREAD:
    throw "END_THREAD not yet implemented";
    break;

  case ATOMIC_BEGIN:
    throw "ATOMIC_BEGIN not yet implemented";
    
  case ATOMIC_END:
    throw "ATOMIC_END not yet implemented";
    
  case DEAD:
    throw "DEAD not yet implemented";
  
  default:
    throw "encountered instruction with undefined instruction type";
  }
  
  PC=next_PC;
}
コード例 #4
0
ファイル: oun_act.cpp プロジェクト: mecirt/7k2
//--------- Begin of function Unit::pre_process ---------//
//
void Unit::pre_process()
{
	//--- if the unit's hit point drops to 0, it dies now ---//

	if( hit_points <= 0 )
	{
		set_die();
		return;
	}

	//------- process fog of war ----------//

	visit_area();

	//------ process unit_mode -------//
#ifdef DEBUG
	long startTime;
#endif

	switch( unit_mode )
	{
		case UNIT_MODE_TOWN_DEFENDER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_town_defender();
#ifdef DEBUG
			unit_process_town_defender_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_MODE_CAMP_DEFENDER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_camp_defender();
#ifdef DEBUG
			unit_process_camp_defender_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_MODE_REBEL:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_rebel();
#ifdef DEBUG
			unit_process_rebel_profile_time += m.get_time() - startTime;
#endif
			break;
	}

	//--- if the current order has been reset and there is a pushed order, pop the order ---//

	if( cur_order.mode==0 && has_pushed_order() )
   	pop_order();

	//-------- process unit order now -------//

	switch( cur_order.mode )
	{
		case UNIT_MOVE:		// nothing to do with move mode, as UnitB already takes care of it
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_move();
#ifdef DEBUG
			unit_execute_move_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_ATTACK:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_attack();
#ifdef DEBUG
			unit_execute_attack_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_BUILD_FIRM:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_build_firm();
#ifdef DEBUG
			unit_execute_build_firm_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_SETTLE_TOWN:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_settle_town();
#ifdef DEBUG
			unit_execute_settle_town_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_ASSIGN:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_assign();
#ifdef DEBUG
			unit_execute_assign_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_GO_CAST_POWER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_go_cast_power();
#ifdef DEBUG
			unit_cast_power_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_TRANSFORM_FORTRESS:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_transform_fortress();
#ifdef DEBUG
			unit_transform_fortress_profile_time += m.get_time() - startTime;
#endif
			break;
	}
}
コード例 #5
0
ファイル: execute_thread_ct.cpp プロジェクト: olivo/BP
void simulator_ctt::execute_instruction(
  statet &state,
  const program_formulat::formula_goto_programt::instructiont &instruction)
{
  switch(instruction.type)
  {
  case GOTO:
    assert(false);
    // done somewhere else
    break;

  case ASSUME:
    execute_assume(state, instruction);
    break;

  case ASSERT:
    execute_assert(state, instruction);
    break;

  case ASSIGN:
    execute_assign(state, instruction);
    break;
    
  case FUNCTION_CALL:
    assert(false); // done somewhere else
    break;

  case OTHER:
    assert(false);
    break;

  case SKIP:
  case LOCATION:
  case END_FUNCTION:
    // do nothing
    break;
    
  case START_THREAD:
    throw "start_thread is not supported";
    break;
    
  case END_THREAD:
    assert(false);
    break;
    
  case ATOMIC_BEGIN:
    state.data_w().in_atomic_section=true;
    break;
    
  case ATOMIC_END:
    state.data_w().in_atomic_section=false;
    break;
    
  case DEAD:
    break;
    
  case RETURN:
    assert(false); // done somewhere else
    break;
    
  default:
    std::cerr << instruction.type << std::endl;
    assert(false);  
  }
}