1
0
mirror of https://github.com/cclassic/model-ghdl synced 2025-04-21 02:14:46 +02:00

Compare commits

...

11 Commits

Author SHA1 Message Date
55bf73e52d Use append_string for files
The old "manual" method missed zeroing the string before
the first use, thus creating random garbage before the
file names.
2018-01-21 14:14:47 +01:00
ef6c65d20d Add missing cast to GTK_WINDOW 2018-01-21 14:12:06 +01:00
55105018aa Refactor indentation 2018-01-21 14:11:41 +01:00
bccb210a8f Use gtk_window_present to show dialogs on top 2017-10-01 15:35:53 +02:00
Markus Koch
fad1f6433c Changed versioning to include nth commit instead of only commit hash 2016-06-04 16:30:19 +02:00
Markus Koch
964e9fd055 Bugfix in version detection 2016-06-04 16:28:59 +02:00
Markus Koch
cee0976240 Added wrapper function for debugging 2016-05-30 19:49:16 +02:00
Markus Koch
fde1671c08 Bugfix preventing detection of program when called from PATH 2016-05-30 19:42:53 +02:00
Markus Koch
7a8226f44d Added Arch Linux PKGBUILD 2016-05-30 19:15:30 +02:00
Markus Koch
8c5bdd7c60 Added installation instructions to CMakeLists 2016-05-30 17:59:47 +02:00
Markus Koch
d0c20c6e01 Changed default compilation method to compile-on-vcom. See README.MD on how to revert to syntax-check-only behavior. 2016-05-22 11:26:16 +02:00
7 changed files with 556 additions and 488 deletions

View File

@ -22,3 +22,6 @@ add_custom_command(
COMMAND ln -sf ${PROJECT_NAME} vdel COMMAND ln -sf ${PROJECT_NAME} vdel
COMMAND ln -sf ${PROJECT_NAME} vlib COMMAND ln -sf ${PROJECT_NAME} vlib
) )
install (TARGETS model-ghdl DESTINATION bin)
install (FILES vsim vcom vmap vdel vlib DESTINATION bin)

View File

@ -24,6 +24,7 @@ VCOM
### Additional commands ### Additional commands
* -ghdl *param*: Supply these arguments directly to GHDL (can be used multiple times) * -ghdl *param*: Supply these arguments directly to GHDL (can be used multiple times)
* -no-precompile: Compile the files not until calling vsim. (Faster syntax check, but longer wait time for the simulation to start.)
### Notes ### Notes
* *cwd* is expected to be the compile directory * *cwd* is expected to be the compile directory

35
arch/PKGBUILD Normal file
View File

@ -0,0 +1,35 @@
# Maintainer: Markus Koch <CClassicVideos@aol.com>
pkgname=model-ghdl
pkgver=59.cee0976
pkgrel=1
pkgdesc='A wrapper for ghdl to make it look like modelsim.'
arch=('i686' 'x86_64')
url='https://github.com/cclassic/model-ghdl'
license=('GPL')
depends=('gtk3')
makedepends=('cmake' 'git')
source=("model-ghdl::git://github.com/cclassic/model-ghdl.git")
sha1sums=('SKIP')
pkgver() {
cd "$srcdir/model-ghdl"
echo -n $(git log|grep -e ^commit|wc -l).
echo $(git log | head -n 1 | sed "s/.* //g" | head -c 7)
}
build() {
cd "$srcdir/model-ghdl"
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .
#-DCMAKE_C_FLAGS=-DPROGRAM_REVISION="#${pkgver}";
make
}
package() {
cd "$srcdir/model-ghdl"
make DESTDIR="${pkgdir}" install
}

12
arch/README.md Normal file
View File

@ -0,0 +1,12 @@
Arch Linux Build Script
=======================
This directory contains the PKGBUILD required to compile binary distribution packages for Arch Linux.
Build instructions
------------------
On Arch, simply enter
```
$ makepkg -s
# pacman -U model-ghdl-xxxxxxx-1-arch.pkg.tar.xz
```
to install the program.

