update isl to version 0.10
[ppcg.git] / pet_printer.c
bloba96a4e5218daed412b398d522cec16ef3d70392e
1 /*
2 * Copyright 2010-2011 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 #include "pet_printer.h"
12 #include "pet.h"
14 static void print_pet_expr_help(FILE *out, struct pet_expr *expr, int outer,
15 void (*print_access_fn)(struct pet_expr *expr, void *usr), void *usr)
17 int i;
19 switch (expr->type) {
20 case pet_expr_double:
21 fprintf(out, "%g", expr->d);
22 break;
23 case pet_expr_access:
24 print_access_fn(expr, usr);
25 break;
26 case pet_expr_unary:
27 if (!outer)
28 fprintf(out, "(");
29 fprintf(out, " %s ", pet_op_str(expr->op));
30 print_pet_expr_help(out, expr->args[pet_un_arg], 0,
31 print_access_fn, usr);
32 if (!outer)
33 fprintf(out, ")");
34 break;
35 case pet_expr_binary:
36 if (!outer)
37 fprintf(out, "(");
38 print_pet_expr_help(out, expr->args[pet_bin_lhs], 0,
39 print_access_fn, usr);
40 fprintf(out, " %s ", pet_op_str(expr->op));
41 print_pet_expr_help(out, expr->args[pet_bin_rhs], 0,
42 print_access_fn, usr);
43 if (!outer)
44 fprintf(out, ")");
45 break;
46 case pet_expr_ternary:
47 if (!outer)
48 fprintf(out, "(");
49 print_pet_expr_help(out, expr->args[pet_ter_cond], 0,
50 print_access_fn, usr);
51 fprintf(out, " ? ");
52 print_pet_expr_help(out, expr->args[pet_ter_true], 0,
53 print_access_fn, usr);
54 fprintf(out, " : ");
55 print_pet_expr_help(out, expr->args[pet_ter_false], 0,
56 print_access_fn, usr);
57 if (!outer)
58 fprintf(out, ")");
59 break;
60 case pet_expr_call:
61 fprintf(out, "%s(", expr->name);
62 for (i = 0; i < expr->n_arg; ++i) {
63 if (i)
64 fprintf(out, ", ");
65 print_pet_expr_help(out, expr->args[i], 1,
66 print_access_fn, usr);
68 fprintf(out, ")");
72 void print_pet_expr(FILE *out, struct pet_expr *expr,
73 void(*print_access)(struct pet_expr *expr, void *usr), void *usr)
75 print_pet_expr_help(out, expr, 1, print_access, usr);