-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
142 lines (114 loc) · 2.61 KB
/
parser.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef _PARSER_H
#define _PARSER_H
#include <stdio.h>
#include <stdlib.h>
struct symbol
{
/* symbol name */
char *str;
/* single bit value */
int bit_length;
long value;
/* array */
void *array;
int *array_size;
int array_depth;
/* some complex form of symbol like number range */
struct element *predefined;
struct symbol *next;
};
enum mnemonic
{
mnemonic_bslbf,
mnemonic_uimsbf,
mnemonic_simsbf,
mnemonic_vlclbf,
};
#define element_type(n) element_type_##n,
enum element_type
{
#include "parser_element_types.h"
};
#undef element_type
extern const char *element_type_name[];
struct element
{
enum element_type type;
int data_num;
void **data;
/* used when listing same element types. NULL if its end */
struct element *next, *prev;
};
struct element *element_new (enum element_type type, int args, ...);
extern struct symbol symbol_parser;
struct symbol *symbol_get (struct symbol *root, const char *name);
extern void _error_element (FILE *o, const char *func, int line,
struct element *e, const char *f, ...) __attribute__((format (printf, 5, 6)));
#define LOG_FORMAT_PREFIX "%-24s %4d: "
#if 1
#define debug(f,a...) do{ \
if(debug_level>0) \
printf (LOG_FORMAT_PREFIX f,__func__,__LINE__,##a); \
}while(0)
#else
#define debug(f,a...) do{}while(0)
#endif
#define info(f,a...) printf (LOG_FORMAT_PREFIX f,__func__,__LINE__,##a)
#define error(f,a...) printf (LOG_FORMAT_PREFIX f,__func__,__LINE__,##a)
#define ferror_element(o,e,f,a...) _error_element (o, __func__,__LINE__,e,f,##a)
#define error_element(e,f,a...) _error_element (stdout, __func__,__LINE__,e,f,##a)
enum return_status
{
return_internal_error,
return_bitstream_error, // try again if possible
return_end_of_stream,
};
extern enum return_status return_status;
enum return_type
{
return_type_nothing,
return_type_boolean,
return_type_stream_offset,
return_type_string,
return_type_integer,
return_type_symbol,
return_type_bitlength,
return_type_function_return,
};
struct stream_offset
{
int bytes;
int bits;
};
struct return_value
{
enum return_type type;
union
{
int nothing;
int boolean;
struct stream_offset stream_offset;
const char *string;
long long integer;
struct symbol *symbol;
int bitlength;
struct return_value *function_return;
} v;
};
#define return_value_init(r,t,val) \
do { \
r = calloc (1, sizeof(*r)); \
if (r) \
{ \
r->type = return_type_##t; \
r->v.t = val; \
} \
} while(0)
#define return_value(t,val) \
do { \
struct return_value *r; \
return_value_init(r,t,val); \
return r; \
} while (0)
extern const char *desc_return_value (struct return_value *r);
#endif