OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [Open8 Tools/] [open8_src/] [open8_as/] [opcode_table_generator/] [main.c] - Rev 198

Go to most recent revision | Compare with Previous | Blame | View Log

 
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "../defines.h"
#include "defines.h"
 
 
char outname[] = "../opcodes_v8urisc_tables.c";
#include "../opcodes_v8urisc.c"
 
 
/* this program is used to generate the opcode decoding speedup tables */
 
 
int print_table(FILE *f, int *d) {
 
  int x;
 
 
  for (x = 0; x < 256; x++) {
    if ((x % 8) == 0)
      fprintf(f, "  ");
    fprintf(f, "%d", d[x]);
    if ((x % 8) == 7) {
      if (x == 255)
	fprintf(f, " };\n");
      else
	fprintf(f, ",\n");
    }
    else
      fprintf(f, ", ");
  }
 
  return SUCCEEDED;
}
 
 
int main(int argc, char *argv[]) {
 
  struct optcode *opt_tmp;
  FILE *out;
  char max_name[256];
  int x, opcode_n[256], opcode_p[256], a, b, n, max = 0, ob;
 
 
 
  /* generate opcode decoding jump tables */
  for (x = 0; x < 256; x++) {
    opcode_n[x] = 0;
    opcode_p[x] = 0;
  }
 
  opt_tmp = opt_table;
  a = 'A';
  b = 'a';
  ob = 'a';
  n = 0;
  x = 0;
  opcode_p[(int)a] = 0;
  opcode_p[(int)b] = 0;
  while (opt_table[n].type != -1) {
    if (strlen(opt_table[n].op) > max) {
      max = strlen(opt_table[n].op);
      strcpy(max_name, opt_table[n].op);
    }
    if (opt_tmp[n].op[0] != a) {
      opcode_n[(int)a] = x;
      opcode_n[(int)b] = x;
      a = opt_tmp[n].op[0];
      b = tolower((int)a);
      if (ob > b) {
	fprintf(stderr, "MAIN: Instruction are NOT in alphabetical order (first letter): '%c' -> '%c'.\n", ob, b);
	return 1;
      }
      ob = b;
      opcode_p[(int)a] = n;
      opcode_p[(int)b] = n;
      x = 1;
      n++;
    }
    else {
      x++;
      n++;
    }
  }
  opcode_n[(int)a] = x;
  opcode_n[(int)b] = x;
 
  out = fopen(outname, "wb");
  if (out == NULL) {
    fprintf(stderr, "MAIN: Unable to create file \"%s\".\n", outname);
    return 1;
  }
 
  /* opcode_n[256] */
  fprintf(out, "int opcode_n[256] = {\n");
  print_table(out, opcode_n);
 
  /* opcode_p[256] */
  fprintf(out, "int opcode_p[256] = {\n");
  print_table(out, opcode_p);
 
  fclose(out);
 
#if QUIET == 0
  printf("MAIN: max opt[] (\"%s\") lenght was %d bytes.\n", max_name, max);
#endif
 
  return 0;
}
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.