Skip to content

Commit d8a82ed

Browse files
committed
Grind now builds (no idea if it runs).
1 parent 346a18e commit d8a82ed

30 files changed

+203
-272
lines changed

util/grind/avl.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
/* $Id$ */
2-
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
34
#include <alloc.h>
5+
#include "avl.h"
46

57
/* Implementation of AVL-trees: trees in which the difference in depth
68
of the left branch and the right branch is at most one.
@@ -29,18 +31,19 @@ struct avl_node
2931
struct avl_tree
3032
{
3133
struct avl_node* root; /* root of the avl tree */
32-
int (*cmp)(AVLtree* x, AVLtree* y); /* address of comparison routine */
34+
int (*cmp)(char* x, char* y); /* address of comparison routine */
3335
};
3436
/* create definitions for new_avl_tree() and free_avl_tree() */
3537
/* STATICALLOCDEF "avl_tree" 2 */
3638

3739
/* The next routine adds a node to an avl tree. It returns 1 if the
3840
tree got deeper.
3941
*/
40-
static int balance_add(ppsc, n, cmp)
41-
struct avl_node** ppsc; /* address of root */
42-
char* n; /* user-supplied information */
43-
int (*cmp)(); /* user-supplied comparison routine */
42+
static int balance_add(
43+
struct avl_node** ppsc /* address of root */,
44+
char* n /* user-supplied information */,
45+
int (*cmp)(char* x, char* y) /* user-supplied comparison routine */
46+
)
4447
{
4548
struct avl_node *psc = *ppsc, *qsc, *ssc;
4649

@@ -165,7 +168,7 @@ int (*cmp)(); /* user-supplied comparison routine */
165168
/* extern struct avl_tree *create_avl_tree(int (*cmp)());
166169
Returns a fresh avl_tree structure.
167170
*/
168-
struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */
171+
struct avl_tree* create_avl_tree(int (*cmp)(char* x, char* y) /* comparison routine */)
169172
{
170173
struct avl_tree* p = new_avl_tree();
171174

@@ -176,8 +179,7 @@ struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */
176179
/* extern add_to_avl_tree(struct avl_tree *tree, char *n);
177180
Adds the information indicated by 'n' to the avl_tree indicated by 'tree'
178181
*/
179-
add_to_avl_tree(tree, n) struct avl_tree* tree; /* tree to be added to */
180-
char* n; /* information */
182+
void add_to_avl_tree(struct avl_tree* tree /* tree to be added to */, char* n /* information */)
181183
{
182184
(void)balance_add(&(tree->root), n, tree->cmp);
183185
}
@@ -186,9 +188,9 @@ char* n; /* information */
186188
Returns the information in the largest node that still compares <= to 'n',
187189
or 0 if not present.
188190
*/
189-
char* find_ngt(tree, n)
190-
struct avl_tree* tree; /* tree to be searched in */
191-
char* n; /* information to be compared with */
191+
char* find_ngt(
192+
struct avl_tree* tree /* tree to be searched in */,
193+
char* n /* information to be compared with */)
192194
{
193195
struct avl_node *nd = tree->root, *lastnd = 0;
194196

@@ -213,9 +215,9 @@ char* n; /* information to be compared with */
213215
Returns the information in the largest node that still compares >= to 'n',
214216
or 0 if not present.
215217
*/
216-
char* find_nlt(tree, n)
217-
struct avl_tree* tree; /* tree to be searched in */
218-
char* n; /* information to be compared with */
218+
char* find_nlt(
219+
struct avl_tree* tree /* tree to be searched in */,
220+
char* n /* information to be compared with */)
219221
{
220222
struct avl_node *nd = tree->root, *lastnd = 0;
221223

@@ -240,9 +242,9 @@ char* n; /* information to be compared with */
240242
Returns the information in the node that compares equal to 'n',
241243
or 0 if not present.
242244
*/
243-
char* find_eq(tree, n)
244-
struct avl_tree* tree; /* tree to be searched in */
245-
char* n; /* information to be compared with */
245+
char* find_eq(
246+
struct avl_tree* tree /* tree to be searched in */,
247+
char* n /* information to be compared with */)
246248
{
247249
struct avl_node* nd = tree->root;
248250

util/grind/avl.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* $Id$ */
1+
#ifndef AVL_H
2+
#define AVL_H
23

34
/* AVL-trees: trees in which the difference in depth
45
of the left branch and the right branch is at most one.
@@ -19,20 +20,22 @@ typedef struct avl_tree* AVL_tree;
1920
extern AVL_tree create_avl_tree(int (*cmp)(char* x, char* y));
2021

2122
/* Adds the information indicated by 'n' to the avl_tree indicated by 'tree'.
22-
*/
23-
extern void add_to_avl_tree(AVL_tree tree, char *n);
23+
*/
24+
extern void add_to_avl_tree(AVL_tree tree, char* n);
2425

2526
/* Returns the information in the largest node that still compares <= to 'n',
2627
or 0 if not present.
2728
*/
28-
extern char *find_ngt(AVL_tree tree, char *n);
29+
extern char* find_ngt(AVL_tree tree, char* n);
2930

3031
/* Returns the information in the largest node that still compares >= to 'n',
3132
or 0 if not present.
3233
*/
33-
extern char *find_nlt(AVL_tree tree, char *n);
34+
extern char* find_nlt(AVL_tree tree, char* n);
3435

3536
/* Returns the information in the node that compares equal to 'n',
3637
or 0 if not present.
3738
*/
38-
extern char *find_eq(AVL_tree tree, char *n);
39+
extern char* find_eq(AVL_tree tree, char* n);
40+
41+
#endif

util/grind/build.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include("util/cmisc/build.lua")
2+
13
local hh_files = {
24
"./tree.hh",
35
"./file.hh",
@@ -31,7 +33,7 @@ end
3133
local c_targets = {}
3234
for _, f in ipairs(cc_bases) do
3335
local bf = f:gsub("%..*$", ""):gsub("^$./", "")
34-
c_targets[#h_targets+1] = normalrule {
36+
c_targets[#c_targets+1] = normalrule {
3537
name = "cc_header/"..bf,
3638
ins = { "./make.allocd", "./"..f },
3739
outleaves = { bf..".c" },
@@ -86,6 +88,10 @@ llgen {
8688
}
8789
}
8890

91+
tabgen {
92+
name = "tabgen_c",
93+
srcs = { "./char.ct" }
94+
}
8995

9096
cprogram {
9197
name = "grind",
@@ -106,37 +112,40 @@ cprogram {
106112
"./tree.c",
107113
"./type.c",
108114
"+tokenname_c",
115+
"+tabgen_c",
109116
matching(filenamesof("+commands_llgen"), "%.c$"),
110117
matching(filenamesof("+db_symtab_llgen"), "%.c$"),
111118
matching(filenamesof("+ops"), "%.c$"),
112119
c_targets,
113120
},
114121
deps = {
115122
"modules/src/data+lib",
123+
"modules/src/em_data+lib",
116124
"modules/src/string+lib",
125+
"modules/src/object+lib",
117126
"modules/src/system+lib",
118127
"+commands_llgen",
119128
"+db_symtab_llgen",
120129
"+ops",
121130
"./class.h",
122131
"./expr.h",
123132
"./idf.h",
133+
"./itemlist.h",
124134
"./langdep.h",
135+
"./lines.h",
125136
"./message.h",
126137
"./misc.h",
127138
"./operator.h",
128139
"./position.h",
140+
"./print.h",
129141
"./rd.h",
130142
"./scope.h",
131143
"./token.h",
132144
"./tokenname.h",
133-
"./print.h",
134-
"./itemlist.h",
135145
"h+emheaders",
136146
"modules+headers",
137147
"modules/src/alloc+lib",
138148
"modules/src/idf+lib",
139-
"modules/src/em_data+lib",
140149
h_targets,
141150
}
142151
}

util/grind/db_symtab.g

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "rd.h"
2323
#include "misc.h"
2424
#include "tree.h"
25+
#include "scope.h"
2526

2627
static char* DbPtr; /* current pointer in db string */
2728
static int AllowName; /* set if NAME legal at this point */
@@ -544,7 +545,7 @@ param_list(p_type t;)
544545
type(&(p->par_type), (int *) 0, (p_symbol) 0) ';'
545546
{ p->par_off = t->ty_nbparams;
546547
t->ty_nbparams +=
547-
param_size(p->par_type, p->par_kind);
548+
param_size(p->par_kind, p->par_type);
548549
p++;
549550
}
550551
]*

util/grind/do_comm.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdio.h>
77
#include <assert.h>
88
#include <alloc.h>
9+
#include <string.h>
910

1011
#include "operator.h"
1112
#include "position.h"
@@ -22,6 +23,9 @@
2223
#include "run.h"
2324
#include "print.h"
2425
#include "itemlist.h"
26+
#include "lines.h"
27+
#include "itemlist.h"
28+
#include "langdep.h"
2529

2630
extern FILE* db_out;
2731
extern t_lineno listline, currline;
@@ -30,8 +34,6 @@ extern int stack_offset;
3034

3135
p_tree print_command;
3236

33-
extern void set_bytes();
34-
3537
/*ARGSUSED*/
3638
void do_noop(p_tree p)
3739
{
@@ -266,9 +268,6 @@ void do_help(p_tree p)
266268

267269
/* implementation of dump/restore commands */
268270

269-
extern p_tree get_from_item_list();
270-
extern t_addr get_dump();
271-
272271
struct dump
273272
{
274273
char *globals, *stack;
@@ -277,7 +276,7 @@ struct dump
277276

278277
static struct dump* last_dump;
279278

280-
void do_dump(p)
279+
void do_dump(p_tree p)
281280
{
282281
struct dump* d = (struct dump*)malloc(sizeof(struct dump));
283282

@@ -298,7 +297,7 @@ void do_dump(p)
298297
last_dump = d;
299298
}
300299

301-
void do_restore(p)
300+
void do_restore(p_tree p)
302301
{
303302
struct dump* d;
304303

@@ -404,8 +403,6 @@ void do_which(p_tree p)
404403

405404
/* implementation of the list command */
406405

407-
extern t_addr get_addr_from_node();
408-
409406
void do_list(p_tree p)
410407
{
411408
int l1, l2;
@@ -523,8 +520,7 @@ void do_file(p_tree p)
523520

524521
/* implementation of stop/when command */
525522

526-
setstop(p_tree p, kind)
527-
int kind;
523+
int setstop(p_tree p, int kind)
528524
{
529525
t_addr a = get_addr_from_node(p->t_args[0]);
530526

@@ -555,8 +551,7 @@ void do_stop(p_tree p)
555551

556552
/* implementation of the trace command */
557553

558-
settrace(p_tree p, kind)
559-
int kind;
554+
int settrace(p_tree p, int kind)
560555
{
561556
t_addr a, e;
562557

@@ -596,8 +591,7 @@ void do_trace(p_tree p)
596591

597592
/* implementation of the enable/disable commands */
598593

599-
static able(p_tree p, kind)
600-
int kind;
594+
static void able(p_tree p, int kind)
601595
{
602596
if (!p)
603597
{
@@ -723,8 +717,7 @@ void do_regs(p_tree p)
723717

724718
static t_addr where_PC;
725719

726-
static int where_entry(
727-
int num)
720+
static int where_entry(int num)
728721
{
729722
t_addr* buf;
730723
t_addr AB;
@@ -933,7 +926,7 @@ void do_prcomm(p_tree p)
933926

934927
extern int stack_offset;
935928

936-
static void frame_pos( int diff)
929+
static void frame_pos(int diff)
937930
{
938931
if (stack_offset + diff < 0)
939932
diff = -stack_offset;

util/grind/do_comm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
#define DO_COMM_H
33

44
extern void enterlog(p_tree p);
5+
extern int setstop(p_tree p, int kind);
6+
extern int settrace(p_tree p, int kind);
7+
extern void free_dump(p_tree p);
58

69
#endif

0 commit comments

Comments
 (0)