1
0
mirror of https://github.com/cclassic/model-ghdl synced 2025-07-04 11:35:30 +02:00

Compare commits

..

No commits in common. "master" and "v0.1-alpha" have entirely different histories.

7 changed files with 488 additions and 556 deletions

View File

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

View File

@ -24,7 +24,6 @@ VCOM
### Additional commands
* -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
* *cwd* is expected to be the compile directory

View File

@ -1,35 +0,0 @@
# 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
}

View File

@ -1,12 +0,0 @@
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_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 320, 10);
gtk_window_present(GTK_WINDOW(window));
gtk_widget_show (window);
gtk_main();
@ -88,13 +88,15 @@ int showMessage(int message_type, char *text, char *defaultText, char **reply) {
return ret;
}
static void okay(GtkWidget *widget, gpointer data)
static void okay( GtkWidget *widget,
gpointer data )
{
//g_print ("TEXT = %s\n", gtk_entry_get_text(GTK_ENTRY(data)));
gtk_main_quit();
}
static void cancel(GtkWidget *widget, gpointer data)
static void cancel( GtkWidget *widget,
gpointer data )
{
gtk_entry_set_text(GTK_ENTRY(data), "");
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);
// Slots
static void okay(GtkWidget *widget, gpointer data);
static void cancel(GtkWidget *widget, gpointer data);
static void okay( GtkWidget *widget, gpointer data );
static void cancel ( GtkWidget *widget, gpointer data );
#endif // GUI_H

57
main.c
View File

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