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] - Blame information for rev 327

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

Line No. Rev Author Line
1 178 jshamlet
 
2
#include <ctype.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
 
7
#include "../defines.h"
8
#include "defines.h"
9
 
10
 
11
char outname[] = "../opcodes_v8urisc_tables.c";
12
#include "../opcodes_v8urisc.c"
13
 
14
 
15
/* this program is used to generate the opcode decoding speedup tables */
16
 
17
 
18
int print_table(FILE *f, int *d) {
19
 
20
  int x;
21
 
22
 
23
  for (x = 0; x < 256; x++) {
24
    if ((x % 8) == 0)
25
      fprintf(f, "  ");
26
    fprintf(f, "%d", d[x]);
27
    if ((x % 8) == 7) {
28
      if (x == 255)
29
        fprintf(f, " };\n");
30
      else
31
        fprintf(f, ",\n");
32
    }
33
    else
34
      fprintf(f, ", ");
35
  }
36
 
37
  return SUCCEEDED;
38
}
39
 
40
 
41
int main(int argc, char *argv[]) {
42
 
43
  struct optcode *opt_tmp;
44
  FILE *out;
45
  char max_name[256];
46
  int x, opcode_n[256], opcode_p[256], a, b, n, max = 0, ob;
47
 
48
 
49
 
50
  /* generate opcode decoding jump tables */
51
  for (x = 0; x < 256; x++) {
52
    opcode_n[x] = 0;
53
    opcode_p[x] = 0;
54
  }
55
 
56
  opt_tmp = opt_table;
57
  a = 'A';
58
  b = 'a';
59
  ob = 'a';
60
  n = 0;
61
  x = 0;
62
  opcode_p[(int)a] = 0;
63
  opcode_p[(int)b] = 0;
64
  while (opt_table[n].type != -1) {
65
    if (strlen(opt_table[n].op) > max) {
66
      max = strlen(opt_table[n].op);
67
      strcpy(max_name, opt_table[n].op);
68
    }
69
    if (opt_tmp[n].op[0] != a) {
70
      opcode_n[(int)a] = x;
71
      opcode_n[(int)b] = x;
72
      a = opt_tmp[n].op[0];
73
      b = tolower((int)a);
74
      if (ob > b) {
75
        fprintf(stderr, "MAIN: Instruction are NOT in alphabetical order (first letter): '%c' -> '%c'.\n", ob, b);
76
        return 1;
77
      }
78
      ob = b;
79
      opcode_p[(int)a] = n;
80
      opcode_p[(int)b] = n;
81
      x = 1;
82
      n++;
83
    }
84
    else {
85
      x++;
86
      n++;
87
    }
88
  }
89
  opcode_n[(int)a] = x;
90
  opcode_n[(int)b] = x;
91
 
92
  out = fopen(outname, "wb");
93
  if (out == NULL) {
94
    fprintf(stderr, "MAIN: Unable to create file \"%s\".\n", outname);
95
    return 1;
96
  }
97
 
98
  /* opcode_n[256] */
99
  fprintf(out, "int opcode_n[256] = {\n");
100
  print_table(out, opcode_n);
101
 
102
  /* opcode_p[256] */
103
  fprintf(out, "int opcode_p[256] = {\n");
104
  print_table(out, opcode_p);
105
 
106
  fclose(out);
107
 
108
#if QUIET == 0
109
  printf("MAIN: max opt[] (\"%s\") lenght was %d bytes.\n", max_name, max);
110
#endif
111
 
112
  return 0;
113
}

powered by: WebSVN 2.1.0

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