PIPS
instruction.c File Reference

Methods dealing with instructions. More...

#include <stdlib.h>
#include <stdio.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "ri.h"
#include "ri-util.h"
+ Include dependency graph for instruction.c:

Go to the source code of this file.

Functions

instruction make_call_instruction (entity e, list l)
 Build an instruction that call a function entity with an argument list. More...
 
instruction MakeNullaryCallInst (entity f)
 Creates a call instruction to a function with no argument. More...
 
instruction MakeUnaryCallInst (entity f, expression e)
 Creates a call instruction to a function with one argument. More...
 
instruction make_continue_instruction ()
 Creates a CONTINUE instruction, that is the FORTRAN nop, the ";" in C or the "pass" in Python for example. More...
 
instruction make_assign_instruction (expression l, expression r)
 
instruction make_instruction_block (list statements)
 Build an instruction block from a list of statements. More...
 
bool native_call_p (call c, string op_name)
 Test if a call is a native instruction of the language. More...
 
bool native_instruction_p (instruction i, string op_name)
 Test if an instruction is a native instruction of the language. More...
 
bool instruction_assign_p (instruction i)
 Test if an instruction is an assignment. More...
 
bool instruction_continue_p (instruction i)
 Test if an instruction is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python... More...
 
bool return_instruction_p (instruction i)
 Test if an instruction is a C or Fortran "return". More...
 
bool fortran_return_instruction_p (instruction i)
 
bool C_return_instruction_p (instruction i)
 
bool exit_instruction_p (instruction i)
 
bool abort_instruction_p (instruction i)
 
bool instruction_stop_p (instruction i)
 Test if an instruction is a Fortran STOP. More...
 
bool instruction_format_p (instruction i)
 Test if an instruction is a Fortran FORMAT. More...
 
bool assignment_block_p (instruction i)
 Checks if an instruction block is a list of assignments, possibly followed by a continue. More...
 
void flatten_block_if_necessary (instruction i)
 Flatten an instruction block if necessary. More...
 
string instruction_identification (instruction i)
 Return a constant string representing symbolically the instruction type. More...
 
string safe_instruction_identification (instruction i)
 

Detailed Description

Methods dealing with instructions.

Definition in file instruction.c.

Function Documentation

◆ flatten_block_if_necessary()

void flatten_block_if_necessary ( instruction  i)

Flatten an instruction block if necessary.

Detects sequences of sequences and reorder as one sequence.

Some memory leaks. Should not be used. Use the functions from control instead.

This function cannot be used for C code as local declarations are discarded without warnings.

Definition at line 259 of file instruction.c.

260 {
261  if (instruction_block_p(i))
262  {
263  list ls = NIL;
266  if (instruction_block_p(ib))
267  ls = gen_nconc(ls, instruction_block(ib));
268  else
269  ls = gen_nconc(ls, CONS(STATEMENT, s, NIL));
270  }
272  instruction_block(i) = ls;
273  }
274 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define instruction_block_p(i)
#define instruction_block(i)
#define statement_instruction(x)
Definition: ri.h:2458
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, FOREACH, gen_free_list(), gen_nconc(), instruction_block, instruction_block_p, NIL, STATEMENT, and statement_instruction.

+ Here is the call graph for this function:

◆ instruction_identification()

string instruction_identification ( instruction  i)

Return a constant string representing symbolically the instruction type.

Does not work for undefined instructions: core dump.

Returns
a constant string such as "WHILE LOOP" for a "while()" or "do while()" loop and so on.

Definition at line 284 of file instruction.c.

285 {
286  string instrstring = NULL;
287 
288  switch (instruction_tag(i))
289  {
290  case is_instruction_loop:
291  instrstring="DO LOOP";
292  break;
294  instrstring="WHILE LOOP";
295  break;
296  case is_instruction_test:
297  instrstring="TEST";
298  break;
299  case is_instruction_goto:
300  instrstring="GOTO";
301  break;
302  case is_instruction_call:
303  {if (instruction_continue_p(i))
304  instrstring="CONTINUE";
305  else if (return_instruction_p(i))
306  instrstring="RETURN";
307  else if (instruction_stop_p(i))
308  instrstring="STOP";
309  else if (instruction_format_p(i))
310  instrstring="FORMAT";
311  else if (instruction_assign_p(i))
312  instrstring="ASSIGN";
313  else {
314  instrstring="CALL";
315  }
316  break;
317  }
319  instrstring="BLOCK";
320  break;
322  instrstring="UNSTRUCTURED";
323  break;
325  instrstring="FOR LOOP";
326  break;
328  instrstring="EXPRESSION";
329  break;
330  default: pips_internal_error("ill. instruction tag %d",
331  instruction_tag(i));
332  }
333 
334  return instrstring;
335 }
bool instruction_assign_p(instruction i)
Test if an instruction is an assignment.
Definition: instruction.c:164
bool instruction_stop_p(instruction i)
Test if an instruction is a Fortran STOP.
Definition: instruction.c:214
bool instruction_format_p(instruction i)
Test if an instruction is a Fortran FORMAT.
Definition: instruction.c:222
bool instruction_continue_p(instruction i)
Test if an instruction is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: instruction.c:173
bool return_instruction_p(instruction i)
Test if an instruction is a C or Fortran "return".
Definition: instruction.c:185
#define pips_internal_error
Definition: misc-local.h:149
#define is_instruction_block
soft block->sequence transition
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_expression
Definition: ri.h:1478
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511

References instruction_assign_p(), instruction_continue_p(), instruction_format_p(), instruction_stop_p(), instruction_tag, is_instruction_block, is_instruction_call, is_instruction_expression, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, pips_internal_error, and return_instruction_p().

Referenced by external_statement_identification(), LinkInstToCurrentBlock(), MakeNewLabelledStatement(), MakeStatement(), safe_instruction_identification(), statement_identification(), and statement_to_postcondition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_instruction_identification()

string safe_instruction_identification ( instruction  i)

Definition at line 337 of file instruction.c.

338 {
339  string instrstring = string_undefined;
341  instrstring = "UNDEFINED INSTRUCTION";
342  else
343  instrstring = instruction_identification(i);
344  return instrstring;
345 }
string instruction_identification(instruction i)
Return a constant string representing symbolically the instruction type.
Definition: instruction.c:284
#define string_undefined
Definition: newgen_types.h:40
#define instruction_undefined_p(x)
Definition: ri.h:1455

References instruction_identification(), instruction_undefined_p, and string_undefined.

+ Here is the call graph for this function: