Pristine Ack-5.5
[Ack-5.5.git] / modules / src / em_opt / parser.h
1 /* $Id: parser.h,v 1.4 1994/06/24 11:14:33 ceriel Exp $ */
2 #include <stdio.h>
3 #include <system.h>
4
5 /* type of arguments expected by each instruction */
6 #define NOARG  1
7 #define CST    2
8 #define CSTOPT 3
9 #define LAB    4
10 #define DEFILB 5
11 #define PNAM   6
12 #define EXT    7
13
14 #define IDF_TYPE struct id_info
15 struct id_info {
16         struct idf *nextidf;    /* chain all opcodes together */
17         int used;               /* is this op used? */
18         int startpatt;          /* does it start a pattern? */
19         int opcode;             /* opcode of operator */
20         int argfmt;             /* how to access pattern argument */
21 #define id_nextidf      id_user.nextidf
22 #define id_used         id_user.used
23 #define id_startpatt    id_user.startpatt
24 #define id_opcode       id_user.opcode
25 #define id_argfmt       id_user.argfmt
26 };
27 #include <idf_pkg.spec>
28
29 struct exp_node {
30         int node_type;
31         union {
32                 struct {
33                         struct exp_node *left;
34                         struct exp_node *right;
35                 } interior;
36                 int val;
37         } node_args;
38 #define exp_left node_args.interior.left
39 #define exp_right node_args.interior.right
40 #define leaf_val node_args.val
41 };
42
43 struct mnem_elem {
44         struct idf *op_code;
45         struct exp_node *arg;   /* optional arg expression if replacement */
46 };
47
48 struct mnem_list {
49         struct mnem_list *next; /* cdr of list */
50         struct mnem_elem *elem; /* car of list */
51 };
52
53 struct mnems {
54         int m_len;                      /* number of mnem's in pattern */
55         struct mnem_elem **m_elems;     /* array of mnem's */
56 };
57
58 struct action {
59         struct action *next;    /* chain all actions for same state together */
60         int linenum;                    /* line number in patterns */
61         struct exp_node *test;          /* test expression (if any) */
62         struct mnems replacement;       /* replacement pattern */
63 };
64
65 struct state {
66         struct state *next;     /* chain to next entry for this state */
67         struct idf *op;         /* transition on op to.. */
68         int goto_state;         /* state 'goto_state' */
69 };
70
71 #define MAXSTATES       2000
72 #define MAXPATTERN      20
73
74 /* Parser globals */
75 extern struct state     *states[MAXSTATES];
76 extern struct action    *actions[MAXSTATES];
77 extern struct mnems     patterns[MAXSTATES];
78 extern int              numpatterns;    /* Number of patterns */
79 extern int              higheststate;   /* Highest state yet allocated */
80 extern struct idf       *ops;           /* Chained list of all ops */
81 extern int              maxpattern;
82 extern int              maxreplacement;
83 extern int              nerrors;
84 extern FILE             *ofile;
85
86 /* Lexical analyser globals */
87 extern struct idf       *opval;         /* opcode of returned OPCODE*/
88 extern int              lastintval;     /* value of last integer seen */
89 extern int              linenum;        /*line number of input file*/
90
91 /* Functions not returning int */
92 char                    *Malloc();
93 struct exp_node         *mknode();
94 struct exp_node         *mkleaf();
95 struct exp_node         *combinetests();
96 struct mnem_list        *addelem();
97 struct mnem_elem        **constructlist();