PIPS
|
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "smalltalk-defs.h"
Go to the source code of this file.
Data Structures | |
struct | s_ppt |
Macros | |
#define | STPRETTY ".st" |
This phase is used for PHRASE project. More... | |
#define | RESULT_NAME "result" |
#define | current_module_is_a_function() (entity_function_p(get_current_module_entity())) |
Typedefs | |
typedef string(* | prettyprinter) (string, list) |
Functions | |
static string | st_statement (statement s) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s. More... | |
static string | st_sequence (sequence seq) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Sequence Statement (an ordered set of sequential statements) More... | |
static string | st_call (call c) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Call Statement (a code line) More... | |
static string | st_expression (expression) |
static string | st_reference (reference r) |
This function return a string representation of a reference r. More... | |
static string | st_test (test t) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Test Statement (IF/THEN/ELSE) More... | |
static string | st_loop (loop l) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Loop Statement (DO...ENDDO) More... | |
static string | st_whileloop (whileloop w) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a While-Loop Statement (DO WHILE...ENDDO) More... | |
static string | st_forloop (forloop f) |
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a For-Loop Statement (I don't know how to specify in fortran !!!) More... | |
static string | st_entity_local_name (entity var) |
Return beautified string representing name for entity var. More... | |
static string | st_brace_expression_as_string (expression exp) |
Return string representing expression enclosed by parenthesis. More... | |
static string | st_dimension_reference_as_string (dimension dim, expression old_expression) |
Return a string representing dimension reference for a dimension dim and an expression e This function automatically convert bounds in fortran to bounds starting from 0 by doing new_reference = old_reference - lower This function is valid even in case of non-directly-cumputable expressions. More... | |
static string | st_dimension_bound_as_string (dimension dim) |
Return a string representing dimension bounds of a dimension dim This function automatically convert bounds in fortran to bounds starting from 0 by doing upbound = (upper - lower + 1) This function is valid even in case of non-directly-cumputable expressions. More... | |
static string | st_dim_string (string svar, list ldim) |
Return string representing array initialization for variable svar in SMALLTALK. More... | |
static string | c_basic_string (basic b) |
Return a string C-like representation of basic b. More... | |
static string | st_declaration (entity var) |
Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old function this_entity_cdeclaration(entity var) More... | |
static string | st_declaration_init (entity var) |
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var. More... | |
static string | st_declaration_comment (entity var) |
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var. More... | |
static bool | constant_p (entity e) |
This function return a bool indicating if related entity e represents a constant. More... | |
static bool | variable_p (entity e) |
This function return a bool indicating if related entity e represents a variable. More... | |
static bool | argument_p (entity e) |
This function return a bool indicating if related entity e represents an argument. More... | |
static string | st_arguments (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep) |
Return string representing arguments declaration written in SmallTalk style. More... | |
static string | st_declarations (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep) |
Return string representing variables or constants declaration written in SmallTalk style. More... | |
static string | st_declarations_init (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep) |
Return string representing variables or constants declaration initialisation written in SmallTalk style. More... | |
static string | st_declarations_comment (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep) |
Return string representing variables or constants declaration initialisation written in SmallTalk style. More... | |
static string | st_header (entity module) |
Generate header for SMALLTALK module. More... | |
static string | smalltalk_code_string (entity module, statement stat) |
static bool | expression_needs_parenthesis_p (expression e) |
Return bool indicating if expression e must be enclosed in parenthesis. More... | |
static string | ppt_assignement (string in_smalltalk, list le) |
Return string representation for a list of expression le representing an assignement, asserting that le is a list of expressions containing exactly TWO expressions. More... | |
static string | ppt_binary (string in_smalltalk, list le) |
Return string representation for a list of expression le representing a BINARY relation, asserting that le is a list of expressions containing exactly TWO expressions. More... | |
static string | ppt_unary (string in_smalltalk, list le) |
Return string representation for a list of expression le representing a UNARY relation, asserting that le is a list of expressions containing exactly ONE expression. More... | |
static string | ppt_unary_post (string in_smalltalk, list le) |
Return string representation for a list of expression le representing a UNARY POST relation, asserting that le is a list of expressions containing exactly ONE expression. More... | |
static string | ppt_call (string in_smalltalk, list le) |
static struct s_ppt * | get_ppt (entity f) |
Return the prettyprinter structure for SmallTalk. More... | |
bool | print_code_smalltalk (const char *module_name) |
print_code_smalltalk.c More... | |
Variables | |
static struct s_ppt | intrinsic_to_smalltalk [] |
This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk code. More... | |
#define current_module_is_a_function | ( | ) | (entity_function_p(get_current_module_entity())) |
Definition at line 76 of file print_code_smalltalk.c.
#define RESULT_NAME "result" |
Definition at line 74 of file print_code_smalltalk.c.
#define STPRETTY ".st" |
This phase is used for PHRASE project.
NB: The PHRASE project is an attempt to automatically (or semi-automatically) transform high-level language for partial evaluation in reconfigurable logic (such as FPGAs or DataPaths).
This pass is used in context of PHRASE project for synthetisation of reconfigurable logic for a portion of initial code. This function can be viewed as a Smalltalk pretty-printer of a subset of Fortran.
alias print_code_smalltalk 'Smalltalk Pretty-Printer'
print_code_smalltalk > MODULE.smalltalk_code < PROGRAM.entities < MODULE.code
The Smalltalk code will be available in SMALLTALK_CODE_FILE
NB: This code is highly inspired from PRINT_C_CODE phase written by nguyen
Definition at line 70 of file print_code_smalltalk.c.
Definition at line 958 of file print_code_smalltalk.c.
This function return a bool indicating if related entity e represents an argument.
Formal variables
Definition at line 679 of file print_code_smalltalk.c.
References entity_storage, entity_type, storage_formal_p, and type_variable_p.
Referenced by generic_c_words_simplified_entity(), st_header(), and words_type().
Return a string C-like representation of basic b.
Definition at line 332 of file print_code_smalltalk.c.
References basic_float, basic_int, basic_tag, is_basic_bit, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_pointer, is_basic_string, is_basic_typedef, pips_debug, pips_internal_error, SPACE, and strdup().
Referenced by st_declaration_comment().
This function return a bool indicating if related entity e represents a constant.
Constant variables
Definition at line 656 of file print_code_smalltalk.c.
References entity_initial, entity_storage, entity_type, storage_rom_p, type_functional_p, and value_symbolic_p.
Referenced by call_to_points_to_sinks(), constant_points_to_indices_p(), constant_reference_to_normalized_constant_reference(), expression_string_constant_p(), expression_to_points_to_cells(), expression_with_constant_signed_integer_value_p(), extended_expression_constant_p(), intrinsic_call_to_points_to_sinks(), reference_to_points_to_sinks(), reference_with_constant_indices_p(), smalltalk_code_string(), store_independent_points_to_indices_p(), ternary_intrinsic_call_to_points_to_sinks(), and unary_intrinsic_call_to_points_to_sinks().
|
static |
Return bool indicating if expression e must be enclosed in parenthesis.
Definition at line 1243 of file print_code_smalltalk.c.
References call_function, expression_syntax, get_ppt(), is_syntax_call, is_syntax_range, is_syntax_reference, s_ppt::ppt, ppt_binary(), syntax_call, and syntax_tag.
Referenced by ppt_assignement(), ppt_binary(), and st_reference().
Return the prettyprinter structure for SmallTalk.
Definition at line 1230 of file print_code_smalltalk.c.
References entity_local_name(), f(), s_ppt::intrinsic, intrinsic_to_smalltalk, and same_string_p.
Referenced by expression_needs_parenthesis_p(), and st_call().
Return string representation for a list of expression le representing an assignement, asserting that le is a list of expressions containing exactly TWO expressions.
This is a scalar variable
Definition at line 974 of file print_code_smalltalk.c.
References ARRAY2D_AT_AT_PUT_1, ARRAY2D_AT_AT_PUT_2, ARRAY2D_AT_AT_PUT_3, ARRAY_AT_PUT_1, ARRAY_AT_PUT_2, CAR, CDR, CLOSEPAREN, concatenate(), DIMENSION, EMPTY, entity_type, EXPRESSION, expression_needs_parenthesis_p(), expression_syntax, free(), gen_length(), gen_nth(), is_syntax_reference, OPENPAREN, pips_assert, reference_indices, reference_variable, s1, SPACE, st_dimension_reference_as_string(), st_entity_local_name(), st_expression(), st_reference(), strdup(), syntax_reference, syntax_tag, type_variable, and variable_dimensions.
Return string representation for a list of expression le representing a BINARY relation, asserting that le is a list of expressions containing exactly TWO expressions.
Definition at line 1073 of file print_code_smalltalk.c.
References CAR, CDR, CLOSEPAREN, concatenate(), EMPTY, EXPRESSION, expression_needs_parenthesis_p(), free(), gen_length(), OPENPAREN, pips_assert, s1, SPACE, st_expression(), and strdup().
Referenced by expression_needs_parenthesis_p().
Attention: not like this for io statements
Definition at line 1131 of file print_code_smalltalk.c.
Return string representation for a list of expression le representing a UNARY relation, asserting that le is a list of expressions containing exactly ONE expression.
Definition at line 1106 of file print_code_smalltalk.c.
References CAR, concatenate(), EXPRESSION, free(), gen_length(), pips_assert, SPACE, st_expression(), and strdup().
Return string representation for a list of expression le representing a UNARY POST relation, asserting that le is a list of expressions containing exactly ONE expression.
Definition at line 1121 of file print_code_smalltalk.c.
References CAR, concatenate(), EXPRESSION, free(), gen_length(), pips_assert, SPACE, st_expression(), and strdup().
bool print_code_smalltalk | ( | const char * | module_name | ) |
We first build the future resource file, with a .st
save to file
module_name | odule_name |
Definition at line 1670 of file print_code_smalltalk.c.
References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_FILE_RESOURCE, debug_on, entity_name, fprintf(), free(), module, module_name(), module_name_to_entity(), out, pips_debug, s_ppt::ppt, reset_current_module_entity(), reset_current_module_statement(), safe_fclose(), safe_fopen(), set_current_module_entity(), set_current_module_statement(), smalltalk_code_string(), STPRETTY, and strdup().
HEAD generates the header
Generates the variables declarations
What about declarations associated to statements ???
Generates the constant declarations
Generates the variables declarations initialisation
Generates the variables declarations comments
Generates the constant declarations initialisation
Generates the body
Definition at line 860 of file print_code_smalltalk.c.
References BEGINTEMPVAR, concatenate(), constant_p(), ENDTEMPVAR, free(), ifdebug, module, NL, print_entities(), print_statement(), printf(), SPACE, st_declarations(), st_declarations_comment(), st_declarations_init(), st_header(), st_statement(), statement_declarations, strdup(), STSEMICOLON, and variable_p().
Referenced by print_code_smalltalk().
|
static |
Return string representing arguments declaration written in SmallTalk style.
Assert that entity represent a value code
Definition at line 691 of file print_code_smalltalk.c.
References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_entity_local_name(), strdup(), value_code, and value_code_p.
Referenced by st_header().
|
static |
Return string representing expression enclosed by parenthesis.
Definition at line 132 of file print_code_smalltalk.c.
References brace_expression_p(), call_arguments, CLOSEBRACKET, concatenate(), exp, EXPRESSION, expression_syntax, expression_to_string(), MAP, OPENBRACKET, strdup(), and syntax_call.
Referenced by st_declaration_init().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Call Statement (a code line)
special case...
Definition at line 1532 of file print_code_smalltalk.c.
References s_ppt::c, call_arguments, call_constant_p, call_function, current_module_is_a_function, entity_local_name(), entity_main_module_p(), free(), get_current_module_entity(), get_ppt(), s_ppt::ppt, RESULT_NAME, RETURNVALUE, same_string_p, SPACE, st_entity_local_name(), and strdup().
Referenced by st_expression(), and st_statement().
Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old function this_entity_cdeclaration(entity var)
Definition at line 421 of file print_code_smalltalk.c.
References concatenate(), entity_local_name(), entity_storage, entity_type, free(), is_storage_rom, is_type_enum, is_type_struct, is_type_union, is_type_variable, st_entity_local_name(), storage_tag, strdup(), and type_tag.
Referenced by st_declarations(), and st_statement().
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var.
Definition at line 591 of file print_code_smalltalk.c.
References c_basic_string(), COMMENT, comment(), concatenate(), entity_name, entity_type, free(), gen_length(), is_type_enum, is_type_struct, is_type_union, is_type_variable, pips_debug, st_entity_local_name(), strdup(), type_tag, type_variable, variable_basic, and variable_dimensions.
Referenced by st_declarations_comment().
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var.
This is a constant, we must initialize it
This variable must be initialized Anyway, i don't know how to initialize a variable at declaration in Fortran !!!
Definition at line 473 of file print_code_smalltalk.c.
References brace_expression_p(), concatenate(), constant_int, constant_int_p, entity_initial, entity_name, entity_storage, entity_type, exp, expression_to_string(), free(), gen_length(), int2a(), is_storage_rom, is_type_enum, is_type_struct, is_type_union, is_type_variable, pips_debug, SETVALUE, SPACE, st_brace_expression_as_string(), st_dim_string(), st_entity_local_name(), storage_tag, strdup(), symbolic_constant, type_tag, type_variable, value_constant, value_constant_p, value_expression, value_expression_p, value_symbolic, value_symbolic_p, value_undefined_p, and variable_dimensions.
Referenced by st_declarations_init().
|
static |
Return string representing variables or constants declaration written in SmallTalk style.
Assert that entity represent a value code
Definition at line 726 of file print_code_smalltalk.c.
References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration(), st_entity_local_name(), strdup(), value_code, and value_code_p.
Referenced by smalltalk_code_string().
|
static |
Return string representing variables or constants declaration initialisation written in SmallTalk style.
Assert that entity represent a value code
Definition at line 801 of file print_code_smalltalk.c.
References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration_comment(), st_entity_local_name(), strdup(), value_code, and value_code_p.
Referenced by smalltalk_code_string().
|
static |
Return string representing variables or constants declaration initialisation written in SmallTalk style.
Assert that entity represent a value code
Definition at line 761 of file print_code_smalltalk.c.
References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration_init(), st_entity_local_name(), strdup(), value_code, and value_code_p.
Referenced by smalltalk_code_string().
Return string representing array initialization for variable svar in SMALLTALK.
Definition at line 286 of file print_code_smalltalk.c.
References ARRAY, ARRAY2D, ARRAY2D_NEW1, ARRAY2D_NEW2, ARRAY_NEW, concatenate(), DIMENSION, gen_length(), gen_nth(), pips_debug, SETVALUE, SPACE, st_dimension_bound_as_string(), and strdup().
Referenced by st_declaration_init().
Return a string representing dimension bounds of a dimension dim This function automatically convert bounds in fortran to bounds starting from 0 by doing upbound = (upper - lower + 1) This function is valid even in case of non-directly-cumputable expressions.
Definition at line 223 of file print_code_smalltalk.c.
References CLOSEBRACE, concatenate(), dimension_lower, dimension_upper, EMPTY, expression_integer_value(), free(), int2a(), intptr_t, OPENBRACE, pips_debug, st_expression(), and strdup().
Referenced by st_dim_string().
|
static |
Return a string representing dimension reference for a dimension dim and an expression e This function automatically convert bounds in fortran to bounds starting from 0 by doing new_reference = old_reference - lower This function is valid even in case of non-directly-cumputable expressions.
Definition at line 158 of file print_code_smalltalk.c.
References CLOSEBRACE, concatenate(), dimension_lower, EMPTY, expression_integer_value(), free(), int2a(), intptr_t, OPENBRACE, pips_debug, st_expression(), and strdup().
Referenced by ppt_assignement(), and st_reference().
Return beautified string representing name for entity var.
Delete all the prefixes
Definition at line 93 of file print_code_smalltalk.c.
References current_module_is_a_function, entity_local_name(), ENUM_PREFIX, get_current_module_entity(), MAIN_PREFIX, MEMBER_SEP_STRING, pips_debug, RESULT_NAME, same_string_p, strdup(), STRUCT_PREFIX, TYPEDEF_PREFIX, and UNION_PREFIX.
Referenced by ppt_assignement(), st_arguments(), st_call(), st_declaration(), st_declaration_comment(), st_declaration_init(), st_declarations(), st_declarations_comment(), st_declarations_init(), st_header(), st_loop(), st_reference(), and st_statement().
|
static |
add cast, sizeof here
Definition at line 1644 of file print_code_smalltalk.c.
References expression_syntax, is_syntax_call, is_syntax_range, is_syntax_reference, pips_internal_error, st_call(), st_reference(), strdup(), syntax_call, syntax_reference, and syntax_tag.
Referenced by ppt_assignement(), ppt_binary(), ppt_unary(), ppt_unary_post(), st_dimension_bound_as_string(), st_dimension_reference_as_string(), st_forloop(), st_loop(), st_test(), and st_whileloop().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a For-Loop Statement (I don't know how to specify in fortran !!!)
Definition at line 1502 of file print_code_smalltalk.c.
References CLOSEBRACKET, concatenate(), f(), forloop_body, forloop_condition, forloop_increment, forloop_initialization, free(), init, NL, OPENBRACKET, SPACE, st_expression(), st_statement(), ST_WHILETRUE, strdup(), and STSEMICOLON.
Referenced by st_statement().
Generate header for SMALLTALK module.
Generates the arguments declarations
Definition at line 834 of file print_code_smalltalk.c.
References argument_p(), COMMENT, concatenate(), entity_type, module, NL, pips_assert, SPACE, st_arguments(), st_entity_local_name(), strdup(), and type_functional_p.
Referenced by smalltalk_code_string().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Loop Statement (DO...ENDDO)
Definition at line 1423 of file print_code_smalltalk.c.
References CLOSEBRACKET, concatenate(), expression_integer_value(), free(), int2a(), intptr_t, loop_body, loop_index, loop_range, NL, OPENBRACKET, range_increment, range_lower, range_upper, SETVALUE, SPACE, st_entity_local_name(), st_expression(), ST_LE, ST_MINUS, ST_PLUS, st_statement(), ST_WHILETRUE, strdup(), and STSEMICOLON.
Referenced by st_statement().
This function return a string representation of a reference r.
A reference is an array element, considering non-array variables (scalar variables) are 0-dimension arrays elements. We must here differently manage scalar, 1-D arrays (using SmallTalk Array class) and 2-D arrays (using SmallTalk Array2D).
NB: in Fortran, the indexes are reversed
This is a scalar variable, no need to manage array indices
Definition at line 1577 of file print_code_smalltalk.c.
References ARRAY2D_AT_AT_1, ARRAY2D_AT_AT_2, ARRAY_AT, CLOSEPAREN, COMMENT, concatenate(), DIMENSION, EMPTY, entity_type, EXPRESSION, expression_needs_parenthesis_p(), free(), gen_length(), gen_nth(), OPENPAREN, reference_indices, reference_variable, SPACE, st_dimension_reference_as_string(), st_entity_local_name(), strdup(), type_variable, and variable_dimensions.
Referenced by ppt_assignement(), and st_expression().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Sequence Statement (an ordered set of sequential statements)
Definition at line 1400 of file print_code_smalltalk.c.
References concatenate(), current, EMPTY, free(), MAP, sequence_statements, st_statement(), STATEMENT, and strdup().
Referenced by st_statement().
This method returns Smalltalk-like string representation (pretty-print) for a statement s.
nstructured u = instruction_unstructured(i);
tatement g = instruction_goto(i);
add switch, forloop break, continue, return instructions here
Definition at line 1264 of file print_code_smalltalk.c.
References COMMENT, concatenate(), debug(), ENDP, ENTITY, f(), free(), ifdebug, instruction_call, instruction_forloop, instruction_loop, instruction_sequence, instruction_tag, instruction_test, instruction_whileloop, is_instruction_call, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, MAP, NL, pips_debug, pips_user_warning, print_statement(), printf(), st_call(), st_declaration(), st_entity_local_name(), st_forloop(), st_loop(), st_sequence(), st_test(), st_whileloop(), statement_declarations, statement_instruction, strdup(), and STSEMICOLON.
Referenced by smalltalk_code_string(), st_forloop(), st_loop(), st_sequence(), st_test(), and st_whileloop().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Test Statement (IF/THEN/ELSE)
Definition at line 1363 of file print_code_smalltalk.c.
References CLOSEBRACKET, CLOSEPAREN, concatenate(), empty_statement_p(), free(), NL, OPENBRACKET, OPENPAREN, SPACE, st_expression(), ST_IFFALSE, ST_IFTRUE, st_statement(), strdup(), STSEMICOLON, test_condition, test_false, and test_true.
Referenced by st_statement().
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a While-Loop Statement (DO WHILE...ENDDO)
valuation eval = whileloop_evaluation(w);
Definition at line 1480 of file print_code_smalltalk.c.
References CLOSEBRACKET, concatenate(), free(), NL, OPENBRACKET, SPACE, st_expression(), st_statement(), ST_WHILETRUE, strdup(), STSEMICOLON, whileloop_body, and whileloop_condition.
Referenced by st_statement().
This function return a bool indicating if related entity e represents a variable.
Definition at line 668 of file print_code_smalltalk.c.
References entity_storage, entity_type, storage_ram_p, storage_return_p, and type_variable_p.
Referenced by smalltalk_code_string().
|
static |
This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk code.
Definition at line 1131 of file print_code_smalltalk.c.
Referenced by get_ppt().