Advertisement
Ladies_Man

opt1 tree-ssa-dec.c print_nodes

Apr 22nd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.92 KB | None | 0 0
  1. //=====================================
  2. //=========PRINT-NODE-FUCNTION=========
  3. //=====================================
  4.  
  5.  
  6.  
  7. static void
  8. print_nodes()
  9. {
  10.     printf("===PRINTING NODES===\n");
  11.     basic_block bb;
  12.    
  13.     FILE* dump_file = fopen("optlab1.txt", "w");
  14.  
  15.     FOR_EACH_BB_FN (bb, cfun)
  16.     {
  17.         gimple_stmt_iterator gsi;
  18.         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
  19.         {
  20.         gimple stmt = gsi_stmt (gsi);
  21.  
  22.         switch (gimple_code (stmt)) {
  23.         case GIMPLE_ASSIGN:
  24.                 fprintf (dump_file, "\n======ASSIGN======\n");
  25.                 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
  26.                 break;
  27.         case GIMPLE_CALL:
  28.                 fprintf (dump_file, "\n=======CALL=======\n");
  29.                 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
  30.                 break;
  31.         case GIMPLE_COND:
  32.                 fprintf (dump_file, "\n=======COND=======\n");
  33.                 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
  34.                 break;
  35.         case GIMPLE_RETURN:
  36.                 fprintf (dump_file, "\n======RETURN======\n");
  37.                 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
  38.                 break;
  39.        
  40.         default:
  41.                 break;
  42.         }
  43.  
  44.         if (gimple_has_mem_ops(stmt)) {
  45.             fprintf (dump_file, "statement has memory operands\n");
  46.             fprintf(dump_file, "statement's number of operands: %d\n", gimple_num_ops(stmt));
  47.         }
  48.         if (gimple_has_volatile_ops(stmt)) {
  49.                 fprintf (dump_file, "statement has volatile operands\n");
  50.         }
  51.  
  52.         if (0 != gimple_num_ops(stmt)) {
  53.             int k;
  54.             for (k = 0; k < gimple_num_ops(stmt); k++) {
  55.                
  56.                 fprintf(dump_file, "operand %d:", k);
  57.                 tree tmp_tree = gimple_op(stmt, k);
  58.                 print_generic_stmt(dump_file, tmp_tree, TDF_SLIM);
  59.             }
  60.         }
  61.            
  62.         }
  63.     }
  64.     fclose(dump_file);
  65. }
  66. #include <stdio.h>
  67. #include <time.h>
  68. #include <stdlib.h>
  69.  
  70. int func(int x) {
  71.     return x * 1337;
  72. }
  73.  
  74. int func2(int a, int b) {
  75.     int d = a + b;
  76.     return d;
  77. }
  78.  
  79. int main (void)
  80. {
  81.     srand(time(NULL));
  82.     int cond = (rand() % 5) -2;
  83.  
  84.     int b, c, a;
  85.     a = 322;
  86.     c = 1337;
  87.  
  88.     if (cond > 0) {
  89.         a += func2(a, b);
  90.     } else {
  91.         a -= func2(a, b);
  92.     }
  93.  
  94.     printf("Hello, World!\n");
  95.     printf("c=%d, a=%d\n", c, a);
  96.     return 0;
  97. }
  98.  
  99.  
  100. =======CALL=======
  101. _4 = time (0B);
  102. statement has memory operands
  103. statement's number of operands: 4
  104. operand 0:_4
  105. operand 1:time;
  106. operand 2:
  107. operand 3:0B
  108.  
  109. ======ASSIGN======
  110. _5 = (unsigned int) _4;
  111. statement has memory operands
  112. statement's number of operands: 2
  113. operand 0:_5
  114. operand 1:_4
  115.  
  116. =======CALL=======
  117. srand (_5);
  118. statement has memory operands
  119. statement's number of operands: 4
  120. operand 0:
  121. operand 1:srand;
  122. operand 2:
  123. operand 3:_5
  124.  
  125. =======CALL=======
  126. _8 = rand ();
  127. statement has memory operands
  128. statement's number of operands: 3
  129. operand 0:_8
  130. operand 1:rand;
  131. operand 2:
  132.  
  133. ======ASSIGN======
  134. _9 = _8 % 5;
  135. statement has memory operands
  136. statement's number of operands: 3
  137. operand 0:_9
  138. operand 1:_8
  139. operand 2:5
  140.  
  141. =======COND=======
  142. if (_9 > 2)
  143. operand 0:_9
  144. operand 1:2
  145. operand 2:
  146. operand 3:
  147.  
  148. ======ASSIGN======
  149. a_11 = b_10(D) + 644;
  150. statement has memory operands
  151. statement's number of operands: 3
  152. operand 0:a_11
  153. operand 1:b_10(D)
  154. operand 2:644
  155.  
  156. ======ASSIGN======
  157. a_12 = -b_10(D);
  158. statement has memory operands
  159. statement's number of operands: 2
  160. operand 0:a_12
  161. operand 1:b_10(D)
  162.  
  163. =======CALL=======
  164. __builtin_puts (&"Hello, World!"[0]);
  165. statement has memory operands
  166. statement's number of operands: 4
  167. operand 0:
  168. operand 1:__builtin_puts;
  169. operand 2:
  170. operand 3:&"Hello, World!"[0];
  171.  
  172. =======CALL=======
  173. printf ("c=%d, a=%d\n", 1337, a_1);
  174. statement has memory operands
  175. statement's number of operands: 6
  176. operand 0:
  177. operand 1:printf;
  178. operand 2:
  179. operand 3:"c=%d, a=%d\n";
  180. operand 4:1337
  181. operand 5:a_1
  182.  
  183. ======RETURN======
  184. return 0;
  185. statement has memory operands
  186. statement's number of operands: 1
  187. operand 0:0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement