3 #include "clast_scanner.h"
5 void clast_scanner::print(clast_name
*n
)
7 fprintf(dst
, "%s", n
->name
);
10 void clast_scanner::print(clast_term
*t
)
12 cloog_int_print(dst
, t
->val
);
15 if (t
->var
->type
== clast_expr_red
)
18 if (t
->var
->type
== clast_expr_red
)
23 void clast_scanner::print(clast_binary
*b
)
28 s1
= "MOD(", s2
= ", ";
34 s1
= "DIVCEIL(", s2
= ", ";
37 s1
= "DIVFLOOR(", s2
= ", ";
45 cloog_int_print(dst
, b
->RHS
);
49 void clast_scanner::print(clast_reduction
*r
)
56 const char *s1
, *s2
, *s3
;
60 s1
= "", s2
= " + ", s3
= "";
63 s1
= "MAX(", s2
= ", ", s3
= ")";
66 s1
= "MIN(", s2
= ", ", s3
= ")";
72 for (int i
= 1; i
< r
->n
; ++i
)
75 for (int i
= 1; i
< r
->n
; ++i
) {
82 void clast_scanner::print(clast_expr
*e
)
86 print((clast_name
*) e
);
89 print((clast_term
*) e
);
92 print((clast_reduction
*) e
);
95 print((clast_binary
*) e
);
102 void clast_scanner::print(clast_assignment
*a
)
105 fprintf(dst
, "%s = ", a
->LHS
);
110 void clast_scanner::print(clast_guard
*g
)
114 fprintf(dst
, "if (");
115 for (int i
= 0; i
< n
; ++i
) {
120 if (g
->eq
[i
].sign
== 0)
122 else if (g
->eq
[i
].sign
> 0)
129 fprintf(dst
, ") {\n");
137 void clast_scanner::print(clast_for
*f
)
139 assert(f
->LB
&& f
->UB
);
141 fprintf(dst
, "for (%s=", f
->iterator
);
143 fprintf(dst
, "; %s<=", f
->iterator
);
145 fprintf(dst
, "; ++%s) {\n", f
->iterator
);
153 void clast_scanner::print(clast_stmt
*s
)
155 for ( ; s
; s
= s
->next
) {
156 if (CLAST_STMT_IS_A(s
, stmt_root
))
158 if (CLAST_STMT_IS_A(s
, stmt_ass
)) {
159 print((clast_assignment
*) s
);
160 } else if (CLAST_STMT_IS_A(s
, stmt_user
)) {
161 print_user((clast_user_stmt
*) s
);
162 } else if (CLAST_STMT_IS_A(s
, stmt_for
)) {
163 print((clast_for
*) s
);
164 } else if (CLAST_STMT_IS_A(s
, stmt_guard
)) {
165 print((clast_guard
*) s
);
172 void clast_scanner::print_header()
174 fprintf(dst
, "%s", "#include <assert.h>\n");
175 fprintf(dst
, "%s", "#include <stdio.h>\n");
176 fprintf(dst
, "%s", "#define MIN(x,y)\t" "((x)<(y)?(x):(y))" "\n");
177 fprintf(dst
, "%s", "#define MAX(x,y)\t" "((x)>(y)?(x):(y))" "\n");
178 fprintf(dst
, "%s", "#define MOD(x,y)\t" "((((x) % (y)) < 0) ? "
179 "(((y) < 0) ? (((x) % (y)) - (y)) : (((x) % (y)) + (y))) : ((x) % (y)))"
181 fprintf(dst
, "%s", "#define DIVCEIL(x,y)\t" "(((x)<0)^((y)<0) ? (x)/(y) : "
182 "((x) < 0 ? ((x)+(y)+1)/(y) : ((x)+(y)-1)/(y)))" "\n");
183 fprintf(dst
, "%s", "#define DIVFLOOR(x,y)\t"
184 "(((x)<0)^((y)<0) ? ((x) < 0 ? ((x)-(y)+1)/(y) : ((x)-(y)-1)/(y)) : "
188 void clast_scanner::print_iterators(CloogNames
* names
)
191 if (names
->nb_iterators
<= 0)
193 fprintf(dst
, "int ");
194 for (int i
= 0; i
< names
->nb_iterators
; ++i
) {
197 fprintf(dst
, names
->iterators
[i
]);