PIPS
xv_compile.c
Go to the documentation of this file.
1 /*
2 
3  $Id: xv_compile.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 #include <stdlib.h>
28 #include <stdio.h>
29 #include <xview/xview.h>
30 #include <xview/panel.h>
31 
32 #include "genC.h"
33 #include "linear.h"
34 #include "ri.h"
35 #include "ri-util.h"
36 #include "misc.h"
37 #include "phases.h"
38 #include "database.h"
39 #include "pipsdbm.h"
40 #include "pipsmake.h"
41 #include "top-level.h"
42 #include "wpips.h"
43 
44 static Menu compile_menu;
45 
46 void
48  void (* function_to_apply_on_each_menu_item)(Menu_item))
49 {
50  int i;
51 
52  for(i = (int) xv_get(compile_menu, MENU_NITEMS); i >= 1; i--) {
53  Menu_item menu_item = (Menu_item) xv_get(compile_menu, MENU_NTH_ITEM, i);
54  /* Skip the title item and the separator items: */
55  if (!(bool) xv_get(menu_item, MENU_TITLE))
56  function_to_apply_on_each_menu_item(menu_item);
57  }
58 }
59 
60 
61 void
63 {
65 }
66 
67 
68 void
70 {
72 }
73 
74 
75 void
77  Menu_item menu_item)
78 {
79  char * file_name = (char *) xv_get(menu_item, MENU_STRING);
81 
82  if (! wpips_emacs_mode) {
83  /* Try to allocate an available edit_textsw in non-emacs mode: */
84  (void) alloc_first_initialized_window(FALSE);
85  }
86 
87  wpips_file_view(path_name, file_name, "HPFC File", "HPFC", "HPFC");
88  user_log("HPFC View of \"%s\" done.\n", file_name);
89 }
90 
91 
92 Menu
94  Menu_item menu_item,
95  Menu_generate action)
96 {
97  int i;
98  Menu menu;
99  gen_array_t file_names = gen_array_make(0);
100  int file_number = 0;
101 
102  pips_debug(2, "Enter\n");
103 
104  menu = (Menu) xv_get(menu_item, MENU_PULLRIGHT);
105 
106  switch(action) {
107  case MENU_DISPLAY:
108  {
109  int return_code;
110  char *hpfc_directory;
111 
112  pips_debug(2, "MENU_DISPLAY\n");
113 
114  /* Create a new menu with the content of the hpfc directory: */
115 
116  if (menu != NULL) {
117  /* First, free the old menu if it exist: */
118  /* We can remove all the menu it now: */
119  for(i = (int) xv_get(menu, MENU_NITEMS); i > 0; i--) {
120  xv_set(menu, MENU_REMOVE, i, NULL);
121  xv_destroy(xv_get(menu, MENU_NTH_ITEM, i));
122  }
123  xv_destroy(menu);
124  }
125 
126 
127  return_code = hpfc_get_file_list(file_names,
128  &hpfc_directory);
129 
130  if (return_code == -1) {
131  user_warning("generate_a_menu_with_HPF_output_files",
132  "Directory \"%s\" not found... \n"
133  " Have you run the HPFC compiler from the Compile menu?\n",
134  hpfc_directory);
135 
136  menu = (Menu) xv_create(NULL, MENU,
137  MENU_TITLE_ITEM,
138  "Are you sure you used the HPF compiler ?",
139  MENU_ITEM, MENU_STRING,
140  "*** No HPFC directory found ! ***", NULL,
141  NULL);
142  }
143  else if (file_number == 0) {
144  user_warning("generate_a_menu_with_HPF_output_files",
145  "No file found in the directory \"%s\"... \n"
146  " Have you run the HPFC compiler from the Compile menu?\n",
147  hpfc_directory);
148 
149  menu = (Menu) xv_create(NULL, MENU,
150  MENU_TITLE_ITEM,
151  "Are you sure you used the HPF compiler ?",
152  MENU_ITEM, MENU_STRING,
153  "*** No HPFC file found ! ***", NULL,
154  NULL);
155  }
156  else {
157  menu = (Menu) xv_create(NULL, MENU,
158  MENU_TITLE_ITEM,
159  " Select an HPFC file to view ",
160  MENU_NOTIFY_PROC, notify_hpfc_file_view,
161  NULL);
162 
163  for(i = 0; i < file_number; i++)
164  xv_set(menu, MENU_APPEND_ITEM,
165  xv_create(XV_NULL, MENUITEM,
166  MENU_STRING,
167  strdup(gen_array_item(file_names, i)),
168  MENU_RELEASE,
169  /* The strdup'ed string will also be
170  freed when the menu is discarded: */
171  MENU_RELEASE_IMAGE,
172  NULL),
173  NULL);
174 
175  gen_array_full_free(file_names);
176  }
177  break;
178  }
179 
180  case MENU_DISPLAY_DONE:
181  /* We cannot remove the menu here since the notify
182  procedure is called afterward. */
183  menu = (Menu) xv_get(menu_item, MENU_PULLRIGHT);
184  pips_debug(2, "MENU_DISPLAY_DONE\n");
185  break;
186 
187  case MENU_NOTIFY:
188  /* Rely on the notify procedure. */
189  menu = (Menu) xv_get(menu_item, MENU_PULLRIGHT);
190  pips_debug(2, "MENU_NOTIFY\n");
191  break;
192 
193  case MENU_NOTIFY_DONE:
194  menu = (Menu) xv_get(menu_item, MENU_PULLRIGHT);
195  pips_debug(2, "MENU_NOTIFY_DONE\n");
196  break;
197 
198  default:
199  pips_internal_error("Unknown Menu_generate action: %d\n", action);
200  }
201  pips_debug(2, "Exit\n");
202  return menu;
203 }
204 
205 #define HPFC_COMPILE "Compile an HPF program"
206 #define HPFC_MAKE "Make an HPF program"
207 #define HPFC_RUN "Run an HPF program"
208 
209 /* quick fix around pipsmake, FC, 23/10/95
210  */
212 
213 void
215 {
217 }
218 
219 void
220 hpfc_notify(Menu menu,
221  Menu_item menu_item)
222 {
223  char *label, *modulename;
224 
225  modulename = db_get_current_module_name();
226  if (!modulename)
227  {
228  prompt_user("No module selected");
229  return;
230  }
231 
232  label = (char *) xv_get(menu_item, MENU_STRING);
233 
234  /* I apply the installation only once, whatever...
235  * Quick fix because the right dependences expressed for pipsmake
236  * do not seem to work. It seems that the verification of up to date
237  * resources is too clever... FC.
238  */
240  {
241  safe_apply(BUILDER_HPFC_INSTALL, modulename);
243  }
244 
245  if (same_string_p(label, HPFC_COMPILE))
246  ;
247  else if (same_string_p(label, HPFC_MAKE))
248  safe_apply_outside_the_notifyer(BUILDER_HPFC_MAKE, modulename);
249  else if (same_string_p(label, HPFC_RUN))
250  safe_apply_outside_the_notifyer(BUILDER_HPFC_RUN, modulename);
251  else
252  pips_internal_error("Bad choice: %s", label);
253 }
254 
255 
256 void
258 {
259  compile_menu =
260  xv_create(XV_NULL, MENU_COMMAND_MENU,
261  MENU_GEN_PIN_WINDOW, main_frame, "Compile Menu",
262  MENU_TITLE_ITEM, "Compilation ",
263  MENU_ACTION_ITEM, HPFC_COMPILE, hpfc_notify,
264  MENU_ACTION_ITEM, HPFC_MAKE, hpfc_notify,
265  MENU_ACTION_ITEM, HPFC_RUN, hpfc_notify,
266  /* Just a separator: */
268  MENU_GEN_PULLRIGHT_ITEM,
269  "View the HPF Compiler Output",
271  NULL);
272 
273  (void) xv_create(main_panel, PANEL_BUTTON,
274  PANEL_LABEL_STRING, "Compile",
275  PANEL_ITEM_MENU, compile_menu,
276  NULL);
277 }
278 
void user_log(const char *format,...)
Definition: message.c:234
string db_get_current_module_name(void)
Also used to check whether set...
Definition: database.c:1059
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
bool wpips_emacs_mode
Here are all the stuff to interface Pips with Emacs.
Definition: emacs.c:65
GtkWidget * main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: gpips.c:60
int alloc_first_initialized_window(bool the_same_as_previous)
Find the first free window if any.
Definition: gtk_edit2.c:215
void prompt_user(string a_printf_format,...)
Definition: gtk_log.c:66
void safe_apply_outside_the_notifyer(string transformation_name_to_apply, string module_name)
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_internal_error
Definition: misc-local.h:149
#define user_warning(fn,...)
Definition: misc-local.h:262
#define same_string_p(s1, s2)
bool safe_apply(const char *phase_n, const char *module_n)
Definition: pipsmake.c:1723
int hpfc_get_file_list(gen_array_t, char **)
Definition: source_file.c:106
string hpfc_generate_path_name_of_file_name(const char *)
Return the path of an HPFC file name relative to the current PIPS directory.
Definition: source_file.c:97
char * strdup()
static string file_name
Panel main_panel
Definition: wpips.c:63
#define WPIPS_MENU_SEPARATOR
Define the menu separator:
Definition: wpips-local.h:94
Menu generate_a_menu_with_HPF_output_files(Menu_item menu_item, Menu_generate action)
Definition: xv_compile.c:93
#define HPFC_COMPILE
Definition: xv_compile.c:205
#define HPFC_RUN
Definition: xv_compile.c:207
static Menu compile_menu
Definition: xv_compile.c:44
void hpfc_notify(Menu menu, Menu_item menu_item)
Definition: xv_compile.c:220
void disable_compile_selection()
Definition: xv_compile.c:62
void apply_on_each_compile_item(void(*function_to_apply_on_each_menu_item)(Menu_item))
Definition: xv_compile.c:47
void create_compile_menu()
Definition: xv_compile.c:257
void initialize_wpips_hpfc_hack_for_fabien_and_from_fabien()
Definition: xv_compile.c:214
static bool wpips_hpfc_install_was_performed_hack
quick fix around pipsmake, FC, 23/10/95
Definition: xv_compile.c:211
void notify_hpfc_file_view(Menu menu, Menu_item menu_item)
Definition: xv_compile.c:76
#define HPFC_MAKE
Definition: xv_compile.c:206
void enable_compile_selection()
Definition: xv_compile.c:69
void wpips_file_view(char *file_name, char *title_module_name, char *title_label, char *icon_name, char *icon_title)
Display a file in a wpips or epips window:
Definition: xv_edit2.c:277
void enable_menu_item(Menu_item item)
Definition: xv_edit2.c:565
void disable_menu_item(Menu_item item)
Definition: xv_edit2.c:558