Example #1
0
static OrcStaticOpcode *
get_store_opcode_for_size (int size)
{
  switch (size) {
    case 1:
      return orc_opcode_find_by_name ("storeb");
    case 2:
      return orc_opcode_find_by_name ("storew");
    case 4:
      return orc_opcode_find_by_name ("storel");
    case 8:
      return orc_opcode_find_by_name ("storeq");
    default:
      ORC_ASSERT(0);
  }
  return NULL;
}
Example #2
0
static OrcStaticOpcode *
get_loadp_opcode_for_size (int size)
{
  switch (size) {
    case 1:
      return orc_opcode_find_by_name ("loadpb");
    case 2:
      return orc_opcode_find_by_name ("loadpw");
    case 4:
      return orc_opcode_find_by_name ("loadpl");
    case 8:
      return orc_opcode_find_by_name ("loadpq");
    default:
      ORC_ASSERT(0);
  }
  return NULL;
}
Example #3
0
/**
 * orc_program_append_ds_str:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @arg0: name of first variable
 * @arg1: name of second variable
 *
 * Appends an instruction to the program, with arguments @arg0 and
 * @arg2.  The instruction must take 2 operands.
 */
void
orc_program_append_ds_str (OrcProgram *program, const char *name,
    const char *arg1, const char *arg2)
{
  OrcInstruction *insn;

  insn = program->insns + program->n_insns;

  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s", name);
  }
  insn->dest_args[0] = orc_program_find_var_by_name (program, arg1);
  insn->src_args[0] = orc_program_find_var_by_name (program, arg2);
  
  program->n_insns++;
}
Example #4
0
/**
 * orc_program_append_ds:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @arg0: index of first variable
 * @arg1: index of second variable
 *
 * Appends an instruction to the program, with arguments @arg0 and
 * @arg1.  The instruction must take 2 operands.
 */
void
orc_program_append_ds (OrcProgram *program, const char *name, int arg0,
    int arg1)
{
  OrcInstruction *insn;

  insn = program->insns + program->n_insns;

  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s", name);
  }
  insn->dest_args[0] = arg0;
  insn->src_args[0] = arg1;
  
  program->n_insns++;
}
Example #5
0
/**
 * orc_program_append_str_2:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @flags: flags
 * @arg0: name of first variable
 * @arg1: name of second variable
 * @arg2: name of third variable
 * @arg3: name of fourth variable
 *
 * Appends an instruction to the program, with arguments @arg0,
 * @arg1, @arg2, and @arg3.
 */
void
orc_program_append_str_2 (OrcProgram *program, const char *name,
    unsigned int flags, const char *arg1, const char *arg2, const char *arg3,
    const char *arg4)
{
  OrcInstruction *insn;
  int args[4];
  int i;

  insn = program->insns + program->n_insns;

  insn->line = program->current_line;
  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s at line %d", name, insn->line);
  }
  args[0] = orc_program_find_var_by_name (program, arg1);
  args[1] = orc_program_find_var_by_name (program, arg2);
  args[2] = orc_program_find_var_by_name (program, arg3);
  args[3] = orc_program_find_var_by_name (program, arg4);
  insn->flags = flags;
  i = 0;
  insn->dest_args[0] = args[i++];
  if (insn->opcode) {
    if (insn->opcode->dest_size[1] != 0) {
      insn->dest_args[1] = args[i++];
    }
    if (insn->opcode->src_size[0] != 0) {
      insn->src_args[0] = args[i++];
    }
    if (insn->opcode->src_size[1] != 0) {
      insn->src_args[1] = args[i++];
    }
    if (insn->opcode->src_size[2] != 0) {
      insn->src_args[2] = args[i++];
    }
  }
  program->n_insns++;
}
Example #6
0
/**
 * orc_program_append_ds_2:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @arg0: index of first variable
 * @arg1: index of second variable
 * @arg2: index of third variable
 * @arg3: index of fourth variable
 *
 * Appends an instruction to the program, with arguments @arg0,
 * @arg1, @arg2, and @arg3.
 */
void
orc_program_append_2 (OrcProgram *program, const char *name, unsigned int flags,
    int arg0, int arg1, int arg2, int arg3)
{
  OrcInstruction *insn;
  int args[4];
  int i;

  insn = program->insns + program->n_insns;

  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s", name);
  }
  insn->flags = flags;
  args[0] = arg0;
  args[1] = arg1;
  args[2] = arg2;
  args[3] = arg3;
  insn->flags = flags;
  i = 0;
  insn->dest_args[0] = args[i++];
  if (insn->opcode) {
    if (insn->opcode->dest_size[1] != 0) {
      insn->dest_args[1] = args[i++];
    }
    if (insn->opcode->src_size[0] != 0) {
      insn->src_args[0] = args[i++];
    }
    if (insn->opcode->src_size[1] != 0) {
      insn->src_args[1] = args[i++];
    }
    if (insn->opcode->src_size[2] != 0) {
      insn->src_args[2] = args[i++];
    }
  }
  program->n_insns++;
}
Example #7
0
/**
 * orc_program_append_str_2:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @flags: flags
 * @arg0: name of first variable
 * @arg1: name of second variable
 * @arg2: name of third variable
 * @arg3: name of fourth variable
 *
 * Appends an instruction to the program, with arguments @arg0,
 * @arg1, @arg2, and @arg3.
 */