8
gui.c
View File

@ -67,7 +67,7 @@ int showMessage(int message_type, char *text, char *defaultText, char **reply) {
gtk_container_add(GTK_CONTAINER(window), mainBox); gtk_container_add(GTK_CONTAINER(window), mainBox);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 320, 10); gtk_window_set_default_size(GTK_WINDOW(window), 320, 10);
gtk_widget_show (window); gtk_window_present(GTK_WINDOW(window));
gtk_main(); gtk_main();
@ -88,15 +88,13 @@ int showMessage(int message_type, char *text, char *defaultText, char **reply) {
return ret; return ret;
} }
static void okay( GtkWidget *widget, static void okay(GtkWidget *widget, gpointer data)
gpointer data )
{ {
//g_print ("TEXT = %s\n", gtk_entry_get_text(GTK_ENTRY(data))); //g_print ("TEXT = %s\n", gtk_entry_get_text(GTK_ENTRY(data)));
gtk_main_quit(); gtk_main_quit();
} }
static void cancel( GtkWidget *widget, static void cancel(GtkWidget *widget, gpointer data)
gpointer data )
{ {
gtk_entry_set_text(GTK_ENTRY(data), ""); gtk_entry_set_text(GTK_ENTRY(data), "");
gtk_main_quit(); gtk_main_quit();

4
gui.h
View File

@ -13,7 +13,7 @@ int gui_init(int *argc, char ***argv);
int showMessage(int message_type, char *text, char *defaultText, char **reply); int showMessage(int message_type, char *text, char *defaultText, char **reply);
// Slots // Slots
static void okay( GtkWidget *widget, gpointer data ); static void okay(GtkWidget *widget, gpointer data);
static void cancel ( GtkWidget *widget, gpointer data ); static void cancel(GtkWidget *widget, gpointer data);
#endif // GUI_H #endif // GUI_H

57
main.c
View File

@ -8,6 +8,8 @@
#define PROGRAM_REVISION "#unknown" #define PROGRAM_REVISION "#unknown"
#endif #endif
//#define DEBUG_ENABLED DEBUG_ENABLED
#define PROG_VCOM 0 #define PROG_VCOM 0
#define PROG_VSIM 1 #define PROG_VSIM 1
#define PROG_VLIB 2 #define PROG_VLIB 2
@ -22,7 +24,7 @@
#define ISOPT(cmd) (strcmp(argv[i], cmd) == 0) #define ISOPT(cmd) (strcmp(argv[i], cmd) == 0)
#define GETOPT(cmd) (strcmp(argv[i], cmd) == 0) && (++i < argc) #define GETOPT(cmd) (strcmp(argv[i], cmd) == 0) && (++i < argc)
const char *laststrstr (const char *__haystack, const char *__needle); const char *getAfter (const char *__haystack, const char *__needle);
int get_application(const char *call); int get_application(const char *call);
int vsim(int argc, char **argv); int vsim(int argc, char **argv);
int vcom(int argc, char **argv); int vcom(int argc, char **argv);
@ -31,6 +33,18 @@ int run_simulation(char *command, ...);
int run_gtkwave(char *toplevel, char *command, ...); int run_gtkwave(char *toplevel, char *command, ...);
char* append_string(char **dest, const char *src); char* append_string(char **dest, const char *src);
pid_t system2(const char * command, int * infp, int * outfp); pid_t system2(const char * command, int * infp, int * outfp);
void debug( const char* format, ... );
void debug( const char* format, ... ) {
#ifdef DEBUG_ENABLED
va_list args;
// fprintf( stderr, "[D] " );
va_start( args, format );
vfprintf( stderr, format, args );
va_end( args );
// fprintf( stderr, "\n" );
#endif
}
// Thanks GreenScape // Thanks GreenScape
// http://stackoverflow.com/questions/22802902/how-to-get-pid-of-process-executed-with-system-command-in-c // http://stackoverflow.com/questions/22802902/how-to-get-pid-of-process-executed-with-system-command-in-c
@ -89,7 +103,7 @@ int run_ghdl(char *command, ...) {
vsprintf(cmd, command, argptr); vsprintf(cmd, command, argptr);
va_end(argptr); va_end(argptr);
//printf("RUN_GHDL: %s\n", cmd); debug("RUN_GHDL: %s\n", cmd);
proc = popen(cmd, "r"); proc = popen(cmd, "r");
if (proc == NULL) { if (proc == NULL) {
@ -162,7 +176,7 @@ int run_simulation(char *command, ...) {
vsprintf(cmd, command, argptr); vsprintf(cmd, command, argptr);
va_end(argptr); va_end(argptr);
//printf("RUN_SIM: %s\n", cmd); debug("RUN_SIM: %s\n", cmd);
proc = popen(cmd, "r"); proc = popen(cmd, "r");
if (proc == NULL) { if (proc == NULL) {
@ -209,10 +223,10 @@ int run_gtkwave(char *toplevel, char *command, ...) {
vsprintf(cmd, command, argptr); vsprintf(cmd, command, argptr);
va_end(argptr); va_end(argptr);
//printf("RUN_SIM: %s\n", cmd); debug("RUN_GTKWAVE: %s\n", cmd);
pid = system2(cmd, NULL, NULL); pid = system2(cmd, NULL, NULL);
//printf("--> PID=%d\n", pid); //debug("--> PID=%d\n", pid);
// Prevent gtkw from starting again each time // Prevent gtkw from starting again each time
fp = fopen(lockpath,"w"); fp = fopen(lockpath,"w");
@ -247,7 +261,7 @@ int vsim(int argc, char **argv)
char *simExt = NULL; char *simExt = NULL;
char *outFileType = NULL; char *outFileType = NULL;
char vhdlver[16] = ""; char vhdlver[16] = "";
int precompiled = 1;
FILE *fp; FILE *fp;
append_string(&params,""); append_string(&params,"");
@ -271,6 +285,9 @@ int vsim(int argc, char **argv)
fp = fopen("/tmp/model-ghdl-vcom","r"); fp = fopen("/tmp/model-ghdl-vcom","r");
if (fp) { if (fp) {
fgets(workdir, sizeof(workdir), fp); // (ab)use workdir variable as temp
if (!strcmp(workdir,"nopre\n"))
precompiled = 0;
fgets(workdir, sizeof(workdir), fp); fgets(workdir, sizeof(workdir), fp);
workdir[strlen(workdir)-1] = 0; workdir[strlen(workdir)-1] = 0;
fgets(vhdlver, sizeof(vhdlver), fp); fgets(vhdlver, sizeof(vhdlver), fp);
@ -344,7 +361,7 @@ int vsim(int argc, char **argv)
} }
printf("[I] Compiling...\n"); printf("[I] Compiling...\n");
if (run_ghdl("ghdl -m %s --work=%s --workdir=\"%s\" %s %s", vhdlver, work, workdir, params, toplevel)) { if (run_ghdl("ghdl -%c %s --work=%s --workdir=\"%s\" %s %s", (precompiled ? 'e' : 'm'), vhdlver, work, workdir, params, toplevel)) {
fprintf(stderr, "[E] Compilation failed!"); fprintf(stderr, "[E] Compilation failed!");
showMessage(MESSAGE_ERROR, "Error! Compilation failed.", NULL, NULL); showMessage(MESSAGE_ERROR, "Error! Compilation failed.", NULL, NULL);
} }
@ -383,13 +400,13 @@ int vsim(int argc, char **argv)
int vcom(int argc, char **argv) int vcom(int argc, char **argv)
{ {
int i; int i;
int slen = 0;
char workdir[1 K]; char workdir[1 K];
char *params = NULL; char *params = NULL;
char *work = NULL; char *work = NULL;
char *files = NULL; char *files = NULL;
char vhdlver[16] = ""; char vhdlver[16] = "";
FILE *fp = NULL; FILE *fp = NULL;
int precompile = 1;
printf ("[I] Emulating vcom.\n"); printf ("[I] Emulating vcom.\n");
@ -423,15 +440,16 @@ int vcom(int argc, char **argv)
else if (ISOPT("-2008")) { else if (ISOPT("-2008")) {
strcpy(vhdlver, "--std=08"); strcpy(vhdlver, "--std=08");
} }
else if (ISOPT("-no-precompile")) {
precompile = 0;
}
else if (GETOPT("-ghdl")) { else if (GETOPT("-ghdl")) {
append_string(&params, " "); append_string(&params, " ");
append_string(&params, argv[i]); append_string(&params, argv[i]);
} }
else if (argv[i][0] != '-'){ // VHDL file else if (argv[i][0] != '-'){ // VHDL file
slen += strlen(argv[i]) + 2; append_string(&files, " ");
files = realloc(files, slen * sizeof(char)); append_string(&files, argv[i]);
strcat(files, " ");
strcat(files, argv[i]);
} }
} }
@ -448,7 +466,7 @@ int vcom(int argc, char **argv)
// Info for vsim later on // Info for vsim later on
fp = fopen("/tmp/model-ghdl-vcom","w"); fp = fopen("/tmp/model-ghdl-vcom","w");
if (fp) { if (fp) {
fprintf(fp, "%s\n%s", workdir, vhdlver); fprintf(fp, "%s\n%s\n%s", (precompile ? "pre" : "nopre"), workdir, vhdlver);
fclose(fp); fclose(fp);
} }
else { else {
@ -457,9 +475,8 @@ int vcom(int argc, char **argv)
run_ghdl("ghdl -i --work=%s --workdir=%s %s %s %s 2>&1", run_ghdl("ghdl -i --work=%s --workdir=%s %s %s %s 2>&1",
work, workdir, vhdlver, params, files); work, workdir, vhdlver, params, files);
run_ghdl("ghdl -s --work=%s --workdir=%s %s %s %s 2>&1", run_ghdl("ghdl -%c --work=%s --workdir=%s %s %s %s 2>&1",
work, workdir, vhdlver, params, files); (precompile ? 'a' : 's'), work, workdir, vhdlver, params, files);
free(files); free(files);
@ -504,7 +521,7 @@ int main(int argc, char **argv)
// Detects which function to call depending on the program name in argv[0] // Detects which function to call depending on the program name in argv[0]
int get_application(const char *call) { int get_application(const char *call) {
char *pos; char *pos;
pos = (char*) laststrstr(call, "/") + 1; pos = (char*) getAfter(call, "/");
if (strcmp(pos, "vcom") == 0) { if (strcmp(pos, "vcom") == 0) {
return PROG_VCOM; return PROG_VCOM;
} }
@ -527,14 +544,16 @@ int get_application(const char *call) {
} }
// Returns the string after the last occurence of __needle // Returns the string after the last occurence of __needle
const char *laststrstr (const char *__haystack, const char *__needle) { const char *getAfter (const char *__haystack, const char *__needle) {
char *pos, *realPos; char *pos, *realPos;
char *haystack; char *haystack;
haystack = (char*) __haystack; haystack = (char*) __haystack;
pos = (char*) __haystack; pos = (char*) __haystack;
while (pos != NULL) { while (pos != NULL) {
realPos = pos; realPos = pos + 1;
pos = strstr(haystack, __needle); pos = strstr(haystack, __needle);
if (haystack == __haystack && pos == NULL) // If no __needle is present at all...
realPos = (char*) __haystack; // Return the entire string
haystack = pos + 1; haystack = pos + 1;
} }
return realPos; return realPos;