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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [sim/] [v850/] [gencode.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#include <stdio.h>
2
#include <ctype.h>
3
#include "ansidecl.h"
4
#include "opcode/v850.h"
5
#include <limits.h>
6
 
7
static void write_header PARAMS ((void));
8
static void write_opcodes PARAMS ((void));
9
static void write_template PARAMS ((void));
10
 
11
long Opcodes[512];
12
static int curop=0;
13
 
14
int
15
main (argc, argv)
16
     int argc;
17
     char *argv[];
18
{
19
  if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
20
    write_header();
21
  else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
22
    write_template ();
23
  else
24
    write_opcodes();
25
  return 0;
26
}
27
 
28
 
29
static void
30
write_header ()
31
{
32
  struct v850_opcode *opcode;
33
 
34
  for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
35
    printf("int OP_%X PARAMS ((void));\t\t/* %s */\n",
36
           opcode->opcode, opcode->name);
37
}
38
 
39
 
40
/* write_template creates a file all required functions, ready */
41
/* to be filled out */
42
 
43
static void
44
write_template ()
45
{
46
  struct v850_opcode *opcode;
47
  int i,j;
48
 
49
  printf ("#include \"sim-main.h\"\n");
50
  printf ("#include \"v850_sim.h\"\n");
51
  printf ("#include \"simops.h\"\n");
52
 
53
  for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
54
    {
55
      printf("/* %s */\nvoid\nOP_%X (void)\n{\n", opcode->name, opcode->opcode);
56
 
57
      /* count operands */
58
      j = 0;
59
      for (i = 0; i < 6; i++)
60
        {
61
          int flags = v850_operands[opcode->operands[i]].flags;
62
 
63
          if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
64
            j++;
65
        }
66
      switch (j)
67
        {
68
        case 0:
69
          printf ("printf(\"   %s\\n\");\n", opcode->name);
70
          break;
71
        case 1:
72
          printf ("printf(\"   %s\\t%%x\\n\", OP[0]);\n", opcode->name);
73
          break;
74
        case 2:
75
          printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
76
                  opcode->name);
77
          break;
78
        case 3:
79
          printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
80
                  opcode->name);
81
          break;
82
        default:
83
          fprintf (stderr,"Too many operands: %d\n", j);
84
        }
85
      printf ("}\n\n");
86
    }
87
}
88
 
89
static void
90
write_opcodes ()
91
{
92
  struct v850_opcode *opcode;
93
  int i, j;
94
  int numops;
95
 
96
  /* write out opcode table */
97
  printf ("#include \"sim-main.h\"\n");
98
  printf ("#include \"v850_sim.h\"\n");
99
  printf ("#include \"simops.h\"\n\n");
100
  printf ("struct simops Simops[] = {\n");
101
 
102
  for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
103
    {
104
      printf ("  { 0x%x,0x%x,OP_%X,",
105
              opcode->opcode, opcode->mask, opcode->opcode);
106
 
107
      Opcodes[curop++] = opcode->opcode;
108
 
109
      /* count operands */
110
      j = 0;
111
      for (i = 0; i < 6; i++)
112
        {
113
          int flags = v850_operands[opcode->operands[i]].flags;
114
 
115
          if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
116
            j++;
117
        }
118
      printf ("%d,{",j);
119
 
120
      j = 0;
121
      numops = 0;
122
      for (i = 0; i < 6; i++)
123
        {
124
          int flags = v850_operands[opcode->operands[i]].flags;
125
          int shift = v850_operands[opcode->operands[i]].shift;
126
 
127
          if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
128
            {
129
              if (j)
130
                printf (", ");
131
              printf ("%d,%d,%d", shift,
132
                      v850_operands[opcode->operands[i]].bits,flags);
133
              j = 1;
134
              numops++;
135
            }
136
        }
137
 
138
      switch (numops)
139
        {
140
        case 0:
141
          printf ("0,0,0");
142
        case 1:
143
          printf (",0,0,0");
144
        }
145
 
146
      printf ("}},\n");
147
    }
148
  printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n");
149
}

powered by: WebSVN 2.1.0

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