void
orc_program_append_str_2 (OrcProgram *program, const char *name,
    unsigned int flags, const char *arg1, const char *arg2, const char *arg3,
    const char *arg4)
{
  OrcInstruction *insn;
  int args[4];

  insn = program->insns + program->n_insns;

  insn->line = program->current_line;
  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s at line %d", name, insn->line);
  }
  args[0] = orc_program_find_var_by_name (program, arg1);
  args[1] = orc_program_find_var_by_name (program, arg2);
  args[2] = orc_program_find_var_by_name (program, arg3);
  args[3] = orc_program_find_var_by_name (program, arg4);
  insn->flags = flags;
  orc_program_dispatch_operands (insn, args);
  program->n_insns++;
}
Example #8
0
/**
 * orc_program_append_str_n:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @flags: flags
 * @argc: number of variableds
 * @argv: array of variables
 *
 * Appends an instruction to the program, with any number of
 * arguments. Only o <= number <= 4 is supported.
 *
 * Returns: status code.
 * 0: succesfull
 * <0: malformed opcode (unknown or bad arguments)
 * >0: unknown argument. Then the return value equals to the nth
 * argument. Beware: this is index, not offset (the first is 1).
 */
int
orc_program_append_str_n (OrcProgram *program, const char *name,
    unsigned int flags, int argc, const char **argv)
{
  OrcInstruction *insn;
  int args[4];
  int i;
  int n = (argc < 4) ?argc :4;

  insn = program->insns + program->n_insns;

  insn->line = program->current_line;
  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    return -1;
  }

  if (n < 0) {
    return -1;
  }

  for (i=0;i<n;i++){
    args[i] = orc_program_find_var_by_name (program, argv[i]);
    if (args[i] == -1) {
/*
      ORC_ERROR ("bad operand \"%s\" in position %d for opcode: %s at line %d",
                 argv[i], i+1, name, insn->line);
 */
      return i+1;
    }
  }

  insn->flags = flags;
  orc_program_dispatch_operands (insn, args);
  program->n_insns++;
  return 0;
}
Example #9
0
/**
 * orc_program_append_str:
 * @program: a pointer to an OrcProgram structure
 * @name: name of instruction
 * @arg0: name of first variable
 * @arg1: name of second variable
 * @arg2: name of third variable
 *
 * Appends an instruction to the program, with arguments @arg0,
 * @arg1, and @arg2.  The instruction must take 3 operands.
 */
void
orc_program_append_str (OrcProgram *program, const char *name,
    const char *arg1, const char *arg2, const char *arg3)
{
  OrcInstruction *insn;

  insn = program->insns + program->n_insns;

  insn->opcode = orc_opcode_find_by_name (name);
  if (!insn->opcode) {
    ORC_ERROR ("unknown opcode: %s", name);
    return;
  }
  insn->dest_args[0] = orc_program_find_var_by_name (program, arg1);
  if (insn->opcode->dest_size[1] != 0) {
    insn->dest_args[1] = orc_program_find_var_by_name (program, arg2);
    insn->src_args[0] = orc_program_find_var_by_name (program, arg3);
  } else {
    insn->src_args[0] = orc_program_find_var_by_name (program, arg2);
    insn->src_args[1] = orc_program_find_var_by_name (program, arg3);
  }
  
  program->n_insns++;
}
Example #10
0
int
main (int argc, char *argv[])
{
  char *code;
  int n = 0;
  int i;
  OrcProgram **programs;
  const char *filename = NULL;

  orc_init ();
  orc_test_init ();

  for(i=1;i<argc;i++){
    if (strcmp("-x", argv[i]) == 0) {
      format = FORMAT_HEX;
    } else if (strcmp("-s", argv[i]) == 0) {
      format = FORMAT_SIGNED;
    } else if (strcmp("-u", argv[i]) == 0) {
      format = FORMAT_UNSIGNED;
    } else if (strcmp("-f", argv[i]) == 0) {
      format = FORMAT_FLOAT;
    } else if (strcmp("-n", argv[i]) == 0) {
      if (i + 1 < argc) {
        array_n = strtol (argv[i+1], NULL, 0);
        i++;
      }
    } else {
      filename = argv[i];
    }
  }

  if (filename == NULL) {
    filename = getenv ("testfile");
  }
  if (filename == NULL) {
    filename = "test.orc";
  }
  code = read_file (filename);
  if (code) {
    n = orc_parse (code, &programs);
  } else {
    OrcStaticOpcode *opcode;

    opcode = orc_opcode_find_by_name (filename);
    if (opcode) {
      programs = malloc(sizeof(void *));
      programs[0] = orc_test_get_program_for_opcode (opcode);
      n = 1;
    } else {
      printf("show_parse [-fsux] (<file.orc>|opcode)\n");
      exit(1);
    }
  }

  for(i=0;i<n;i++){
    show (programs[i]);
  }

  if (error) return 1;
  return 0;
}