25 #include "pips_config.h"
60 #include "resources.h"
70 #define STPRETTY ".st"
74 #define RESULT_NAME "result"
76 #define current_module_is_a_function() \
77 (entity_function_p(get_current_module_entity()))
124 pips_debug(6,
"st_entity_local_name is now : %s\n",name);
163 bool low_given_by_expression =
false;
164 bool old_given_by_expression =
false;
171 low_given_by_expression =
true;
174 low_given_by_expression =
false;
178 old_given_by_expression =
true;
181 old_given_by_expression =
false;
185 if (low_given_by_expression) {
186 if (old_given_by_expression) {
187 pips_debug(5,
"old=%"PRIdPTR
" low=%"PRIdPTR
"\n", old, low);
188 string istr =
int2a(old-low);
193 pips_debug(5,
"sold=%s low=%"PRIdPTR
"\n", sold, low);
194 string istr =
int2a(low);
200 if (old_given_by_expression) {
201 pips_debug(5,
"old=%"PRIdPTR
" slow=%s\n", old, slow);
202 string istr =
int2a(old);
208 pips_debug(5,
"sold=%s slow=%s\n", sold, slow);
228 bool low_given_by_expression =
false;
229 bool up_given_by_expression =
false;
236 low_given_by_expression =
true;
239 low_given_by_expression =
false;
243 up_given_by_expression =
true;
246 up_given_by_expression =
false;
250 if (low_given_by_expression) {
251 if (up_given_by_expression) {
252 pips_debug(5,
"up=%"PRIdPTR
" low=%"PRIdPTR
"\n", up, low);
253 string istr =
int2a(up-low+1);
258 string istr =
int2a(low-1);
259 pips_debug(5,
"sup=%s low=%"PRIdPTR
"\n", sup, low);
265 if (up_given_by_expression) {
266 pips_debug(5,
"up=%"PRIdPTR
" slow=%s\n", up, slow);
267 string istr =
int2a(up+1);
293 pips_debug(5,
"Dimension : %d \n", dimensions);
295 if (dimensions == 0) {
299 else if (dimensions == 1) {
310 else if (dimensions == 2) {
324 result =
strdup(
"More than 2-dimensionals arrays not handled !");
334 string result =
"UNKNOWN_BASIC" SPACE;
342 case 1: result =
"char" SPACE;
344 case 2: result =
"short" SPACE;
346 case 4: result =
"int" SPACE;
348 case 6: result =
"long" SPACE;
350 case 8: result =
"long long" SPACE;
352 case 11: result =
"unsigned char" SPACE;
354 case 12: result =
"unsigned short" SPACE;
356 case 14: result =
"unsigned int" SPACE;
358 case 16: result =
"unsigned long" SPACE;
360 case 18: result =
"unsigned long long" SPACE;
362 case 21: result =
"signed char" SPACE;
364 case 22: result =
"signed short" SPACE;
366 case 24: result =
"signed int" SPACE;
368 case 26: result =
"signed long" SPACE;
370 case 28: result =
"signed long long" SPACE;
378 case 4: result =
"float" SPACE;
380 case 8: result =
"double" SPACE;
385 result =
"int" SPACE;
388 result =
"char" SPACE;
392 result =
"Basic bit not handled";
397 result =
"Basic pointer not handled";
402 result =
"Basic derived not handled";
407 result =
"Basic typedef not handled";
423 string result =
"Undefined entity";
466 return result? result:
strdup(
"");
475 string result = NULL;
491 pips_debug(4,
"Constant with defined value\n");
513 pips_debug(4,
"Type of constant not handled\n");
515 SPACE,
"undefined", NULL));
537 if (dimensions == 0) {
553 else if (dimensions < 3) {
559 pips_debug(2,
"Arrays dimension > 2 not handled\n");
567 result =
"undefined STRUCT in SMALLTALK";
572 result =
"undefined UNION in SMALLTALK";
577 result =
"undefined ENUM in SMALLTALK";
593 string comment =
"Undefined entity";
609 if (dimensions == 0) {
613 else if (dimensions < 3) {
615 if (dimensions == 1) {
618 else if (dimensions == 2) {
692 bool (*consider_this_entity)(
entity),
696 string result =
strdup(
"");
707 if (consider_this_entity(var))
712 svar, lastsep? separator:
"", NULL));
727 bool (*consider_this_entity)(
entity),
731 string result =
strdup(
"");
742 if (consider_this_entity(var))
747 svar, lastsep? separator:
"", NULL));
762 bool (*consider_this_entity)(
entity),
766 string result =
strdup(
"");
777 if (consider_this_entity(var))
783 svar, lastsep? separator:
"", NULL));
802 bool (*consider_this_entity)(
entity),
806 string result =
strdup(
"");
817 if (consider_this_entity(var))
822 svar, lastsep? separator:
"", NULL));
836 string result, svar, args;
862 string st_head, st_variables, st_constants;
863 string st_variables_init, st_constants_init;
864 string st_variables_comment;
865 string st_body, result;
868 printf(
"Module statement: \n");
870 printf(
"and declarations: \n");
889 printf(
"%s \n", st_variables);
899 printf(
"%s \n", st_constants);
908 printf(
"VARIABLES INIT: \n");
909 printf(
"%s \n", st_variables_init);
918 printf(
"VARIABLES COMMENT: \n");
919 printf(
"%s \n", st_variables_comment);
928 printf(
"CONSTANTS INIT: \n");
929 printf(
"%s \n", st_constants_init);
940 st_variables_comment,
NL
943 st_constants_init,
NL,
944 st_variables_init,
NL,
979 bool p1, p2, pr1, pr2;
991 pips_assert(
"assignment call: first expression is reference",
1060 result =
strdup(
"Arrays more than 2D are not handled !");
1270 printf(
"\nCurrent statement : \n");
1322 "UNSTRUCTURED: Instruction not implementable in SMALLTALK",
1331 "GOTO: Instruction not implementable in SMALLTALK",
1367 string cond, strue, sfalse;
1391 if (sfalse)
free(sfalse);
1405 string oldresult = result;
1411 result =
strdup(oldresult);
1425 string result, initialisation, loopbody, incrementation;
1438 if (incasint >= 0) {
1439 istr =
int2a(incasint);
1444 istr =
int2a(-incasint);
1460 body, incrementation,
1466 free(initialisation);
1467 free(incrementation);
1504 string result, loopbody;
1510 body,
"}" NL, NULL));
1646 string result = NULL;
1654 result =
strdup(
"range not implemented");
1673 string ppt, smalltalkcode, dir, filename;
1687 debug_on(
"SMALLTALK_PRETTYPRINTER_DEBUG_LEVEL");
struct _newgen_struct_statement_ * statement
const char * module_name(const char *s)
Return the module part of an entity name.
FILE * safe_fopen(const char *filename, const char *what)
int safe_fclose(FILE *stream, const char *filename)
#define call_constant_p(C)
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
entity get_current_module_entity(void)
Get the entity of the current module.
#define ENDP(l)
Test if a list is empty.
#define NIL
The empty list (nil in Lisp)
size_t gen_length(const list l)
#define CAR(pcons)
Get the value of the first element of a list.
#define CDR(pcons)
Get the list less its first element.
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
bool empty_statement_p(statement)
Test if a statement is empty.
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
#define MEMBER_SEP_STRING
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define same_string_p(s1, s2)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
string db_get_current_workspace_directory(void)
string expression_to_string(expression e)
void print_statement(statement)
Print a statement on stderr.
static bool variable_p(entity e)
This function return a bool indicating if related entity e represents a variable.
static string st_entity_local_name(entity var)
Return beautified string representing name for entity var.
static string st_reference(reference r)
This function return a string representation of a reference r.
static struct s_ppt * get_ppt(entity f)
Return the prettyprinter structure for SmallTalk.
static bool argument_p(entity e)
This function return a bool indicating if related entity e represents an argument.
static string ppt_unary(string in_smalltalk, list le)
Return string representation for a list of expression le representing a UNARY relation,...
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 functio...
static string st_expression(expression)
static string st_declaration_comment(entity var)
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) v...
static bool expression_needs_parenthesis_p(expression)
Return bool indicating if expression e must be enclosed in parenthesis.
static string st_header(entity module)
Generate header for SMALLTALK module.
static string st_whileloop(whileloop w)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
bool print_code_smalltalk(const char *module_name)
print_code_smalltalk.c
static string ppt_call(string in_smalltalk, list le)
static string st_sequence(sequence seq)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string ppt_unary_post(string in_smalltalk, list le)
Return string representation for a list of expression le representing a UNARY POST relation,...
static string st_loop(loop l)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_test(test t)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
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.
string(* prettyprinter)(string, list)
static string st_statement(statement s)
This method returns Smalltalk-like string representation (pretty-print) for a statement s.
static string st_dimension_bound_as_string(dimension dim)
Return a string representing dimension bounds of a dimension dim This function automatically convert ...
static string ppt_assignement(string in_smalltalk, list le)
Return string representation for a list of expression le representing an assignement,...
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 sty...
static struct s_ppt intrinsic_to_smalltalk[]
This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk co...
static string st_call(call c)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static bool constant_p(entity e)
This function return a bool indicating if related entity e represents a constant.
#define current_module_is_a_function()
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 sty...
static string ppt_binary(string in_smalltalk, list le)
Return string representation for a list of expression le representing a BINARY relation,...
static string c_basic_string(basic b)
Return a string C-like representation of basic b.
static string st_dim_string(string svar, list ldim)
Return string representing array initialization for variable svar in SMALLTALK.
static string smalltalk_code_string(entity module, statement stat)
static string st_brace_expression_as_string(expression exp)
Return string representing expression enclosed by parenthesis.
#define STPRETTY
This phase is used for PHRASE project.
static string st_forloop(forloop f)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_arguments(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
Return string representing arguments declaration written in SmallTalk style.
static string st_declaration(entity var)
Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old func...
static string st_declaration_init(entity var)
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) v...
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
bool entity_main_module_p(entity e)
static int init
Maximal value set for Fortran 77.
void print_entities(list l)
bool expression_integer_value(expression e, intptr_t *pval)
bool brace_expression_p(expression e)
Return bool indicating if expression e is a brace expression.
#define type_functional_p(x)
#define value_undefined_p(x)
#define storage_formal_p(x)
#define value_constant(x)
#define syntax_reference(x)
#define forloop_initialization(x)
#define reference_variable(x)
#define forloop_increment(x)
#define symbolic_constant(x)
#define instruction_loop(x)
#define dimension_lower(x)
#define entity_storage(x)
#define code_declarations(x)
#define range_increment(x)
#define value_constant_p(x)
#define value_symbolic(x)
#define EXPRESSION(x)
EXPRESSION.
#define constant_int_p(x)
@ is_instruction_unstructured
@ is_instruction_whileloop
@ is_instruction_sequence
#define instruction_tag(x)
#define value_symbolic_p(x)
#define sequence_statements(x)
#define dimension_upper(x)
#define reference_indices(x)
#define instruction_sequence(x)
#define instruction_forloop(x)
#define test_condition(x)
#define instruction_whileloop(x)
#define variable_dimensions(x)
#define whileloop_body(x)
#define statement_declarations(x)
#define statement_instruction(x)
#define instruction_call(x)
#define forloop_condition(x)
#define call_arguments(x)
#define instruction_test(x)
#define whileloop_condition(x)
#define value_expression_p(x)
#define expression_syntax(x)
#define storage_return_p(x)
#define type_variable_p(x)
#define value_expression(x)
#define variable_basic(x)
#define STATEMENT(x)
STATEMENT.
#define entity_initial(x)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define ARRAY2D_AT_AT_PUT_2
#define ARRAY2D_AT_AT_PUT_3
#define ARRAY2D_AT_AT_PUT_1
The structure used to build lists in NewGen.
#define exp
Avoid some warnings from "gcc -Wshadow".