summaryrefslogtreecommitdiff
path: root/regcomp.pl
blob: ee63d05698876651a46be2f2048a63b01a8edca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
BEGIN {
    # Get function prototypes
    require 'regen_lib.pl';
}
#use Fatal qw(open close rename chmod unlink);
open DESC, 'regcomp.sym';
$ind = 0;

while (<DESC>) {
  next if /^\s*($|\#)/;
  $ind++;
  chomp;
  ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3;
  ($type[$ind], $code[$ind], $args[$ind], $longj[$ind]) 
    = split /[,\s]\s*/, $desc, 4;
}
close DESC;
$tot = $ind;

$tmp_h = 'tmp_reg.h';

unlink $tmp_h if -f $tmp_h;

open OUT, ">$tmp_h";
binmode OUT;

print OUT <<EOP;
/* -*- buffer-read-only: t -*-
   !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
   This file is built by regcomp.pl from regcomp.sym.
   Any changes made here will be lost!
*/

/* Regops and State definitions */

EOP

$ind = 0;
while (++$ind <= $tot) {
  $oind = $ind - 1;
  $hind = sprintf "%#4x", $oind;
  print OUT <<EOP;
#define	$name[$ind]	$oind	/* $hind $rest[$ind] */
EOP
}

print OUT <<EOP;

/* PL_regkind[] What type of regop or state is this. */
#ifndef DOINIT
EXTCONST U8 PL_regkind[];
#else
EXTCONST U8 PL_regkind[] = {
EOP

$ind = 0;
while (++$ind <= $tot) {
  print OUT <<EOP;
	$type[$ind],		/* $name[$ind] */
EOP
}

print OUT <<EOP;
};
#endif

/* regarglen[] - How large is the argument part of the node (in regnodes) */

#ifdef REG_COMP_C
static const U8 regarglen[] = {
EOP

$ind = 0;
while (++$ind <= $tot) {
  $size = 0;
  $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
  
  print OUT <<EOP;
	$size,		/* $name[$ind] */
EOP
}

print OUT <<EOP;
};

/* reg_off_by_arg[] - Which argument holds the offset to the next node */

static const char reg_off_by_arg[] = {
EOP

$ind = 0;
while (++$ind <= $tot) {
  $size = $longj[$ind] || 0;

  print OUT <<EOP;
	$size,		/* $name[$ind] */
EOP
}

print OUT <<EOP;
};

/* reg_name[] - Opcode/state names in string form, for debugging */

#ifdef DEBUGGING
static const char * const reg_name[] = {
EOP

$ind = 0;
while (++$ind <= $tot) {
  $hind = sprintf "%#4x", $ind-1;
  $size = $longj[$ind] || 0;

  print OUT <<EOP;
	"$name[$ind]",		/* $hind */
EOP
}

print OUT <<EOP;
};

static const int reg_num = $tot;

#endif /* DEBUGGING */
#endif /* REG_COMP_C */

/* ex: set ro: */
EOP

close OUT or die "close $tmp_h: $!";

safer_rename $tmp_h, 'regnodes.h';