PIPS
statement.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "properties.h"
#include "ri-util.h"
+ Include dependency graph for statement.c:

Go to the source code of this file.

Data Structures

struct  add_statement_declarations_t
 
struct  entities_t
 
struct  fswl
 structure used by find_statements_with_label_walker More...
 
struct  fswp
 used to pass parameters to find_statements_with_comment_walker More...
 
struct  sb
 
struct  replace_statement_context
 

Macros

#define ERROR_PREFIX   "!ERROR: "
 as name indicate, a comment is added. More...
 
#define BUFSIZE   1024
 
#define PIPS_DECLARATION_COMMENT   "PIPS generated variable\n"
 
#define MAX_COMMENTERS   8
 

Typedefs

typedef string(* generated_variable_commenter) (entity)
 commenters are function used to add comments to pips-created variables they are handled as a limited size stack all commenters are supposed to return allocated data More...
 

Functions

static bool cannot_be_empty (bool *statement_is_empty)
 
static bool call_filter (call c, bool *statement_is_empty)
 
bool empty_code_p (statement s)
 statement.c More...
 
bool empty_code_list_p (list l)
 
bool empty_comments_p (const char *s)
 
bool comments_equal_p (string c1, string c2)
 
bool statement_with_empty_comment_p (statement s)
 Return true if the statement has an empty statement: More...
 
bool assignment_statement_p (statement s)
 Test if a statement is an assignment. More...
 
bool assignment_block_or_statement_p (statement s)
 
bool return_statement_p (statement s)
 Test if a statement is a C or Fortran "return". More...
 
bool exit_statement_p (statement s)
 
bool abort_statement_p (statement s)
 
bool fortran_return_statement_p (statement s)
 Test if a statement is a Fortran "return". More...
 
bool C_return_statement_p (statement s)
 Test if a statement is a C "return". More...
 
bool continue_statement_p (statement s)
 Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python... More...
 
bool forloop_statement_p (statement s)
 
bool declaration_statement_p (statement s)
 Had to be optimized according to Beatrice Creusillet. More...
 
bool continue_statements_p (list sl)
 Check that all statements contained in statement list sl are a continue statements. More...
 
bool stop_statement_p (statement s)
 Test if a statement is a Fortran STOP. More...
 
bool format_statement_p (statement s)
 Test if a statement is a Fortran FORMAT. More...
 
bool write_statement_p (statement s)
 
bool statement_less_p (statement st1, statement st2)
 
bool statement_possible_less_p (statement st1, statement st2)
 
bool statement_sequence_p (statement s)
 Statement classes induced from instruction type. More...
 
bool statement_test_p (statement s)
 
bool statement_loop_p (statement s)
 
bool statement_whileloop_p (statement s)
 
bool statement_goto_p (statement s)
 
bool statement_call_p (statement s)
 
bool statement_unstructured_p (statement s)
 
bool statement_forloop_p (statement s)
 
bool statement_multitest_p (statement s)
 
bool statement_expression_p (statement s)
 
bool empty_statement_p (statement st)
 Test if a statement is empty. More...
 
bool unlabelled_statement_p (statement st)
 
bool nop_statement_p (statement s)
 
bool empty_statement_or_labelless_continue_p (statement st)
 Return true if the statement is an empty instruction block without label or a continue without label or a recursive combination of above. More...
 
bool empty_statement_or_continue_p (statement st)
 Return true if the statement is an empty instruction block or a continue or a recursive combination of above. More...
 
bool empty_statement_or_continue_without_comment_p (statement st)
 Return true if the statement is an empty instruction block or a continue without comments or without LABEL or without declarations or a recursive combination of above. More...
 
bool check_io_statement_p (statement s)
 
string comments_dup (string comment)
 functions to generate statements More...
 
string decls_text_dup (string dt)
 Duplicate statement decls_text. More...
 
statement make_assign_statement (expression l, expression r)
 
statement instruction_to_statement (instruction instr)
 Build a statement from a give instruction. More...
 
