PIPS
gtk_compile.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gtk_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 
28 #include <stdlib.h>
29 #include <stdio.h>
30 
31 #include "genC.h"
32 #include "linear.h"
33 #include "ri.h"
34 #include "ri-util.h"
35 #include "misc.h"
36 #include "phases.h"
37 #include "database.h"
38 #include "pipsdbm.h"
39 #include "pipsmake.h"
40 #include "top-level.h"
41 #include "preprocessor.h"
42 
43 // imports gtk
44 #undef test_undefined // also defined in glib included from gtk
45 #include <gtk/gtk.h>
46 #include "gpips.h"
47 
48 #define HPFC_COMPILE "Compile an HPF program"
49 #define HPFC_MAKE "Make an HPF program"
50 #define HPFC_RUN "Run an HPF program"
51 
52 static GtkWidget *compile_menu, *compile_menu_item;
55 
56 void apply_on_each_compile_item(void(* function_to_apply_on_each_menu_item)(
57  GtkWidget *)) {
58  guint i;
59 
60  GtkWidget * child;
61  GList * compile_menu_children = gtk_container_get_children(GTK_CONTAINER(
62  compile_menu));
63  for (i = 0; i < g_list_length(compile_menu_children); i++) {
64  child = (GtkWidget *) g_list_nth_data(compile_menu_children, i);
65  if (!GTK_IS_MENU_ITEM(child))
66  continue;
67  if (GTK_IS_SEPARATOR(child))
68  continue;
69  function_to_apply_on_each_menu_item(child);
70  }
71  g_list_free(compile_menu_children);
72 }
73 
76 }
77 
80 }
81 
82 void notify_hpfc_file_view(GtkWidget * widget, gpointer data) {
83  const char * file_name = gpips_gtk_menu_item_get_label(widget);
85 
86  (void) alloc_first_initialized_window(FALSE);
87 
88  gpips_file_view(path_name, file_name, "HPFC File", "HPFC", "HPFC");
89  user_log("HPFC View of \"%s\" done.\n", file_name);
90 }
91 
92 void generate_a_menu_with_HPF_output_files(GtkWidget * widget, gpointer data) {
93  guint i;
94  GtkWidget * menu_item;
95 
96  gen_array_t file_names = gen_array_make(0);
97  int file_number = 0;
98 
99  int return_code;
100  char *hpfc_directory;
101 
102  /* Create a new menu with the content of the hpfc directory: */
103 
104  if (dynamic_hpf_output_files_menu != NULL)
105  /* First, free the old menu if it exist: */
106  /* We can remove all the menu it now: */
107  gtk_menu_item_remove_submenu(GTK_MENU_ITEM(
109 
110  return_code = hpfc_get_file_list(file_names, &hpfc_directory);
111 
112  dynamic_hpf_output_files_menu = gtk_menu_new();
113 
114  if (return_code == -1) {
115  user_warning("generate_a_menu_with_HPF_output_files",
116  "Directory \"%s\" not found... \n"
117  " Have you run the HPFC compiler from the Compile menu?\n",
118  hpfc_directory);
119 
120  menu_item = gtk_menu_item_new_with_label(
121  "*** No HPFC directory found ! ***");
122  gtk_menu_shell_append(GTK_MENU_SHELL(dynamic_hpf_output_files_menu),
123  menu_item);
124  } else if (file_number == 0) {
125  user_warning("generate_a_menu_with_HPF_output_files",
126  "No file found in the directory \"%s\"... \n"
127  " Have you run the HPFC compiler from the Compile menu?\n",
128  hpfc_directory);
129 
130  menu_item
131  = gtk_menu_item_new_with_label("*** No HPFC file found ! ***");
132  gtk_menu_shell_append(GTK_MENU_SHELL(dynamic_hpf_output_files_menu),
133  menu_item);
134  } else {
135  for (i = 0; i < file_number; i++) {
136  menu_item = gtk_menu_item_new_with_label(gen_array_item(file_names,
137  i));
138  gtk_menu_append(GTK_MENU(dynamic_hpf_output_files_menu), menu_item);
139  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(
140  notify_hpfc_file_view), NULL);
141  }
142 
143  gen_array_full_free(file_names);
144  }
145  gtk_menu_item_set_submenu(
146  GTK_MENU_ITEM(dynamic_hpf_output_files_menu_item),
148 }
149 
150 /* quick fix around pipsmake, FC, 23/10/95
151  */
153 
156 }
157 
158 void hpfc_notify(GtkWidget * menu_item, gpointer data) {
159  const char *label;
160  char *modulename;
161 
162  modulename = db_get_current_module_name();
163  if (!modulename) {
164  prompt_user("No module selected");
165  return;
166  }
167 
168  label = gpips_gtk_menu_item_get_label(menu_item);
169 
170  /* I apply the installation only once, whatever...
171  * Quick fix because the right dependences expressed for pipsmake
172  * do not seem to work. It seems that the verification of up to date
173  * resources is too clever... FC.
174  */
176  safe_apply(BUILDER_HPFC_INSTALL, modulename);
178  }
179 
180  if (same_string_p(label, HPFC_COMPILE))
181  ;
182  else if (same_string_p(label, HPFC_MAKE))
183  safe_apply_outside_the_notifyer(BUILDER_HPFC_MAKE, modulename);
184  else if (same_string_p(label, HPFC_RUN))
185  safe_apply_outside_the_notifyer(BUILDER_HPFC_RUN, modulename);
186  else
187  pips_internal_error("Bad choice: %s", label);
188 }
189 
191  GtkWidget *hpfc_compile_menu_item, *hpfc_make_menu_item,
192  *hpfc_run_menu_item;
193 
194  compile_menu = gtk_menu_new();
195 
196  hpfc_compile_menu_item = gtk_menu_item_new_with_label(HPFC_COMPILE);
197  hpfc_make_menu_item = gtk_menu_item_new_with_label(HPFC_MAKE);
198  hpfc_run_menu_item = gtk_menu_item_new_with_label(HPFC_RUN);
199 
200  g_signal_connect(G_OBJECT(hpfc_compile_menu_item), "activate",
201  G_CALLBACK(hpfc_notify), NULL);
202  g_signal_connect(G_OBJECT(hpfc_make_menu_item), "activate",
203  G_CALLBACK(hpfc_notify), NULL);
204  g_signal_connect(G_OBJECT(hpfc_run_menu_item), "activate",
205  G_CALLBACK(hpfc_notify), NULL);
206 
207  gtk_menu_shell_append(GTK_MENU_SHELL(compile_menu), hpfc_compile_menu_item);
208  gtk_menu_shell_append(GTK_MENU_SHELL(compile_menu), hpfc_make_menu_item);
209  gtk_menu_shell_append(GTK_MENU_SHELL(compile_menu), hpfc_run_menu_item);
210  gtk_menu_shell_append(GTK_MENU_SHELL(compile_menu),
211  gtk_separator_menu_item_new());
212 
213  dynamic_hpf_output_files_menu = gtk_menu_new();
214  dynamic_hpf_output_files_menu_item = gtk_menu_item_new_with_label(
215  "View the HPF Compiler Output");
216  gtk_menu_item_set_submenu(
217  GTK_MENU_ITEM(dynamic_hpf_output_files_menu_item),
219 
220  gtk_menu_shell_append(GTK_MENU_SHELL(compile_menu),
222  // each time the menu is accessed, it is regenerated
223  g_signal_connect(G_OBJECT(dynamic_hpf_output_files_menu_item), "activate",
224  G_CALLBACK(generate_a_menu_with_HPF_output_files), NULL);
225 
226  compile_menu_item = gtk_menu_item_new_with_label("Compile");
227  gtk_menu_item_set_submenu(GTK_MENU_ITEM(compile_menu_item), compile_menu);
228 
229  gtk_menu_bar_append(GTK_MENU_BAR(main_window_menu_bar), compile_menu_item);
230  gtk_widget_show(compile_menu_item);
231  gtk_widget_show_all(compile_menu);
232 }
233 
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
GtkWidget * main_window_menu_bar
Definition: gpips.c:62
#define HPFC_COMPILE
Definition: gtk_compile.c:48
#define HPFC_RUN
Definition: gtk_compile.c:50
void notify_hpfc_file_view(GtkWidget *widget, gpointer data)
Definition: gtk_compile.c:82
static GtkWidget * compile_menu_item
Definition: gtk_compile.c:52
static GtkWidget * dynamic_hpf_output_files_menu
Definition: gtk_compile.c:53
static GtkWidget * dynamic_hpf_output_files_menu_item
Definition: gtk_compile.c:54
void disable_compile_selection()
Definition: gtk_compile.c:74
void generate_a_menu_with_HPF_output_files(GtkWidget *widget, gpointer data)
Definition: gtk_compile.c:92
void apply_on_each_compile_item(void(*function_to_apply_on_each_menu_item)(GtkWidget *))
Definition: gtk_compile.c:56
void hpfc_notify(GtkWidget *menu_item, gpointer data)
Definition: gtk_compile.c:158
void create_compile_menu()
Definition: gtk_compile.c:190
static GtkWidget * compile_menu
Definition: gtk_compile.c:52
void initialize_gpips_hpfc_hack_for_fabien_and_from_fabien()
Definition: gtk_compile.c:154
static bool gpips_hpfc_install_was_performed_hack
quick fix around pipsmake, FC, 23/10/95
Definition: gtk_compile.c:152
#define HPFC_MAKE
Definition: gtk_compile.c:49
void enable_compile_selection()
Definition: gtk_compile.c:78
int alloc_first_initialized_window(bool the_same_as_previous)
Find the first free window if any.
Definition: gtk_edit2.c:215
void gpips_file_view(char *file_name, const char *title_module_name, char *title_label, char *icon_name, char *icon_title)
Display a file in a gpips window:
Definition: gtk_edit2.c:271
void disable_item(GtkWidget *item)
Definition: gtk_edit2.c:461
void enable_item(GtkWidget *item)
Definition: gtk_edit2.c:465
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)
const char * gpips_gtk_menu_item_get_label(GtkWidget *w)
Definition: gtk_utils.c:43
#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
static string file_name