1
0
mirror of https://github.com/cclassic/model-ghdl synced 2024-11-13 07:35:06 +01:00

Invoked compiler, simtime and error dialog

This commit is contained in:
Markus Koch 2015-10-23 20:47:21 +02:00
parent 5c4b51a3ae
commit cc44efb787
3 changed files with 123 additions and 28 deletions

51
gui.c
View File

@ -19,7 +19,7 @@ int showMessage(int message_type, char *text, char *defaultText, char **reply) {
char *entryText;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Meow");
gtk_window_set_title(GTK_WINDOW(window), "model-ghdl");
label = gtk_label_new(text);
gtk_widget_show(label);
@ -28,45 +28,58 @@ int showMessage(int message_type, char *text, char *defaultText, char **reply) {
gtk_entry_set_text(GTK_ENTRY(entry), (char*) defaultText);
g_signal_connect (entry, "activate",
G_CALLBACK(okay), entry);
gtk_widget_show(entry);
buttonOkay = gtk_button_new_with_label("Okay!");
gtk_widget_show(buttonOkay);
buttonCancel = gtk_button_new_with_label("Cancel");
gtk_widget_show(buttonCancel);
if (MESSAGE_IS_INPUT(message_type)) {
buttonCancel = gtk_button_new_with_label("Cancel");
g_signal_connect (buttonCancel, "clicked",
G_CALLBACK(cancel), entry);
gtk_widget_show(buttonCancel);
gtk_widget_show(entry);
}
buttonBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_pack_start(GTK_BOX(buttonBox), buttonCancel, true, true, 0);
if (MESSAGE_IS_INPUT(message_type)) {
gtk_box_pack_start(GTK_BOX(buttonBox), buttonCancel, true, true, 0);
}
gtk_box_pack_start(GTK_BOX(buttonBox), buttonOkay, true, true, 0);
g_signal_connect (buttonOkay, "clicked",
G_CALLBACK(okay), entry);
gtk_widget_show(buttonBox);
mainBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
gtk_box_pack_start(GTK_BOX(mainBox), label, true, true, 0);
gtk_box_pack_start(GTK_BOX(mainBox), entry, true, true, 0);
gtk_box_pack_start(GTK_BOX(mainBox), buttonBox, true, true, 0);
gtk_box_pack_start(GTK_BOX(mainBox), label, true, true, 10);
if (MESSAGE_IS_INPUT(message_type)) {
gtk_box_pack_start(GTK_BOX(mainBox), entry, true, true, 0);
}
gtk_box_pack_start(GTK_BOX(mainBox), buttonBox, false, false, 0);
gtk_widget_show(mainBox);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
G_CALLBACK (cancel), NULL);
gtk_container_add(GTK_CONTAINER(window), mainBox);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 320, 10);
gtk_widget_show (window);
gtk_main();
entryText = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
if (entryText[0] == 0) {
return false;
if (MESSAGE_IS_INPUT(message_type)) {
entryText = (char*) gtk_entry_get_text(GTK_ENTRY(entry));
if (entryText[0] == 0) {
return false;
}
else {
*reply = realloc(*reply, sizeof(char)*strlen(entryText));
if (*reply != NULL)
strcpy(*reply, entryText);
return true;
}
}
else {
*reply = realloc(*reply, sizeof(char)*strlen(entryText));
if (*reply != NULL)
strcpy(*reply, entryText);
return true;
}
gtk_widget_destroy(window);
}

6
gui.h
View File

@ -4,10 +4,16 @@
#include <string.h>
#include <stdlib.h>
// #define MESSAGE_INFO 0 // NYI!
#define MESSAGE_ERROR 1
#define MESSAGE_INPUT 32
#define MESSAGE_IS_INPUT(msg) ((msg >= 32) && (msg < 64))
int gui_init(int *argc, char ***argv);
int showMessage(int message_type, char *text, char *defaultText, char **reply);
// Slots
static void okay( GtkWidget *widget, gpointer data );
static void cancel ( GtkWidget *widget, gpointer data );
#endif // GUI_H

94
main.c
View File

