forked from katef/libfsm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathir.h
126 lines (103 loc) · 2.31 KB
/
ir.h
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
/*
* Copyright 2018 Katherine Flavel
*
* See LICENCE for the full copyright terms.
*/
#ifndef FSM_INTERNAL_IR_H
#define FSM_INTERNAL_IR_H
/*
* Codegen IR intended for C-like switch statements
*
* The fsm_state structs don't exist from this IR onwards.
* These nodes are always DFA. No epsilons, No duplicate edge labels,
* so this IR takes advantage of that.
*
* But this is not neccessarily a minimal DFA. By this stage,
* we're done with graph algorithmics.
*/
struct fsm_options;
enum ir_strategy {
IR_NONE = 1 << 0,
IR_SAME = 1 << 1,
IR_COMPLETE = 1 << 2,
IR_PARTIAL = 1 << 3,
IR_DOMINANT = 1 << 4,
IR_ERROR = 1 << 5,
IR_TABLE = 1 << 6
};
/* ranges are inclusive */
struct ir_range {
unsigned char start;
unsigned char end;
};
/*
* Each group represents a single destination state, and the same state
* cannot appear in multiple groups.
*/
struct ir_group {
unsigned to;
size_t n;
const struct ir_range *ranges; /* array */
};
struct ir_error {
size_t n;
const struct ir_range *ranges; /* array */
};
struct ir_state {
const char *example;
struct ir_state_endids {
fsm_end_id_t *ids; /* NULL -> 0 */
size_t count;
} endids;
struct ir_state_eager_output {
size_t count;
fsm_output_id_t ids[];
} *eager_outputs; /* NULL -> 0 */
unsigned int isend:1;
enum ir_strategy strategy;
union {
struct {
unsigned to;
} same;
struct {
size_t n;
const struct ir_group *groups; /* array */
} complete;
struct {
size_t n;
const struct ir_group *groups; /* array */
} partial;
struct {
unsigned mode;
size_t n;
const struct ir_group *groups; /* array */
} dominant;
struct {
unsigned mode;
struct ir_error error;
size_t n;
const struct ir_group *groups; /* array */
} error;
struct {
/* Note: This is allocated separately, to avoid
* making the union significantly larger. */
struct ir_state_table {
unsigned to[FSM_SIGMA_COUNT];
} *table;
} table;
} u;
};
struct ir {
size_t n;
unsigned start;
struct ir_state *states; /* array */
};
/* caller frees */
int
make_example(const struct fsm *fsm, fsm_state_t s, char **example);
/* TODO: can pass in mask of allowed strategies */
struct ir *
make_ir(const struct fsm *fsm, const struct fsm_options *opt);
void
free_ir(const struct fsm *fsm, struct ir *ir);
#endif