statement make_block_statement (list body)
 Make a block statement from a list of statement. More...
 
statement make_empty_block_statement ()
 Build an empty statement (block/sequence) More...
 
statement make_empty_statement_with_declarations_and_comments (list d, string dt, string c)
 Build an empty statement with declaration list, declaration text and comment. More...
 
void move_statement_attributes (statement from, statement to)
 Move all the attributes from one statement to another one. More...
 
void copy_statement_attributes (statement from, statement to)
 Copy all the attributes from one statement to another one. More...
 
statement make_statement_from_statement_list_or_empty_block (list l)
 Build a statement sequence from a statement list. More...
 
statement make_statement_from_statement_list (list l)
 Build a statement sequence from a statement list. More...
 
statement make_statement_from_statement_varargs_list (statement s,...)
 Build a statement sequence from a statement NULL-terminated varargs list. More...
 
statement make_block_with_stmt_if_not_already (statement stmt)
 Build a statement block from a statement if not already a statement block. More...
 
statement make_return_statement (entity module)
 
instruction make_simple_Fortran_io_instruction (bool is_read_p, expression f, list io_list)
 Derived from the Fortran parser code. More...
 
statement make_print_statement (string message)
 Make a Fortran print statement. More...
 
statement make_C_print_statement (string message)
 
statement make_any_print_statement (string message)
 Generate a print of a constant character string on stderr for C or on stdout for Fortran. More...
 
statement make_stop_statement (string message)
 This function returns a Fortran stop statement with an error message. More...
 
statement make_exit_statement (int n, string errmess)
 This function returns a statement ending with a C exit statement. More...
 
statement make_continue_statement (entity l)
 
statement make_plain_continue_statement ()
 Make a simple continue statement to be used as a NOP or ";" in C. More...
 
statement make_declarations_statement (list idl, int sn, string cs)
 Make a declaration(s) statement. More...
 
statement make_declaration_statement (entity v, int sn, string cs)
 Make one declaration statement. More...
 
bool declaration_statements_p (list sl)
 Check that all statements contained in statement list sl are declaration statements. More...
 
statement add_initialization_information_to_declaration_statement (statement s, list iel)
 The initialization expression list is integrated into the internal representation as an argument list. More...
 
list declaration_statement_to_initializations (statement s)
 
statement make_whileloop_statement (expression condition, statement body, int line_number, bool before)
 Build a while loop statement. More...
 
statement make_loop_statement (entity i, expression low, expression up, expression inc, statement b)
 Build a loop statement. More...
 
statement make_forloop_statement (expression init, expression cond, expression inc, statement body)
 
statement make_test_statement (expression cond, statement truebody, statement falsebody)
 
statement make_call_statement (string function_name, list args, entity l, string c)
 This function is limited to intrinsics calls... More...
 
statement make_expression_statement (expression e)
 Build a statement from a given expression. More...
 
sequence statement_sequence (statement s)
 Get the sequence of a statement sequence. More...
 
list statement_block (statement s)
 Get the list of block statements of a statement sequence. More...
 
test statement_test (statement s)
 Get the test of a statement. More...
 
statement effective_test_true (test t)
 returns the effective true branch of a test by skipping a possible sequence of one element. More...
 
loop statement_loop (statement s)
 Get the loop of a statement. More...
 
whileloop statement_whileloop (statement s)
 Get the whileloop of a statement. More...
 
statement statement_goto (statement s)
 Get the goto of a statement. More...
 
call statement_call (statement s)
 Get the call of a statement. More...
 
unstructured statement_unstructured (statement s)
 Get the unstructured of a statement. More...
 
forloop statement_forloop (statement s)
 Get the forloop of a statement. More...
 
multitest statement_multitest (statement s)
 Get the multitest of a statement. More...
 
expression statement_expression (statement s)
 Get the expression of a statement. More...
 
static void update_number_to_statement (statement s)
 
statement apply_number_to_statement (hash_table nts, _int n)
 
