Example #1
0
static int handle_argument(const char *var, const char *val,
                           struct cmdarg *cmdargs)
{
    // compare var against array of recognized arguments
    for(int i = 0; cmdargs[i].arg != NULL; i++) {
        struct cmdarg *a = &cmdargs[i];
        if(!strncmp(var, a->arg, strlen(a->arg))) {
            switch(a->type) {
            case ArgType_Int:
                return handle_int(a->var.integer, val);

            case ArgType_UInt:
                return handle_uint(a->var.uinteger, val);

            case ArgType_Bool:
                return handle_bool(a->var.boolean, val);

            case ArgType_Custom:
                return a->var.handler(var, val);

            default:
                assert(!"Unknown type %d in kernel argument array!");
                return -1;
            }
        }
    }

    return 0;
}
Example #2
0
int handle_type(json_parser *parser, const char c){
    switch (c){
        //TODO ADD SPECIAL STORAGE SUPPORT
        //TODO ADD ARRAY SUPPORT
        //skip White spaces
        case ' ': case '\t': case '\r': case '\n':
            break;
        case '{': case '[':
            parser->state = JSON_STATE_BEGIN_VAL_OR_KEY;
            parser->level++;
            break;
        case '0' ... '9':
            parser->state = JSON_STATE_INT;
            handle_int(parser, c);
            break;
        case 't':
            parser->state = JSON_STATE_TRUE;
            break;
        case 'f':
            parser->state = JSON_STATE_FALSE;
            break;
        case 'n':
            parser->state = JSON_STATE_NULL;
            break;
        case '\"':
            parser->state = JSON_STATE_STR;
            break;
        default:
            return JSON_ERROR_PARSING;
    }

    return JSON_CONTINUE;
}
Example #3
0
// TODO: Check and handle any requested ints between instructions
void Ez80::execute()
{
  if(pc==breakpoint) { debugger("Breakpoint!\n"); return; }
  opcode=map->read8(pc);
  op_len=Ez80_size[opcode];
  cycle=Ez80_time[opcode];
  unsigned int op=opcode,loc=pc,topcode=opcode;
#include <cpulib/generated/Ez80_exec.h>
  pc+=op_len;
  cycles+=cycle;
  if(int_pending) handle_int(int_pending);
}
Example #4
0
//TODO ADD OPTIMISATIONS DURING KEY MATCHING
int json_parse(json_parser *parser,
               const char *input_buff, size_t buff_sz){
	int i;

    //The parser looks at one char at a time.
    //the character is only advanced by this for loop.
	for (; parser->buff_offset < buff_sz
            && input_buff[parser->buff_offset] != '\0';
           parser->buff_offset++) {
		char c;
        int res;

		c = input_buff[parser->buff_offset];


        switch (parser->state){
            case JSON_STATE_BEGIN_VAL_OR_KEY:
                res = handle_begin_val_or_key(parser, c); break;
            case JSON_STATE_INT_ELEM:
                res = handle_int_elem(parser, c); break;
            case JSON_STATE_TRUE_ELEM:
                    case JSON_STATE_FALSE_ELEM:
                    case JSON_STATE_NULL_ELEM:
                res = handle_special_elem(parser, c); break;
            case JSON_STATE_KEY_OR_STR: case JSON_STATE_KEY_OR_STR_ESCAPE:
                res = handle_key_or_str(parser, c); break;
            case JSON_STATE_KEY_OR_STR_END:
                res = handle_key_or_str_end(parser, c); break;
            case JSON_STATE_TYPE:
                res = handle_type(parser, c); break;
            case JSON_STATE_INT:
                res = handle_int(parser, c); break;
            case JSON_STATE_TRUE: case JSON_STATE_FALSE: case JSON_STATE_NULL:
                res = handle_special(parser, c); break;
            case JSON_STATE_STR: case JSON_STATE_STR_ESCAPE:
                res = handle_str(parser, c); break;
            case JSON_STATE_END_VAL:
                res = handle_end_val(parser, c); break;
            case JSON_STATE_START:
                res = handle_start(parser, c); break;

            //parsing stop if we are done or if there was an error
            if (res <= 0)
                return res;
        }
	}

    //ran out of buffer, parser is either done or needs more input
    if (parser->level == 0)
        return JSON_DONE;
    return JSON_CONTINUE;
}
Example #5
0
void Ez80::cause_int(ULONG value)
{
  if(!intsEnabled) {
    int_pending=value;
    return;
  }
  // TODO: What if we already had a pending one?
  switch(value) {
    case Ez80_INT_RESET:
      reset();
      break;
    case Ez80_INT_NMI:
      handle_int(value);
      break;
    case Ez80_INT_IRQ:
      handle_int(value);
      break;
    default:
      debugger("Illegal interrupt requested!\n");
      break;
  }
}
Example #6
0
void EHitachi::execute()
{
    R[7]=sp;  // to keep them in sync...
    if(pc==breakpoint) {
        debugger("Breakpoint!\n");
        return;
    }
    opcode=map->read16l(pc); // always little endian?
    topcode=(opcode>>8)&0xff;
    op_len=EHitachi_size[topcode];
    cycle=EHitachi_time[topcode];
    ULONG loc=pc;
#include <cpulib/generated/EHitachi_exec.h>
    pc+=op_len;
    sp=R[7];  // to keep them in sync...
    cycles+=cycle;
    if(int_pending) handle_int(int_pending);
}
Example #7
0
void EArm::execute()
{
  if(pc==breakpoint) { debugger("Breakpoint!\n"); return; }
  opcode=read32mem(pc); // always little endian?
  unsigned int topcode=(opcode>>20)&0xff;
  unsigned int ccode=(opcode>>28)&0xf;
  //op_len=EARM_size[topcode];
  op_len=4;
  cycle=EArm_time[topcode];
  mode=EArm_format[topcode];
  decode();
  ULONG loc=pc;
  if(willExecute) {
#include <cpulib/generated/EArm_exec.h>
  }
  pc+=op_len;
  cycles+=cycle;
  if(int_pending) handle_int(int_pending);
}
Example #8
0
void EMips::execute(void)
{
  if(pc==breakpoint) { debugger("Breakpoint!\n"); return; }
  doRun=true;
  ir=read32mem(pc);
  op=ir;
  tookBranch=false;
  top=(op>>26)&0x3f;
  opName=EMips_name[top];
  opFormat=EMips_format[top];
  opSubFormat=EMips_subformat[top];
  opFlags=EMips_flags[top];
  decode(op);
  int topcode=top;
#include <cpulib/generated/EMips_exec.h>
  pc=npc;
  npc+=4;
  if(tookBranch) npc=branch_address;
  if(anull) { pc=npc; npc=pc+4; anull=false; }
  if(int_pending) handle_int(int_pending);
}