mirror of
https://github.com/cclassic/model-ghdl
synced 2025-04-21 02:14:46 +02:00
Compare commits
11 Commits
v0.1-alpha
...
master
Author | SHA1 | Date | |
---|---|---|---|
55bf73e52d | |||
ef6c65d20d | |||
55105018aa | |||
bccb210a8f | |||
![]() |
fad1f6433c | ||
![]() |
964e9fd055 | ||
![]() |
cee0976240 | ||
![]() |
fde1671c08 | ||
![]() |
7a8226f44d | ||
![]() |
8c5bdd7c60 | ||
![]() |
d0c20c6e01 |
@ -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)
|
||||||
|
@ -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
35
arch/PKGBUILD
Normal 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
12
arch/README.md
Normal 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
8
gui.c
@ -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();
|
||||||
|
57
main.c
57
main.c
@ -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(¶ms,"");
|
append_string(¶ms,"");
|
||||||
@ -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(¶ms, " ");
|
append_string(¶ms, " ");
|
||||||
append_string(¶ms, argv[i]);
|
append_string(¶ms, 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user