PIPS
language.c
Go to the documentation of this file.
1 /*
2 
3  $Id: language.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * The motivation of text is to delay string concatenation by dealing with
29  * lists of strings instead as more as possible.
30  */
31 
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <string.h>
35 #include <ctype.h> // isdigit()
36 
37 #include "genC.h"
38 #include "linear.h" // needed for ri.h
39 
40 #include "misc.h"
41 #include "properties.h"
42 
43 // FC: this one is bad, but the point is to avoid including ri-util...
44 #include "ri.h"
45 
46 #include "text-util.h"
47 
48 /*===================== Language management ===========*/
49 
50 /* The prettyprint language */
52 /**
53  * @brief please avoid using this function directly, use predicate instead
54  * (see below)
55  * @return the prettyprint language as a newgen language object
56  */
60  return prettyprint_language;
61 }
62 
63 
64 /**
65  * @return the prettyprint language as a language_utype
66  **/
69 }
70 
71 
72 /**
73  * @return true if the language is f77
74  **/
77 }
78 
79 
80 /**
81  * @return true if the language is f95
82  **/
85 }
86 
87 
88 /**
89  * @return true if the language is C
90  **/
93 }
94 
95 /**
96  * @brief set the prettyprint language according to the property
97  * PRETTYPRINT_LANGUAGE
98  * @description If the property PRETTYPRINT_LANGUAGE is set to the special
99  * value "native" then the language passed in arg is used, usually it's the
100  * module native language. The user can set "F77", "F95", or "C" to force the
101  * prettyprint of a language.
102  */
106  }
107  const char* lang = get_string_property ("PRETTYPRINT_LANGUAGE");
108  if (strcmp (lang, "F77") == 0) {
110  }
111  else if (strcmp (lang, "C") == 0) {
113  }
114  else if (strcmp (lang, "F95") == 0) {
116  }
117  else if (strcmp (lang, "native") == 0) {
119  } else {
120  pips_internal_error("bad property value for language");
121  }
122 }
123 
124 
125 /**
126  @brief set the prettyprint language from a newgen language object
127  @param lang, the language to be used to set the prettyprint_language
128  variable, content is copied so caller may free if it was malloced
129  **/
133  *prettyprint_language = *lang;
134 }
135 
136 
137 /**
138  @brief set the prettyprint language from a language_utype argument
139  @param lang, the language to be used to set the prettyprint_language
140  variable
141  **/
142 
147 }
148 
149 /* Get the prettyprint format of a C label
150 
151  @param label a string to render
152 
153  @return the printf-format string
154  */
155 string get_C_label_printf_format(const char* label) {
156  /* If the label begin with a digit, prefix it with a 'l' to be C
157  compatible.
158 
159  Hmmm, this does not verify that there is no such label in the program
160  already... :-( Should be solved quite earlier anyway...
161  */
162  return isdigit(label[0]) ? "l%s:" : "%s:";
163 }
language make_language_fortran(void)
Definition: ri.c:1250
char * get_string_property(const char *)
bool prettyprint_language_is_fortran95_p()
Definition: language.c:83
void set_prettyprint_language(language lang)
set the prettyprint language from a newgen language object
Definition: language.c:130
void set_prettyprint_language_from_property(enum language_utype native)
set the prettyprint language according to the property PRETTYPRINT_LANGUAGE @description If the prope...
Definition: language.c:103
language get_prettyprint_language()
please avoid using this function directly, use predicate instead (see below)
Definition: language.c:57
static language prettyprint_language
==================== Language management ===========
Definition: language.c:51
bool prettyprint_language_is_c_p()
Definition: language.c:91
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
bool prettyprint_language_is_fortran_p()
Definition: language.c:75
string get_C_label_printf_format(const char *label)
Get the prettyprint format of a C label.
Definition: language.c:155
void set_prettyprint_language_tag(enum language_utype lang)
set the prettyprint language from a language_utype argument
Definition: language.c:143
#define pips_internal_error
Definition: misc-local.h:149
#define language_undefined
Definition: ri.h:1551
#define language_tag(x)
Definition: ri.h:1590
language_utype
Definition: ri.h:1565
@ is_language_fortran
Definition: ri.h:1566
@ is_language_fortran95
Definition: ri.h:1568
@ is_language_c
Definition: ri.h:1567