1 /*
2  * Copyright 2008-2009 Katholieke Universiteit Leuven
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege, K.U.Leuven, Departement
7  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8  */
9 
10 #ifndef ISL_STREAM_H
11 #define ISL_STREAM_H
12 
13 #include <stdio.h>
14 #include <isl/hash.h>
15 #include <isl/aff_type.h>
16 #include <isl/obj.h>
17 
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 enum isl_token_type { ISL_TOKEN_ERROR = -1,
23 			ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
24 			ISL_TOKEN_IDENT, ISL_TOKEN_GE,
25 			ISL_TOKEN_LE, ISL_TOKEN_GT, ISL_TOKEN_LT,
26 			ISL_TOKEN_NE, ISL_TOKEN_EQ_EQ,
27 			ISL_TOKEN_LEX_GE, ISL_TOKEN_LEX_LE,
28 			ISL_TOKEN_LEX_GT, ISL_TOKEN_LEX_LT,
29 			ISL_TOKEN_TO, ISL_TOKEN_AND,
30 			ISL_TOKEN_OR, ISL_TOKEN_EXISTS, ISL_TOKEN_NOT,
31 			ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN,
32 			ISL_TOKEN_MIN, ISL_TOKEN_MAX, ISL_TOKEN_RAT,
33 			ISL_TOKEN_TRUE, ISL_TOKEN_FALSE,
34 			ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD, ISL_TOKEN_MOD,
35 			ISL_TOKEN_STRING,
36 			ISL_TOKEN_MAP, ISL_TOKEN_AFF,
37 			ISL_TOKEN_LAST };
38 
39 struct isl_token {
40 	int type;
41 
42 	unsigned int on_new_line : 1;
43 	unsigned is_keyword : 1;
44 	int line;
45 	int col;
46 
47 	union {
48 		isl_int	v;
49 		char	*s;
50 		isl_map *map;
51 		isl_pw_aff *pwaff;
52 	} u;
53 };
54 
55 void isl_token_free(struct isl_token *tok);
56 
57 struct isl_stream {
58 	struct isl_ctx	*ctx;
59 	FILE        	*file;
60 	const char  	*str;
61 	int	    	line;
62 	int	    	col;
63 	int	    	eof;
64 
65 	char	    	*buffer;
66 	size_t	    	size;
67 	size_t	    	len;
68 	int	    	c;
69 	int		un[5];
70 	int		n_un;
71 
72 	struct isl_token	*tokens[5];
73 	int	    	n_token;
74 
75 	struct isl_hash_table	*keywords;
76 	enum isl_token_type	 next_type;
77 };
78 
79 struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file);
80 struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str);
81 void isl_stream_free(struct isl_stream *s);
82 
83 void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg);
84 
85 struct isl_token *isl_stream_next_token(struct isl_stream *s);
86 struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s);
87 int isl_stream_next_token_is(struct isl_stream *s, int type);
88 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
89 void isl_stream_flush_tokens(struct isl_stream *s);
90 int isl_stream_eat_if_available(struct isl_stream *s, int type);
91 char *isl_stream_read_ident_if_available(struct isl_stream *s);
92 int isl_stream_eat(struct isl_stream *s, int type);
93 int isl_stream_is_empty(struct isl_stream *s);
94 int isl_stream_skip_line(struct isl_stream *s);
95 
96 enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
97 	const char *name);
98 
99 struct isl_obj isl_stream_read_obj(struct isl_stream *s);
100 __isl_give isl_multi_aff *isl_stream_read_multi_aff(struct isl_stream *s);
101 __isl_give isl_map *isl_stream_read_map(struct isl_stream *s);
102 __isl_give isl_set *isl_stream_read_set(struct isl_stream *s);
103 __isl_give isl_pw_qpolynomial *isl_stream_read_pw_qpolynomial(
104 	struct isl_stream *s);
105 __isl_give isl_union_map *isl_stream_read_union_map(struct isl_stream *s);
106 
107 #if defined(__cplusplus)
108 }
109 #endif
110 
111 #endif
112