Beispiel #1
0
int acppLoad(char* filename)
{
  acppUnload();
  yyin = fopen(filename, "r");
  if (yyin == NULL)
    return 0;
  return 1;
}
Beispiel #2
0
/*
  Main Code

*/
int main(int argc, char **argv)
{
  char buffer[200];
  
  /* Initializes the pre-processor */
  acppInit(1);

  /* Command line parsing code */
  while (1) {

    int longind;
    int optc = getopt_long_only(argc, argv, shortopts, longopts,
                &longind);

    if (optc == -1)
      break;
    
    switch (optc) {

    case 1:  /* file */
      if (file_name != NULL) {
        fprintf(stderr, "Argument duplicated: '%s'.\n", optarg);
        exit(1);
      }
      file_name = (char *) malloc(strlen(optarg)+1);
      strcpy(file_name, optarg);
      break;

    case 'a':
      if (get_arch_name() != NULL) {
        fprintf(stderr, "Argument duplicated: '%s'.\n", optarg);
        exit(1);
      }
      set_arch_name(optarg);
      break;

    case 'h':
      show_usage(stdout);
      exit(0);

    case 'v':
      show_version(stdout);
      exit(0);

    default:
      show_usage(stdout);
      exit(1);
    }
  }

  if (file_name == NULL) {
    fprintf(stderr, "No ArchC description file specified.\n");
    exit(1);
  }

  if (get_arch_name() == NULL) {
    fprintf(stderr, "No architecture name specified.\n");
    exit(1);
  }

  /* Parse the ARCH file */
  if (!acppLoad(file_name)) {
    fprintf(stderr, "Invalid file: '%s'.\n", file_name);
    exit(1);
  }

  if (acppRun()) {
    fprintf(stderr, "Parser error in ARCH file.\n");
    exit(1);
  }
  acppUnload();


  /* Parse the ISA file */
  if (!acppLoad(isa_filename)) {
    fprintf(stderr, "Invalid ISA file: '%s'.\n", isa_filename);
    exit(1);
  }
  if (acppRun()) {
    fprintf(stderr, "Parser error in ISA file.\n");
    exit(1);
  }
  acppUnload();


  /*
    File Generation
  */
 
  if (!Createm4File()) {
    fprintf(stderr, "Error creating m4 file.\n");
    exit(1);
  }
 
  create_operand_list(); /* this MUST preceed create_relocation_list */
  create_relocation_list();

  strcpy(buffer, GEN_DIR);
  strcat(buffer, OPCODE_TABLE_FILE);
  if (!CreateOpcodeTable(buffer)) {     /* write the opcode table */
    fprintf(stderr, "Error creating opcode table.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, SYMBOL_TABLE_FILE);  
  if (!CreateAsmSymbolTable(buffer)) {  /* write the symbol table */
    fprintf(stderr, "Error creating symbol table.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, PSEUDO_TABLE_FILE);
  if (!CreatePseudoOpsTable(buffer)) {  /* write the pseudo-op table */
    fprintf(stderr, "Error creating pseudo table.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, OPERAND_TABLE_FILE);
  if (!CreateOperandTable(buffer)) {  /* write the pseudo-op table */
    fprintf(stderr, "Error creating operand table.\n");
    exit(1);
  }

  
  strcpy(buffer, GEN_DIR);
  strcat(buffer, RELOC_IDS_FILE);
  if (!CreateRelocIds(buffer)) {
    fprintf(stderr, "Error creating relocation IDs.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, RELOC_HOWTO_FILE);
  if (!CreateRelocHowto(buffer)) {
    fprintf(stderr, "Error creating relocation HOWTO structure.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, RELOC_MAP_FILE);
  if (!CreateRelocMap(buffer)) {
    fprintf(stderr, "Error creating relocation map.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, FIELD_VALUE_FN_FILE);
  if (!CreateGetFieldValueFunc(buffer)) {
    fprintf(stderr, "Error creating field value function.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, ENCODING_FN_FILE);
  if (!CreateEncodingFunc(buffer)) {
    fprintf(stderr, "Error creating encoding function.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, FIELD_SIZE_FN_FILE);
  if (!CreateGetFieldSizeFunc(buffer)) {
    fprintf(stderr, "Error creating field size function.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, INSN_SIZE_FN_FILE);
  if (!CreateGetInsnSizeFunc(buffer)) {
    fprintf(stderr, "Error creating insn size function.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, MODIFIER_ENUM_FILE);
  if (!CreateModifierEnum(buffer)) {
    fprintf(stderr, "Error creating modifier enumeration.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, MODIFIER_PROT_FILE);
  if (!CreateModifierProt(buffer)) {
    fprintf(stderr, "Error creating modifier prototypes declaration.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, MODENC_PTR_FILE);
  if (!CreateModifierPtr(buffer, 0)) {
    fprintf(stderr, "Error creating modifier pointers.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, MODDEC_PTR_FILE);
  if (!CreateModifierPtr(buffer, 1)) {
    fprintf(stderr, "Error creating decode modifier pointers.\n");
    exit(1);
  }

  strcpy(buffer, GEN_DIR);
  strcat(buffer, FORMAT_STRUCT_FILE);
  if (!CreateFormatStruct(buffer)) {
    fprintf(stderr, "Error creating field definitions.\n");
    exit(1);
  }

  return 0;
}