f62eb8fc8855c8f75e678c6ed63d86383ceb5c9b
[libfirm] / ir / ir / irvrfy.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2  * All rights reserved.
3  *
4  * Authors: Christian Schaefer
5  *
6  *
7  */
8
9 /* $Id$ */
10
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14
15 # include "irgraph_t.h"
16 # include "irvrfy.h"
17 # include "irgwalk.h"
18
19 #ifdef NDEBUG
20 /*
21  * in RELEASE mode, returns ret if the expression expr evaluates to zero
22  * in ASSERT mode, asserts the expression expr (and the string string).
23  */
24 #define ASSERT_AND_RET(expr, string, ret)               if (!(expr)) return (ret)
25
26 /*
27  * in RELEASE mode, returns ret if the expression expr evaluates to zero
28  * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts
29  */
30 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)      if (!(expr)) return (ret)
31 #else
32 #define ASSERT_AND_RET(expr, string, ret)               do { assert((expr) && string); if (!(expr)) return (ret); } while(0)
33 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)      do { if (!(expr)) { { blk } assert(0 && string); return (ret); } } while(0)
34 #endif
35
36 /* @@@ replace use of array "in" by access functions. */
37 ir_node **get_irn_in(ir_node *node);
38
39 INLINE static int
40 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
41   ir_node *pred;
42   ir_mode *mode;
43   int proj;
44
45   pred = skip_nop(get_Proj_pred(p));
46   assert(get_irn_mode(pred) == mode_T);
47   mode = get_irn_mode(p);
48   proj = get_Proj_proj(p);
49
50   switch (get_irn_opcode(pred)) {
51     case iro_Start:
52       ASSERT_AND_RET(
53           (
54            (proj == pns_initial_exec   && mode == mode_X) ||
55            (proj == pns_global_store   && mode == mode_M) ||
56            (proj == pns_frame_base     && mode_is_reference(mode)) ||
57            (proj == pns_globals        && mode_is_reference(mode)) ||
58            (proj == pns_args           && mode == mode_T) ||
59            (proj == pns_value_arg_base && mode_is_reference(mode))
60           ),
61           "wrong Proj from Start", 0);
62       break;
63
64     case iro_Cond:
65       ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from Cond", 0);
66       break;
67
68     case iro_Raise:
69       ASSERT_AND_RET(
70           ((proj == 0 && mode == mode_X) ||
71            (proj == 1 && mode == mode_M)),
72           "wrong Proj from Raise", 0);
73       break;
74
75     case iro_InstOf:
76       ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from InstOf", 0);
77       break;
78
79     case iro_Call:
80       ASSERT_AND_RET(
81           ((proj == 0 && mode == mode_M) ||
82            (proj == 1 && mode == mode_X) ||
83            (proj == 2 && mode == mode_T) ||
84            (proj == 3 && mode == mode_M)),
85           "wrong Proj from Call", 0);
86       break;
87
88     case iro_Quot:
89       ASSERT_AND_RET(
90           ((proj == 0 && mode == mode_M) ||
91            (proj == 1 && mode == mode_X) ||
92            (proj == 2 && mode_is_float(mode))),
93           "wrong Proj from Quot", 0);
94       break;
95
96     case iro_DivMod:
97       ASSERT_AND_RET(
98           ((proj == 0 && mode == mode_M) ||
99            (proj == 1 && mode == mode_X) ||
100            (proj == 2 && mode == mode_Is) ||
101            (proj == 3 && mode_is_int(mode))),
102           "wrong Proj from DivMod", 0);
103       break;
104
105     case iro_Div:
106     case iro_Mod:
107       ASSERT_AND_RET(
108           ((proj == 0 && mode == mode_M) ||
109            (proj == 1 && mode == mode_X) ||
110            (proj == 2 && mode_is_int(mode))),
111           "wrong Proj from Div or Mod", 0);
112       break;
113
114     case iro_Cmp:
115       ASSERT_AND_RET(
116           (proj >= 0 && proj <= 15 && mode == mode_b),
117           "wrong Proj from Cmp", 0);
118       break;
119
120     case iro_Load:
121       ASSERT_AND_RET(
122           ((proj == 0 && mode == mode_M) ||
123            (proj == 1 && mode == mode_X) ||
124            (proj == 2 && mode_is_data(mode))),
125           "wrong Proj from Load", 0);
126       break;
127
128     case iro_Store:
129       ASSERT_AND_RET(
130           ((proj == 0 && mode == mode_M) ||
131            (proj == 1 && mode == mode_X)),
132           "wrong Proj from Store", 0);
133       break;
134
135     case iro_Alloc:
136       ASSERT_AND_RET(
137           (
138            (proj == 0 && mode == mode_M) ||
139            (proj == 1 /* && mode == mode_X*/) ||
140            (proj == 2 && mode_is_reference(mode))
141           ),
142           "wrong Proj from Alloc", 0);
143       break;
144
145     case iro_Proj:
146       {
147         type *mt; /* A method type */
148         pred = skip_nop(get_Proj_pred(pred));
149         ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
150         switch (get_irn_opcode(pred))
151         {
152           case iro_Start:
153             {
154               ASSERT_AND_RET(
155                   (proj >= 0 && mode_is_data(mode)),
156                   "wrong Proj from Proj from Start", 0);
157               mt = get_entity_type(get_irg_ent(irg));
158               ASSERT_AND_RET(
159                   (proj < get_method_n_params(mt)),
160                   "More Projs for args than args in type", 0);
161               if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
162                 /* value argument */ break;
163
164               ASSERT_AND_RET(
165                   (mode == get_type_mode(get_method_param_type(mt, proj))),
166                   "Mode of Proj from Start doesn't match mode of param type.", 0);
167             }
168             break;
169
170           case iro_Call:
171             {
172               ASSERT_AND_RET(
173                   (proj >= 0 && mode_is_data(mode)),
174                   "wrong Proj from Proj from Call", 0);
175               mt = get_Call_type(pred);
176               ASSERT_AND_RET(
177                   (proj < get_method_n_ress(mt)),
178                   "More Projs for results than results in type.", 0);
179               if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
180                 /* value result */ break;
181
182               ASSERT_AND_RET(
183                   (mode == get_type_mode(get_method_res_type(mt, proj))),
184                   "Mode of Proj from Call doesn't match mode of result type.", 0);
185             }
186             break;
187
188           case iro_Tuple:
189             /* We don't test */
190             break;
191
192           default:
193             ASSERT_AND_RET(0, "Unknown opcode", 0);
194         }
195         break;
196
197       }
198     case iro_Tuple:
199       /* We don't test */
200       break;
201
202     case iro_CallBegin:
203       break;
204
205     case iro_EndReg:
206       break;
207
208     case iro_EndExcept:
209       break;
210
211     default:
212       ASSERT_AND_RET(0, "Unknown opcode", 0);
213   }
214
215   /* all went ok */
216   return 1;
217 }
218
219 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
220 {
221   int i;
222   int opcode, opcode1;
223   ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
224   int op_is_symmetric = 1;  /*  0: asymmetric
225 1: operands have identical modes
226 2: modes of operands == mode of this node */
227   type *mt; /* A method type */
228
229   ir_node **in;
230
231   if (! interprocedural_view) {
232     /*
233      * do NOT check placement in interprocedural view, as we don't always know
234      * the "right" graph ...
235      */
236     ASSERT_AND_RET(node_is_in_irgs_storage(irg, n), "Node is not stored on proper IR graph!", 0);
237   }
238
239   opcode = get_irn_opcode (n);
240
241   /* We don't want to test nodes whose predecessors are Bad or Unknown,
242      as we would have to special case that for each operation. */
243   if (opcode != iro_Phi && opcode != iro_Block)
244     for (i = 0; i < get_irn_arity(n); i++) {
245       opcode1 = get_irn_opcode(get_irn_n(n, i));
246       if (opcode1 == iro_Bad || opcode1 == iro_Unknown)
247         return 1;
248     }
249
250   mymode = get_irn_mode (n);
251   in = get_irn_in (n);
252
253   switch (opcode)
254   {
255     case iro_Start:
256       ASSERT_AND_RET(
257           /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
258           mymode == mode_T, "Start node", 0
259           );
260       break;
261
262     case iro_Jmp:
263       ASSERT_AND_RET(
264           /* Jmp: BB --> X */
265           mymode == mode_X, "Jmp node", 0
266           );
267       break;
268
269     case iro_Break:
270       ASSERT_AND_RET(
271           /* Jmp: BB --> X */
272           mymode == mode_X, "Jmp node", 0
273           );
274       break;
275
276     case iro_Cond:
277       op1mode = get_irn_mode(in[1]);
278       ASSERT_AND_RET(
279           /* Cond: BB x b --> X x X */
280           (op1mode == mode_b ||
281            /* Cond: BB x int --> X^n */
282            mode_is_int(op1mode) ),  "Cond node", 0
283           );
284       ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
285       break;
286
287     case iro_Return:
288       op1mode = get_irn_mode(in[1]);
289       /* Return: BB x M x data1 x ... x datan --> X */
290       /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
291       ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 );  /* operand M */
292       for (i=2; i < get_irn_arity(n); i++) {
293         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 );  /* operand datai */
294       };
295       ASSERT_AND_RET( mymode == mode_X, "Result X", 0 );   /* result X */
296       /* Compare returned results with result types of method type */
297       mt = get_entity_type(get_irg_ent(irg));
298       ASSERT_AND_RET( get_Return_n_ress(n) == get_method_n_ress(mt),
299           "Number of results for Return doesn't match number of results in type.", 0 );
300       for (i = 0; i < get_Return_n_ress(n); i++)
301         ASSERT_AND_RET(
302             get_irn_mode(get_Return_res(n, i)) == get_type_mode(get_method_res_type(mt, i)),
303             "Mode of result for Return doesn't match mode of result type.", 0);
304       break;
305
306     case iro_Raise:
307       op1mode = get_irn_mode(in[1]);
308       op2mode = get_irn_mode(in[2]);
309       ASSERT_AND_RET(
310           /* Sel: BB x M x ref --> X x M */
311           op1mode == mode_M && mode_is_reference(op2mode) &&
312           mymode == mode_T, "Raise node", 0
313           );
314       break;
315
316     case iro_Const:
317       ASSERT_AND_RET(
318           /* Const: BB --> data */
319           (mode_is_data (mymode) ||
320            mymode == mode_b)      /* we want boolean constants for static evaluation */
321           ,"Const node", 0        /* of Cmp. */
322           );
323       break;
324
325     case iro_SymConst:
326       ASSERT_AND_RET(
327           /* SymConst: BB --> int*/
328           (mode_is_int(mymode) ||
329            /* SymConst: BB --> ref */
330            mode_is_reference(mymode))
331           ,"SymConst node", 0);
332       break;
333
334     case iro_Sel:
335       op1mode = get_irn_mode(in[1]);
336       op2mode = get_irn_mode(in[2]);
337       ASSERT_AND_RET(
338           /* Sel: BB x M x ref x int^n --> ref */
339           (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
340           "Sel node", 0
341           );
342       for (i=3; i < get_irn_arity(n); i++)
343       {
344         ASSERT_AND_RET(mode_is_int(get_irn_mode(in[i])), "Sel node", 0);
345       }
346       break;
347
348     case iro_InstOf:
349       ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
350       ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
351       break;
352
353     case iro_Call:
354       op1mode = get_irn_mode(in[1]);
355       op2mode = get_irn_mode(in[2]);
356       /* Call: BB x M x ref x data1 x ... x datan
357          --> M x datan+1 x ... x data n+m */
358       ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 );  /* operand M x ref */
359       for (i=3; i < get_irn_arity(n); i++) {
360         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 );  /* operand datai */
361       };
362       ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 );   /* result T */
363       /* Compare arguments of node with those of type */
364       mt = get_Call_type(n);
365
366       if (get_method_variadicity(mt) == variadic) {
367         ASSERT_AND_RET(
368             get_Call_n_params(n) >= get_method_n_params(mt),
369             "Number of args for Call doesn't match number of args in variadic type.",
370             0);
371       }
372       else {
373         ASSERT_AND_RET(
374             get_Call_n_params(n) == get_method_n_params(mt),
375             "Number of args for Call doesn't match number of args in non variadic type.",
376             0);
377       }
378
379       for (i = 0; i < get_method_n_params(mt); i++) {
380         ASSERT_AND_RET_DBG(
381             get_irn_mode(get_Call_param(n, i)) == get_type_mode(get_method_param_type(mt, i)),
382             "Mode of arg for Call doesn't match mode of arg type.", 0,
383             {
384               int i;
385
386               fprintf(stderr, "Assertion for Call type-check failed: %s(", get_type_name(mt));
387               for (i = 0; i < get_method_n_params(mt); ++i) {
388                 fprintf(stderr, "%s ", get_mode_name(get_type_mode(get_method_param_type(mt, i))));
389               }
390               fprintf(stderr, ") != CALL(");
391
392               for (i = 0; i < get_Call_n_params(n); ++i) {
393                 fprintf(stderr, "%s ", get_mode_name(get_irn_mode(get_Call_param(n, i))));
394               }
395               fprintf(stderr, ")\n");
396
397             }
398             );
399       }
400       break;
401
402     case iro_Add:
403       op1mode = get_irn_mode(in[1]);
404       op2mode = get_irn_mode(in[2]);
405       ASSERT_AND_RET(
406           (
407            /* common Add: BB x numP x numP --> numP */
408            (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
409            /* Pointer Add: BB x ref x int --> ref */
410            (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
411            /* Pointer Add: BB x int x ref --> ref */
412            (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
413           ),
414           "Add node", 0
415           );
416       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
417         /* BB x ref x int --> ref or BB x int x ref --> ref */
418         op_is_symmetric = 0; /* ArmRoq */
419       } else {
420         /* BB x num x num --> num or BB x ref x ref */
421         op_is_symmetric = 2;
422       }
423       break;
424
425     case iro_Sub:
426       op1mode = get_irn_mode(in[1]);
427       op2mode = get_irn_mode(in[2]);
428       ASSERT_AND_RET(
429           /* common Sub: BB x numP x numP --> numP */
430           ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
431            /* Pointer Sub: BB x ref x int --> ref */
432            (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
433            /* Pointer Sub: BB x int x ref --> ref */
434            (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
435            /* Pointer Sub: BB x ref x ref --> int */
436            (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
437           "Sub node", 0
438           );
439       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
440         op_is_symmetric = 0; /* ArmRoq */
441       } else {
442         op_is_symmetric = 2;
443       }
444       break;
445
446     case iro_Minus:
447       op1mode = get_irn_mode(in[1]);
448       ASSERT_AND_RET(
449           /* Minus: BB x float --> float */
450           op1mode == mymode && get_mode_sort(op1mode) == irms_float_number, "Minus node", 0
451           );
452       op_is_symmetric = 2;
453       break;
454
455     case iro_Mul:
456       op1mode = get_irn_mode(in[1]);
457       op2mode = get_irn_mode(in[2]);
458       ASSERT_AND_RET(
459           /* Mul: BB x int1 x int1 --> int2 */
460           ((mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode)) ||
461            (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
462           "Mul node",0
463           );
464       op_is_symmetric = 2;
465       break;
466
467     case iro_Quot:
468       op1mode = get_irn_mode(in[1]);
469       op2mode = get_irn_mode(in[2]);
470       op3mode = get_irn_mode(in[3]);
471       ASSERT_AND_RET(
472           /* Quot: BB x M x float x float --> M x X x float */
473           op1mode == mode_M && op2mode == op3mode &&
474           get_mode_sort(op2mode) == irms_float_number &&
475           mymode == mode_T,
476           "Quot node",0
477           );
478       op_is_symmetric = 2;
479       break;
480
481     case iro_DivMod:
482       op1mode = get_irn_mode(in[1]);
483       op2mode = get_irn_mode(in[2]);
484       op3mode = get_irn_mode(in[3]);
485       ASSERT_AND_RET(
486           /* DivMod: BB x M x int x int --> M x X x int x int */
487           op1mode == mode_M &&
488           mode_is_int(op2mode) &&
489           op3mode == op2mode &&
490           mymode == mode_T,
491           "DivMod node", 0
492           );
493       op_is_symmetric = 1;
494       break;
495
496     case iro_Div:
497     case iro_Mod:
498       op1mode = get_irn_mode(in[1]);
499       op2mode = get_irn_mode(in[2]);
500       op3mode = get_irn_mode(in[3]);
501       ASSERT_AND_RET(
502           /* Div or Mod: BB x M x int x int --> M x X x int */
503           op1mode == mode_M &&
504           op2mode == op3mode &&
505           mode_is_int(op2mode) &&
506           mymode == mode_T,
507           "Div or Mod node", 0
508           );
509       op_is_symmetric = 1;
510       break;
511
512     case iro_Abs:
513       op1mode = get_irn_mode(in[1]);
514       ASSERT_AND_RET(
515           /* Abs: BB x num --> num */
516           op1mode == mymode &&
517           mode_is_num (op1mode),
518           "Abs node",0
519           );
520       op_is_symmetric = 2;
521       break;
522
523     case iro_And:
524     case iro_Or:
525     case iro_Eor:
526       op1mode = get_irn_mode(in[1]);
527       op2mode = get_irn_mode(in[2]);
528       ASSERT_AND_RET(
529           /* And or Or or Eor: BB x int x int --> int */
530           mode_is_int(mymode) &&
531           op2mode == op1mode &&
532           mymode == op2mode,
533           "And, Or or Eor node", 0
534           );
535       op_is_symmetric = 2;
536       break;
537
538     case iro_Not:
539       op1mode = get_irn_mode(in[1]);
540       ASSERT_AND_RET(
541           /* Not: BB x int --> int */
542           mode_is_int(mymode) &&
543           mymode == op1mode,
544           "Not node", 0
545           );
546       op_is_symmetric = 2;
547       break;
548
549
550     case iro_Cmp:
551       op1mode = get_irn_mode(in[1]);
552       op2mode = get_irn_mode(in[2]);
553       ASSERT_AND_RET(
554           /* Cmp: BB x datab x datab --> b16 */
555           mode_is_data (op1mode) &&
556           op2mode == op1mode &&
557           mymode == mode_T,
558           "Cmp node", 0
559           );
560       break;
561
562     case iro_Shl:
563     case iro_Shr:
564     case iro_Shrs:
565       op1mode = get_irn_mode(in[1]);
566       op2mode = get_irn_mode(in[2]);
567       assert(
568           /* Shl, Shr or Shrs: BB x int x int_u --> int */
569           mode_is_int(op1mode) &&
570           mode_is_int(op2mode) &&
571           !mode_is_signed(op2mode) &&
572           mymode == op1mode &&
573           "Shl, Shr, Shr or Rot node"
574           );
575       break;
576
577     case iro_Rot:
578       op1mode = get_irn_mode(in[1]);
579       op2mode = get_irn_mode(in[2]);
580       ASSERT_AND_RET(
581           /* Rot: BB x int x int --> int */
582           mode_is_int(op1mode) &&
583           mode_is_int(op2mode) &&
584           mymode == op1mode,
585           "Rot node",0
586           );
587       break;
588
589     case iro_Conv:
590       op1mode = get_irn_mode(in[1]);
591       ASSERT_AND_RET(
592           /* Conv: BB x datab1 --> datab2 */
593           mode_is_datab(op1mode) && mode_is_data(mymode),
594           "Conv node", 0
595           );
596       break;
597
598     case iro_Phi:
599       /* Phi: BB x dataM^n --> dataM */
600       /* for some reason "<=" aborts. int there a problem with get_store? */
601       for (i=1; i < get_irn_arity(n); i++) {
602         if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
603           ASSERT_AND_RET( get_irn_mode(in[i]) == mymode, "Phi node", 0);
604       };
605       ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
606       break;
607
608     case iro_Load:
609       op1mode = get_irn_mode(in[1]);
610       op2mode = get_irn_mode(in[2]);
611       ASSERT_AND_RET(
612           /* Load: BB x M x ref --> M x X x data */
613           op1mode == mode_M && mode_is_reference(op2mode),
614           "Load node", 0
615           );
616       ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
617       break;
618
619     case iro_Store:
620       op1mode = get_irn_mode(in[1]);
621       op2mode = get_irn_mode(in[2]);
622       op3mode = get_irn_mode(in[3]);
623       ASSERT_AND_RET(
624           /* Load: BB x M x ref data --> M x X */
625           op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
626           "Store node", 0
627           );
628       ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
629       break;
630
631     case iro_Alloc:
632       op1mode = get_irn_mode(in[1]);
633       op2mode = get_irn_mode(in[2]);
634       ASSERT_AND_RET(
635           /* Alloc: BB x M x int_u --> M x X x ref */
636           op1mode == mode_M &&
637           mode_is_int(op2mode) &&
638           !mode_is_signed(op2mode) &&
639           mymode == mode_T,
640           "Alloc node", 0
641           );
642       break;
643
644     case iro_Free:
645       op1mode = get_irn_mode(in[1]);
646       op2mode = get_irn_mode(in[2]);
647       ASSERT_AND_RET(
648           /* Free: BB x M x ref --> M */
649           op1mode == mode_M && mode_is_reference(op2mode) &&
650           mymode == mode_M,
651           "Free node",0
652           );
653       break;
654
655     case iro_Sync:
656       /* Sync: BB x M^n --> M */
657       for (i=1; i < get_irn_arity(n); i++) {
658         ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
659       };
660       ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
661       break;
662
663     case iro_Proj:
664       return vrfy_Proj_proj(n, irg);
665       break;
666
667     default:
668       break;
669   }
670
671   /* All went ok */
672   return 1;
673 }
674
675 int irn_vrfy(ir_node *n)
676 {
677   return irn_vrfy_irg(n, current_ir_graph);
678 }
679
680 /*******************************************************************/
681 /* Verify the whole graph.                                         */
682 /*******************************************************************/
683
684 static void vrfy_wrap(ir_node *node, void *env)
685 {
686   int *res = env;
687
688   *res = irn_vrfy(node);
689 }
690
691 int irg_vrfy(ir_graph *irg)
692 {
693   int res = 1;
694   ir_graph *rem;
695
696   rem = current_ir_graph;
697   current_ir_graph = irg;
698
699   assert(get_irg_pinned(irg) == pinned);
700
701   irg_walk(irg->end, vrfy_wrap, NULL, &res);
702
703   current_ir_graph = rem;
704
705   return res;
706 }