Skip to content

Commit

Permalink
Grind now builds (no idea if it runs).
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Dec 15, 2024
1 parent 346a18e commit d8a82ed
Show file tree
Hide file tree
Showing 30 changed files with 203 additions and 272 deletions.
40 changes: 21 additions & 19 deletions util/grind/avl.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* $Id$ */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include "avl.h"

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

/* The next routine adds a node to an avl tree. It returns 1 if the
tree got deeper.
*/
static int balance_add(ppsc, n, cmp)
struct avl_node** ppsc; /* address of root */
char* n; /* user-supplied information */
int (*cmp)(); /* user-supplied comparison routine */
static int balance_add(
struct avl_node** ppsc /* address of root */,
char* n /* user-supplied information */,
int (*cmp)(char* x, char* y) /* user-supplied comparison routine */
)
{
struct avl_node *psc = *ppsc, *qsc, *ssc;

Expand Down Expand Up @@ -165,7 +168,7 @@ int (*cmp)(); /* user-supplied comparison routine */
/* extern struct avl_tree *create_avl_tree(int (*cmp)());
Returns a fresh avl_tree structure.
*/
struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */
struct avl_tree* create_avl_tree(int (*cmp)(char* x, char* y) /* comparison routine */)
{
struct avl_tree* p = new_avl_tree();

Expand All @@ -176,8 +179,7 @@ struct avl_tree* create_avl_tree(cmp) int (*cmp)(); /* comparison routine */
/* extern add_to_avl_tree(struct avl_tree *tree, char *n);
Adds the information indicated by 'n' to the avl_tree indicated by 'tree'
*/
add_to_avl_tree(tree, n) struct avl_tree* tree; /* tree to be added to */
char* n; /* information */
void add_to_avl_tree(struct avl_tree* tree /* tree to be added to */, char* n /* information */)
{
(void)balance_add(&(tree->root), n, tree->cmp);
}
Expand All @@ -186,9 +188,9 @@ char* n; /* information */
Returns the information in the largest node that still compares <= to 'n',
or 0 if not present.
*/
char* find_ngt(tree, n)
struct avl_tree* tree; /* tree to be searched in */
char* n; /* information to be compared with */
char* find_ngt(
struct avl_tree* tree /* tree to be searched in */,
char* n /* information to be compared with */)
{
struct avl_node *nd = tree->root, *lastnd = 0;

Expand All @@ -213,9 +215,9 @@ char* n; /* information to be compared with */
Returns the information in the largest node that still compares >= to 'n',
or 0 if not present.
*/
char* find_nlt(tree, n)
struct avl_tree* tree; /* tree to be searched in */
char* n; /* information to be compared with */
char* find_nlt(
struct avl_tree* tree /* tree to be searched in */,
char* n /* information to be compared with */)
{
struct avl_node *nd = tree->root, *lastnd = 0;

Expand All @@ -240,9 +242,9 @@ char* n; /* information to be compared with */
Returns the information in the node that compares equal to 'n',
or 0 if not present.
*/
char* find_eq(tree, n)
struct avl_tree* tree; /* tree to be searched in */
char* n; /* information to be compared with */
char* find_eq(
struct avl_tree* tree /* tree to be searched in */,
char* n /* information to be compared with */)
{
struct avl_node* nd = tree->root;

Expand Down
15 changes: 9 additions & 6 deletions util/grind/avl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* $Id$ */
#ifndef AVL_H
#define AVL_H

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

/* Adds the information indicated by 'n' to the avl_tree indicated by 'tree'.
*/
extern void add_to_avl_tree(AVL_tree tree, char *n);
*/
extern void add_to_avl_tree(AVL_tree tree, char* n);

/* Returns the information in the largest node that still compares <= to 'n',
or 0 if not present.
*/
extern char *find_ngt(AVL_tree tree, char *n);
extern char* find_ngt(AVL_tree tree, char* n);

/* Returns the information in the largest node that still compares >= to 'n',
or 0 if not present.
*/
extern char *find_nlt(AVL_tree tree, char *n);
extern char* find_nlt(AVL_tree tree, char* n);

/* Returns the information in the node that compares equal to 'n',
or 0 if not present.
*/
extern char *find_eq(AVL_tree tree, char *n);
extern char* find_eq(AVL_tree tree, char* n);

#endif
17 changes: 13 additions & 4 deletions util/grind/build.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include("util/cmisc/build.lua")

local hh_files = {
"./tree.hh",
"./file.hh",
Expand Down Expand Up @@ -31,7 +33,7 @@ end
local c_targets = {}
for _, f in ipairs(cc_bases) do
local bf = f:gsub("%..*$", ""):gsub("^$./", "")
c_targets[#h_targets+1] = normalrule {
c_targets[#c_targets+1] = normalrule {
name = "cc_header/"..bf,
ins = { "./make.allocd", "./"..f },
outleaves = { bf..".c" },
Expand Down Expand Up @@ -86,6 +88,10 @@ llgen {
}
}

tabgen {
name = "tabgen_c",
srcs = { "./char.ct" }
}

cprogram {
name = "grind",
Expand All @@ -106,37 +112,40 @@ cprogram {
"./tree.c",
"./type.c",
"+tokenname_c",
"+tabgen_c",
matching(filenamesof("+commands_llgen"), "%.c$"),
matching(filenamesof("+db_symtab_llgen"), "%.c$"),
matching(filenamesof("+ops"), "%.c$"),
c_targets,
},
deps = {
"modules/src/data+lib",
"modules/src/em_data+lib",
"modules/src/string+lib",
"modules/src/object+lib",
"modules/src/system+lib",
"+commands_llgen",
"+db_symtab_llgen",
"+ops",
"./class.h",
"./expr.h",
"./idf.h",
"./itemlist.h",
"./langdep.h",
"./lines.h",
"./message.h",
"./misc.h",
"./operator.h",
"./position.h",
"./print.h",
"./rd.h",
"./scope.h",
"./token.h",
"./tokenname.h",
"./print.h",
"./itemlist.h",
"h+emheaders",
"modules+headers",
"modules/src/alloc+lib",
"modules/src/idf+lib",
"modules/src/em_data+lib",
h_targets,
}
}
Expand Down
3 changes: 2 additions & 1 deletion util/grind/db_symtab.g
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rd.h"
#include "misc.h"
#include "tree.h"
#include "scope.h"

static char* DbPtr; /* current pointer in db string */
static int AllowName; /* set if NAME legal at this point */
Expand Down Expand Up @@ -544,7 +545,7 @@ param_list(p_type t;)
type(&(p->par_type), (int *) 0, (p_symbol) 0) ';'
{ p->par_off = t->ty_nbparams;
t->ty_nbparams +=
param_size(p->par_type, p->par_kind);
param_size(p->par_kind, p->par_type);
p++;
}
]*
Expand Down
29 changes: 11 additions & 18 deletions util/grind/do_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <assert.h>
#include <alloc.h>
#include <string.h>

#include "operator.h"
#include "position.h"
Expand All @@ -22,6 +23,9 @@
#include "run.h"
#include "print.h"
#include "itemlist.h"
#include "lines.h"
#include "itemlist.h"
#include "langdep.h"

extern FILE* db_out;
extern t_lineno listline, currline;
Expand All @@ -30,8 +34,6 @@ extern int stack_offset;

p_tree print_command;

extern void set_bytes();

/*ARGSUSED*/
void do_noop(p_tree p)
{
Expand Down Expand Up @@ -266,9 +268,6 @@ void do_help(p_tree p)

/* implementation of dump/restore commands */

extern p_tree get_from_item_list();
extern t_addr get_dump();

struct dump
{
char *globals, *stack;
Expand All @@ -277,7 +276,7 @@ struct dump

static struct dump* last_dump;

void do_dump(p)
void do_dump(p_tree p)
{
struct dump* d = (struct dump*)malloc(sizeof(struct dump));

Expand All @@ -298,7 +297,7 @@ void do_dump(p)
last_dump = d;
}

void do_restore(p)
void do_restore(p_tree p)
{
struct dump* d;

Expand Down Expand Up @@ -404,8 +403,6 @@ void do_which(p_tree p)

/* implementation of the list command */

extern t_addr get_addr_from_node();

void do_list(p_tree p)
{
int l1, l2;
Expand Down Expand Up @@ -523,8 +520,7 @@ void do_file(p_tree p)

/* implementation of stop/when command */

setstop(p_tree p, kind)
int kind;
int setstop(p_tree p, int kind)
{
t_addr a = get_addr_from_node(p->t_args[0]);

Expand Down Expand Up @@ -555,8 +551,7 @@ void do_stop(p_tree p)

/* implementation of the trace command */

settrace(p_tree p, kind)
int kind;
int settrace(p_tree p, int kind)
{
t_addr a, e;

Expand Down Expand Up @@ -596,8 +591,7 @@ void do_trace(p_tree p)

/* implementation of the enable/disable commands */

static able(p_tree p, kind)
int kind;
static void able(p_tree p, int kind)
{
if (!p)
{
Expand Down Expand Up @@ -723,8 +717,7 @@ void do_regs(p_tree p)

static t_addr where_PC;

static int where_entry(
int num)
static int where_entry(int num)
{
t_addr* buf;
t_addr AB;
Expand Down Expand Up @@ -933,7 +926,7 @@ void do_prcomm(p_tree p)

extern int stack_offset;

static void frame_pos( int diff)
static void frame_pos(int diff)
{
if (stack_offset + diff < 0)
diff = -stack_offset;
Expand Down
3 changes: 3 additions & 0 deletions util/grind/do_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
#define DO_COMM_H

extern void enterlog(p_tree p);
extern int setstop(p_tree p, int kind);
extern int settrace(p_tree p, int kind);
extern void free_dump(p_tree p);

#endif
Loading

0 comments on commit d8a82ed

Please sign in to comment.