PIPS
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "text.h"
#include "text-util.h"
#include "ri.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "misc.h"
#include "properties.h"
Go to the source code of this file.
Functions | |
static void | decorate_trail (entity module, list trail, hash_table labels) |
static text | text_trail (entity module, int margin, list trail, hash_table labels, list *ppdl) |
static bool | control_in_trail_p (list l, control c) |
OK, a hash table could be used, as Pierre used too... More... | |
static bool | appears_first_in_trail (list trail, control c1, control c2) |
returns true if c1 is encountered before c2 in trail, or if c1 == c2 is encountered in trail, false is c2 is encountered first and c2 != c1, core dumps otherwise, if neither c1 nor c2 is in trail More... | |
static void | set_control_to_label (entity m, control c, hash_table h) |
set_control_to_label allocates label for the control node c in the module m. More... | |
static string | control_to_label_name (control c, hash_table h) |
text | text_unstructured (entity module, const char *label, int margin, unstructured u, int num, list *ppdl) |
unstructured.c More... | |
static list | build_trail (list l, control c) |
Any heuristics can be used to build the trail, depth or width first, true or false branch first, lower statement numbering first or not, sorted by statement numbering (but some statements have no number...). More... | |
list | unstructured_to_trail (unstructured u) |
void | dump_trail (list trail) |
void | dump_control_to_label_name (hash_table h) |
returns true if c1 is encountered before c2 in trail, or if c1 == c2 is encountered in trail, false is c2 is encountered first and c2 != c1, core dumps otherwise, if neither c1 nor c2 is in trail
Definition at line 408 of file unstructured.c.
References CAR, CONTROL, control_undefined, MAPL, and pips_assert.
Referenced by decorate_trail(), and text_trail().
Any heuristics can be used to build the trail, depth or width first, true or false branch first, lower statement numbering first or not, sorted by statement numbering (but some statements have no number...).
No simple heuristics seems to be bullet proof.
The exit node must be last in the trace, or an extra node has to be added to reach the continuation of the unstructured (see text_trail()).
For CONS convenience, the list is built in reverse order (and reversed by the caller).
Do not add this artificial node to the trail, follow the left successors only
Add c to the trail if not already in
Follow the false branch in depth first, assuming that IF GOTO's mainly handle exceptions
Definition at line 167 of file unstructured.c.
References CAR, CDR, check_io_statement_p(), CONS, CONTROL, control_in_trail_p(), control_statement, control_successors, control_undefined, debug(), gen_length(), get_bool_property(), ifdebug, instruction_test_p, MAPL, pips_assert, pips_internal_error, statement_identification(), and statement_instruction.
Referenced by unstructured_to_trail().
OK, a hash table could be used, as Pierre used too...
but the order is lost. You need both ordered and direct accesses. Easy to add later if too slow.
Definition at line 283 of file unstructured.c.
References gen_chunk_undefined, and gen_find_eq().
Referenced by build_trail(), decorate_trail(), and unstructured_to_trail().
|
static |
Definition at line 480 of file unstructured.c.
References control_statement, debug(), hash_get(), HASH_UNDEFINED_VALUE, LABEL_PREFIX, local_name(), statement_identification(), strdup(), and string_undefined.
Referenced by text_trail().
|
static |
No need for a label, it must be the exit node... Should be asserted The exit node may have two successors
The real successor is the false successor of the IO check
The real successor is the false successor of the IO check
If the statement "really" has a continuation (e.g. not a STOP or a RETURN)
if(statement_does_return(control_statement(c)) && !(check_io_statement_p(control_statement(succ)) && !get_bool_property("PRETTYPRINT_CHECK_IO_STATEMENTS"))) {
the control successor is the textual successor
A label must be associated with the control successor
Is there a textual successor?
This may happen after restructuring
succ2 must be labelled
succ1 must be labelled
Both successors must be labelled
Both successors must be textual predecessors
Definition at line 290 of file unstructured.c.
References appears_first_in_trail(), CAR, CDR, check_io_statement_p(), CONTROL, control_in_trail_p(), control_statement, control_successors, debug(), ENDP, gen_length(), get_bool_property(), module, NIL, pips_assert, pips_internal_error, POP, set_control_to_label(), statement_does_return(), and statement_identification().
Referenced by text_unstructured().
void dump_control_to_label_name | ( | hash_table | h | ) |
Definition at line 500 of file unstructured.c.
References control_statement, fprintf(), HASH_MAP, and statement_identification().
Referenced by text_unstructured().
void dump_trail | ( | list | trail | ) |
trail | rail |
Definition at line 263 of file unstructured.c.
References CAR, CONTROL, control_statement, ENDP, fprintf(), MAPL, and statement_identification().
Referenced by c_unstructured(), and text_unstructured().
|
static |
set_control_to_label allocates label for the control node c in the module m.
h maps controls to label names. Computes a new label name if necessary.
There is no guarantee that a label generated here appears eventually in the text produced.
There is no guarantee that a label generated here is jumped at.
memory leak in debug code: statement_identification().
Definition at line 441 of file unstructured.c.
References asprintf, control_statement, debug(), empty_global_label_p(), entity_name, entity_undefined_p, free(), GENERATED_LABEL_MODULE_NAME, hash_get(), hash_put(), HASH_UNDEFINED_VALUE, LABEL_PREFIX, lname(), local_name(), module_local_name(), module_name(), MODULE_SEP_STRING, new_label_local_name(), pips_assert, pips_debug, statement_identification(), statement_to_label(), and strdup().
Referenced by decorate_trail().
|
static |
Is a label needed?
Perform the very same tests as in decorate_trail() The successor may have a label but not need a GOTO to be reached.
Build the statement text with enclosing braces if necessary in C and skip parasitic continues
The real successor is the false successor of the IO check
The real successor is the false successor of the IO check
Build the statement text with enclosing braces if necessary in C and skip parasitic continues
If the statement "really" has a continuation (e.g. not a STOP or a RETURN)
if(statement_does_return(st) && !(check_io_statement_p(control_statement(succ)) && !get_bool_property("PRETTYPRINT_CHECK_IO_STATEMENTS")) ) {
the control successor is the textual successor
A GOTO must be generated to reach the control successor
Is there a textual successor?
This may happen after restructuring
succ2 must be reached by GOTO
succ1 must be reached by GOTO
Both successors must be labelled
Both successors must be textual predecessors
Definition at line 513 of file unstructured.c.
References ADD_SENTENCE_TO_TEXT, appears_first_in_trail(), C_comment_to_text(), CAR, CDR, CHAIN_SWORD, check_io_statement_p(), CONTROL, control_statement, control_successors, control_to_label_name(), empty_global_label_p(), ENDP, entity_name, gen_free_list(), gen_length(), gen_nconc(), get_bool_property(), get_prettyprint_language_tag(), INDENTATION, init_text_statement(), instruction_test, instruction_test_p, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_formatted, is_sentence_unformatted, label_local_name(), MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_assert, pips_debug, pips_internal_error, POP, sentence_goto_label(), sentence_undefined, sentence_unformatted, statement_comments, statement_does_return(), statement_identification(), statement_instruction, statement_label, statement_number, statement_to_label(), strdup(), string_undefined, string_undefined_p, test_condition, test_undefined, text_statement_enclosed(), unformatted_label, unformatted_undefined, words_expression(), and words_goto_label().
Referenced by text_unstructured().
text text_unstructured | ( | entity | module, |
const char * | label, | ||
int | margin, | ||
unstructured | u, | ||
int | num, | ||
list * | ppdl | ||
) |
unstructured.c
build an arbitrary reverse trail of control nodes
decorate control nodes with labels when necessary
generate text with labels and goto's
module | odule |
label | abel |
margin | argin |
num | um |
ppdl | pdl |
Definition at line 55 of file unstructured.c.
References ADD_SENTENCE_TO_TEXT, blocks, CAR, CHAIN_SWORD, CONTROL, CONTROL_MAP, control_predecessors, control_statement, control_successors, debug(), decorate_trail(), dump_control_to_label_name(), dump_trail(), fprintf(), gen_free_list(), gen_length(), gen_nreverse(), get_bool_property(), get_comment_sentinel(), hash_pointer, hash_table_free(), hash_table_make(), ifdebug, is_sentence_unformatted, make_sentence(), make_text(), make_unformatted(), MAPL, MERGE_TEXTS, module, NIL, num, ORDERING_NUMBER, ORDERING_STATEMENT, output_a_graph_view_of_the_unstructured(), print_text(), statement_identification(), statement_ordering, strdup(), text_statement(), text_trail(), unstructured_control, unstructured_exit, and unstructured_to_trail().
Referenced by text_instruction().
list unstructured_to_trail | ( | unstructured | u | ) |
The exit node must be first (i.e. last) to reach the continuation of the unstructured, or never reached (e.g. because the program loops forever or stops in the unstructured).
Definition at line 240 of file unstructured.c.
References build_trail(), CAR, CONS, CONTROL, control_in_trail_p(), gen_remove(), NIL, unstructured_control, and unstructured_exit.
Referenced by c_unstructured(), ensure_comment_consistency(), last_statement(), new_points_to_unstructured(), and text_unstructured().