@ -89,10 +89,37 @@ int vsim(int argc, char **argv)
int i;
char *ptr = NULL;
char *lastPtr;
char workdir[1 K];
char *params = NULL;
char *simtime = NULL;
FILE *fp;
gui_init(&argc, &argv);
fp = fopen("/tmp/model-ghdl-vsim","r");
if (fp) {
fgets(workdir, sizeof(workdir), fp); // lets (ab)use the workdir variable here
append_string(&simtime, workdir);
fclose(fp);
}
else {
append_string(&simtime, "100ns");
}
fp = fopen("/tmp/model-ghdl-vcom","r");
if (fp) {
fgets(workdir, sizeof(workdir), fp);
fclose(fp);
}
else {
printf("[E] Could not read temp file /tmp/model-ghdl-vcom! Aborting...");
}
printf ("[I] Emulating vsim.\n");
// -gui work.toplevel(RTL)
for (i=1; i < argc; ++i) {
if (GETOPT("-gui")) {
if (ptr == NULL && GETOPT("-gui")) { // only allow once
append_string(&ptr, argv[i]);
lastPtr = ptr;
for (; *ptr != 0; ptr++) {
@ -113,17 +140,42 @@ int vsim(int argc, char **argv)
// free(ptr); DO NOT FREE, we still need it.
// ptr = NULL;
}
else if (GETOPT("-ghdl")) {
append_string(&params, " ");
append_string(&params, argv[i]);
}
else {
}
}
chdir(workdir);
printf("Compiling...\n");
if (run_ghdl("ghdl -m --work=%s --workdir=\"%s\" %s %s", work, workdir, params, toplevel)) {
fprintf(stderr, "[E] Compilation failed!");
showMessage(MESSAGE_ERROR, "Error! Compilation failed.", NULL, NULL);
}
else {
if (ret = showMessage(MESSAGE_INPUT, "Enter the simulation time: ", simtime, &text)) {
free(simtime);
simtime = NULL;
append_string(&simtime, text);
fp = fopen("/tmp/model-ghdl-vsim","w");
if (fp) {
fprintf(fp, "%s", simtime);
fclose(fp);
}
printf("Simulating...\n");
// TODO: Exec program
// TODO: Exec GtkWave
}
return 0;
}
// After exec
free(ptr);
free(ptr); // Now we can free it
return 0; // DEBUG
gui_init(&argc, &argv);
ret = showMessage(0, "Enter the simulation time: ", "100 ns", &text);
printf("%d: %p: %s\n", ret, text, text);
return 255;
}
int vcom(int argc, char **argv)
@ -132,9 +184,12 @@ int vcom(int argc, char **argv)
int slen = 0;
char workdir[1 K];
char *params = NULL;
char *work;
char *work = NULL;
char *files = NULL;
char vhdlver[16] = "";
FILE *fp = NULL;
printf ("[I] Emulating vsim.\n");
if (!getcwd(workdir, sizeof(workdir))) { // Default compile dir is cwd
fprintf(stderr, "Error: Could not invoke GHDL!\n");
@ -179,14 +234,34 @@ int vcom(int argc, char **argv)
if (!params)
append_string(&params, "");
if (!work)
append_string(&work, "work");
if (!files) {
fprintf(stderr, "[E] No input files specified.\n");
return 2;
}
// Info for vsim later on
fp = fopen("/tmp/model-ghdl-vcom","w");
if (fp) {
fprintf(fp, "%s", workdir);
fclose(fp);
}
else {
printf("Could not create temp file /tmp/model-ghdl-vcom! Ignoring...");
}
run_ghdl("ghdl -i --work=%s --workdir=%s %s %s %s 2>&1",
work, workdir, vhdlver, files, params);
run_ghdl("ghdl -s --work=%s --workdir=%s %s %s %s 2>&1",
work, workdir, vhdlver, files, params);
free(files);
printf("DONE.\n");
return 0;
}
@ -208,6 +283,7 @@ char* append_string(char **dest, const char *src) {
int main(int argc, char **argv)
{
int app;
printf ("model-ghdl revision %s, compiled on %s.\n", PROGRAM_REVISION, __DATE__);
app = get_application(argv[0]);
@ -233,7 +309,7 @@ int get_application(const char *call) {
return PROG_VCOM;
}
else if (strcmp(pos, "vsim") == 0) {
return PROG_VCOM;
return PROG_VSIM;
}
else if (strcmp(pos, "vlib") == 0) {
return PROG_VLIB;