hash_table build_number_to_statement (hash_table nts, statement s)
 
hash_table allocate_number_to_statement ()
 
statement clear_labels (statement s)
 Get rid of all labels in controlized code before duplication. More...
 
void clear_label (statement s)
 
statement st_make_nice_test (expression condition, list ltrue, list lfalse)
 
statement makeloopbody (loop l, statement s_old, bool inner_p)
 statement makeloopbody(l, s_old) make a statement for a loop body, using the fields of a previously existing statement More...
 
string external_statement_identification (statement s)
 Does work neither with undefined statements nor with defined statements with undefined instructions. More...
 
string statement_identification (statement s)
 Like external_statement_identification(), but with internal information, the hexadecimal address of the statement. More...
 
string safe_statement_identification (statement s)
 
static bool gather_all_comments_of_a_statement_filter (statement s, string *all_comments)
 
string gather_all_comments_of_a_statement (statement s)
 Gather all the comments recursively found in the given statement and return them in a strduped string (NULL if no comment found). More...
 
char ** find_first_statement_comment (statement s)
 Find the first non-empty comment of a statement, if any returns a pointer to the comment if found, pointer to a "string_undefined" otherwise. More...
 
static char ** find_first_comment (statement s)
 Find the first comment of a statement, if any. More...
 
bool try_to_put_a_comment_on_a_statement (statement s, string the_comments)
 Put a comment on a statement in a safe way. More...
 
void put_a_comment_on_a_statement (statement s, string the_comments)
 Similar to try_to_put_a_comment_on_a_statement() but insert a CONTINUE to put the comment on it if there is only empty sequence(s) More...
 
void append_comments_to_statement (statement s, string the_comments)
 Append a comment string (if non empty) to the comments of a statement, if the c. More...
 
void insert_comments_to_statement (statement s, const char *the_comments)
 Insert a comment string (if non empty) at the beginning of the comments of a statement. More...
 
void add_one_line_of_comment (statement s, string format,...)
 
statement add_comment_and_line_number (statement s, string sc, int sn)
 Since block cannot carry comments nor line numbers, they must be moved to an internal continue statement. More...
 
void fix_sequence_statement_attributes (statement s)
 Since blocks are not represented in Fortran, they cannot carry a label. More...
 
void fix_statement_attributes_if_sequence (statement s)
 Apply fix_sequence_statement_attributes() on the statement only if it really a sequence. More...
 
entity statement_to_label (statement s)
 See if statement s is labelled and can be reached by a GO TO. More...
 
statement add_label_to_statement (entity label, statement s, statement *labeled_statement)
 Add a label to a statement. More...
 
