示例#1
0
static int parse_unary(struct _asm_context *asm_context, int64_t *num, int operation)
{
  char token[TOKENLEN];
  int token_type;
  int64_t temp;
  struct _var var;

  var_set_int(&var, 0);

  token_type = tokens_get(asm_context, token, TOKENLEN);

//printf("parse_unary: %s token_type=%d(%d)\n", token, token_type, TOKEN_NUMBER);

  if (IS_TOKEN(token,'-'))
  {
    if (parse_unary(asm_context, &temp, OPER_MINUS) == -1) { return -1; }
  }
    else
  if (IS_TOKEN(token,'~'))
  {
    if (parse_unary(asm_context, &temp, OPER_NOT) != 0) { return -1; }
  }
    else
  if (token_type == TOKEN_NUMBER)
  {
    temp = atoll(token);
  }
    else
  if (IS_TOKEN(token, '('))
  {
    if (eval_expression_ex(asm_context, &var) != 0) { return -1; }
    if (var.type != VAR_INT)
    {
      print_error("Non-integer number in expression", asm_context);
      return -1;
    }

    temp = var_get_int64(&var);

    token_type = tokens_get(asm_context, token, TOKENLEN);
    if (IS_NOT_TOKEN(token,')'))
    {
      print_error_unexp(token, asm_context);
      return -1;
    }
  }
    else
  {
    print_error_unexp(token, asm_context);
    return -1;
  }

  if (operation == OPER_NOT) { *num = ~temp; }
  else if (operation == OPER_MINUS) { *num = -temp; }
  else { print_error_internal(NULL, __FILE__, __LINE__); return -1; }

  return 0;
}
示例#2
0
int memory_get_page_address_max(struct _memory *memory, uint32_t address)
{
struct _memory_page *page;

  page = memory->pages;
  while(page != NULL)
  {
    if (address >= page->address && address < page->address + PAGE_SIZE)
    {
      return page->address + page->offset_max;
    }
    page = page->next;
  }

  print_error_internal(NULL, __FILE__, __LINE__);
  return 0;
}