bool statement_does_return (statement s)
 Returns false is no syntactic control path exits s (i.e. More...
 
bool unstructured_does_return (unstructured u)
 
void gather_and_remove_all_format_statements_rewrite (statement s, list *all_formats)
 
list gather_and_remove_all_format_statements (statement s)
 Used to keep aside the FORMAT before many code transformation that could remove them either. More...
 
void put_formats_at_module_beginning (statement s)
 Transfer all the FORMATs at the very beginning of a module: More...
 
void put_formats_at_module_end (statement s)
 Transfer all the FORMATs at the very end of a module: More...
 
bool figure_out_if_it_is_a_format (instruction i, bool *format_inside_statement_has_been_found)
 
bool format_inside_statement_p (statement s)
 
int statement_to_comment_length (statement stmt)
 Number of comment line directly attached to a statement. More...
 
static bool down_counter (statement s)
 
static void up_counter (statement s)
 
persistant_statement_to_int statement_to_line_number (statement s)
 
static void generic_insert_statement (statement s, statement s1, bool before)
 insert statement s1 before or after statement s More...
 
void insert_statement (statement s, statement s1, bool before)
 This is the normal entry point. More...
 
void insert_statement_no_matter_what (statement s, statement s1, bool before)
 Break the IR consistency or, at the very least, do not insert new declarations at the usual place, i.e. More...
 
void append_statement_to_block_statement (statement b, statement s)
 
static string default_generated_variable_commenter (__attribute__((unused)) entity e)
 
void push_generated_variable_commenter (string(*commenter)(entity))
 
void pop_generated_variable_commenter ()
 
string generated_variable_comment (entity e)
 
static bool add_declaration_to_declaration_statement_p (statement s, string c, entity nv)
 Check if declaration of variable nv can be added to the declaration list of statement s. More...
 
static statement generic_add_declaration_statement (statement s, entity e, bool before_p)
 Add a new declaration statement. More...
 
statement add_declaration_statement (statement s, entity e)
 
statement add_declaration_statement_at_beginning (statement s, entity e)
 
statement add_declaration_statement_here (statement block_statement, statement s, entity e, bool before_p)
 Add a new declaration statement (inspired by generic_add_declaration_statement) More...
 
void fix_block_statement_declarations (statement s)
 s is assumed to be a block statement and its declarations field is assumed to be correct, but not necessarily the declaration statements within the block s. More...
 
statement remove_declaration_statement (statement s, entity e)
 Declarations are not only lists of entities, but also statement to carry the line number, comments,... More...
 
statement update_statement_instruction (statement s, instruction i)
 Replace the instruction in statement s by instruction i. More...
 
void statement_replace_with_statement_list (statement as, statement rs, list sl)
 Assume that statement rs appears in statement as and replaced it by a statement list. More...
 
static bool find_implicit_goto (statement s, list *tl)
 
list statement_to_implicit_target_labels (statement s)
 Look for labels appearing in END= or ERR= IO clauses and allocate a label list. More...
 
static bool collect_labels (statement s, list *pll)
 
list statement_to_labels (statement s)
 Look for non-empty labels appearing directly or indirectly and allocate a label list. More...
 
static bool undefined_statement_found_p (statement s, bool *p_undefined_p)
 
bool all_statements_defined_p (statement s)
 
static bool add_statement_declarations (statement s, add_statement_declarations_t *ctxt)
 Add the declarations of a statement to a list if not already here. More...
 
list statement_to_declarations (void *s)
 Get a list of all variables declared recursively within a statement. More...
 
list statements_to_declarations (list sl)
 Returns the declarations contained in a list of statement. More...
 
list instruction_to_declarations (instruction i)
 Get a list of all variables declared recursively within an instruction. More...
 
static list internal_statement_to_direct_declarations (statement st)
 No recursive descent. More...
 
static list unstructured_to_direct_declarations (unstructured u)
 
list statements_to_direct_declarations (list sl)
 Returns the declarations contained directly in the declaration statements of a list of statements. More...
 
list statement_to_direct_declarations (statement s)
 Returns the declarations contained directly in a statement s. More...
 
static bool add_stat_referenced_entities (reference r, entities_t *vars)
 
static bool add_loop_index_entity (loop l, entities_t *vars)
 
static bool add_ref_entities_in_init (statement s, entities_t *vars)
 
list statement_to_referenced_entities (statement s)
 Get a list of all variables referenced recursively within a statement: More...
 
static bool add_stat_called_user_entities (call c, entities_t *funcs)
 
static bool add_stat_called_in_inits (statement s, entities_t *funcs)
 
list statement_to_called_user_entities (statement s)
 Get a list of all user function called recursively within a statement: More...
 
static bool first_reference_to_v_p (reference r)
 
static bool declarations_first_reference_to_v_p (statement st)
 
reference find_reference_to_variable (statement s, entity v)
 
static bool count_static_references_to_v_p (reference r)
 Count static references. More...
 
int count_static_references_to_variable (statement s, entity v)
 
static bool count_references_to_v_p (reference r)
 
static bool declarations_count_references_to_v_p (statement st)
 
static bool count_element_references_to_v_p (reference r)
 This function checks reference to proper elements, not slices. More...
 
static bool declarations_count_element_references_to_v_p (statement st)
 
static bool count_loop_in (loop __attribute__((unused)) l)
 
static void count_loop_out (loop __attribute__((unused)) l)
 
int count_references_to_variable (statement s, entity v)
 
int count_references_to_variable_element (statement s, entity v)
 
static bool statement_in_statement_walker (statement st, struct sb *sb)
 
bool statement_in_statement_p (statement s, statement st)
 
bool statement_in_statements_p (statement s, list l)
 
static bool replace_statement_walker (statement s, struct replace_statement_context *ctx)
 
bool statement_replace_in_root_statement (statement old_stat, statement new_stat, statement root_stat)
 replace old_stat by new_stat in root_stat this pass does not free old_stat similar to replace_in_sequence_statement_with() in phrase/phrase_tools.c but without the constraint that old_stat is in a sequence More...
 
void statement_remove_extensions (statement s)
 That's all folks. More...
 
void statement_remove_useless_label (statement s, bool *changed)
 remove the label of a statement if the statement is not unstructured. More...
 
bool belong_to_statement (statement stmt, statement s, bool found_p)
 return true if s is enclosed in stmt NL: What is the difference with statement_in_statement_p? More...
 
entity find_final_statement_label (statement s)
 Find the label associated with the last statement executed within s. More...
 
string comment_sentinel (tag t)
 Start a single line comment. More...
 
statement finders

find statements with particular constraints

static bool find_statements_with_label_walker (statement s, struct fswl *p)
 helper to find statement with a particular label as label should be unique, the function stops once a statement is found More...
 
statement find_statement_from_label (statement s, entity label)
 find a statement in s with entity label More...
 
statement find_statement_from_label_name (statement s, const char *module_name, const char *label_name)
 
bool statement_with_pragma_p (statement s)
 Test if a statement has some pragma. More...
 
list statement_pragmas (statement s)
 get the list of pragma of a statement s More...
 
extension get_extension_from_statement_with_pragma (statement s, const char *seed)
 Get the extension of a statement with pragma beginning with a prefix. More...
 
static bool find_statements_with_pragma_walker (statement s, struct fswp *p)
 
list find_statements_with_pragma (statement s, const char *begin)
 Get a list of statements with pragma begining with a prefix. More...
 
static bool look_for_user_call (call c, bool *user_call_p)
 
bool statement_contains_user_call_p (statement s)
 
static bool look_for_control_effects (call c, bool *control_effect_p)
 
bool statement_may_have_control_effects_p (statement s)
 
static bool look_for_exiting_intrinsic_calls (call c, bool *control_effect_p)
 
bool statement_may_contain_exiting_intrinsic_call_p (statement s)
 
statement normalize_statement (statement s)
 Make (a bit more) sure that s is gen_defined_p in spite of poor decision for empty fields and that strdup can be used on the string fields. More...
 

Variables

static hash_table number_to_statement = hash_table_undefined
 Mapping from statement number to statement. More...
 
static set duplicate_numbers = set_undefined
 To keep track of duplicate numbers. More...
 
static int current_line = -1
 Poor attempt at associating physical line numbers to statement. More...
 
static persistant_statement_to_int stmt_to_line = persistant_statement_to_int_undefined
 
static generated_variable_commenter generated_variable_commenters [MAX_COMMENTERS]
 
static size_t nb_commenters =1
 
static reference first_reference_to_v = reference_undefined
 Return first reference found. More...
 
static entity variable_searched = entity_undefined
 
static int reference_count = -1
 
static int loop_depth
 Estimate count of dynamic references. More...
 

get_statement_depth and its auxilary functions

static bool is_substatement = false
 
bool statement_substatement_walker (statement some, statement s)
 
bool statement_substatement_p (statement s, statement root)
 search a statement inside a statement More...
 
int get_statement_depth (statement s, statement root)
 computes the block-depth of a statement NOT INTENDED to generate entity name declared at particular block level : The block scope depends on the number of different blocks at the same depth ! More...