mirror of https://github.com/YosysHQ/yosys.git
Merge pull request #454 from rqou/emscripten-and-abc
Add option to statically link abc; emscripten fixes
This commit is contained in:
commit
a5f4b44745
49
Makefile
49
Makefile
|
@ -22,6 +22,9 @@ ENABLE_DEBUG := 0
|
||||||
ENABLE_NDEBUG := 0
|
ENABLE_NDEBUG := 0
|
||||||
LINK_CURSES := 0
|
LINK_CURSES := 0
|
||||||
LINK_TERMCAP := 0
|
LINK_TERMCAP := 0
|
||||||
|
LINK_ABC := 0
|
||||||
|
# Needed for environments that don't have proper thread support (i.e. emscripten)
|
||||||
|
DISABLE_ABC_THREADS := 0
|
||||||
|
|
||||||
# clang sanitizers
|
# clang sanitizers
|
||||||
SANITIZER =
|
SANITIZER =
|
||||||
|
@ -126,6 +129,7 @@ ifeq ($(CONFIG),clang)
|
||||||
CXX = clang
|
CXX = clang
|
||||||
LD = clang++
|
LD = clang++
|
||||||
CXXFLAGS += -std=c++11 -Os
|
CXXFLAGS += -std=c++11 -Os
|
||||||
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H"
|
||||||
|
|
||||||
ifneq ($(SANITIZER),)
|
ifneq ($(SANITIZER),)
|
||||||
$(info [Clang Sanitizer] $(SANITIZER))
|
$(info [Clang Sanitizer] $(SANITIZER))
|
||||||
|
@ -148,16 +152,19 @@ else ifeq ($(CONFIG),gcc)
|
||||||
CXX = gcc
|
CXX = gcc
|
||||||
LD = gcc
|
LD = gcc
|
||||||
CXXFLAGS += -std=c++11 -Os
|
CXXFLAGS += -std=c++11 -Os
|
||||||
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H"
|
||||||
|
|
||||||
else ifeq ($(CONFIG),gcc-4.8)
|
else ifeq ($(CONFIG),gcc-4.8)
|
||||||
CXX = gcc-4.8
|
CXX = gcc-4.8
|
||||||
LD = gcc-4.8
|
LD = gcc-4.8
|
||||||
CXXFLAGS += -std=c++11 -Os
|
CXXFLAGS += -std=c++11 -Os
|
||||||
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H"
|
||||||
|
|
||||||
else ifeq ($(CONFIG),emcc)
|
else ifeq ($(CONFIG),emcc)
|
||||||
CXX = emcc
|
CXX = emcc
|
||||||
LD = emcc
|
LD = emcc
|
||||||
CXXFLAGS := -std=c++11 $(filter-out -fPIC -ggdb,$(CXXFLAGS))
|
CXXFLAGS := -std=c++11 $(filter-out -fPIC -ggdb,$(CXXFLAGS))
|
||||||
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H -DABC_MEMALIGN=8"
|
||||||
EMCCFLAGS := -Os -Wno-warn-absolute-paths
|
EMCCFLAGS := -Os -Wno-warn-absolute-paths
|
||||||
EMCCFLAGS += --memory-init-file 0 --embed-file share -s NO_EXIT_RUNTIME=1
|
EMCCFLAGS += --memory-init-file 0 --embed-file share -s NO_EXIT_RUNTIME=1
|
||||||
EMCCFLAGS += -s EXPORTED_FUNCTIONS="['_main','_run','_prompt','_errmsg']"
|
EMCCFLAGS += -s EXPORTED_FUNCTIONS="['_main','_run','_prompt','_errmsg']"
|
||||||
|
@ -171,6 +178,11 @@ EXE = .js
|
||||||
TARGETS := $(filter-out yosys-config,$(TARGETS))
|
TARGETS := $(filter-out yosys-config,$(TARGETS))
|
||||||
EXTRA_TARGETS += yosysjs-$(YOSYS_VER).zip
|
EXTRA_TARGETS += yosysjs-$(YOSYS_VER).zip
|
||||||
|
|
||||||
|
ifeq ($(ENABLE_ABC),1)
|
||||||
|
LINK_ABC := 1
|
||||||
|
DISABLE_ABC_THREADS := 1
|
||||||
|
endif
|
||||||
|
|
||||||
viz.js:
|
viz.js:
|
||||||
wget -O viz.js.part https://github.com/mdaines/viz.js/releases/download/0.0.3/viz.js
|
wget -O viz.js.part https://github.com/mdaines/viz.js/releases/download/0.0.3/viz.js
|
||||||
mv viz.js.part viz.js
|
mv viz.js.part viz.js
|
||||||
|
@ -192,8 +204,8 @@ CXXFLAGS += -std=c++11 -Os -D_POSIX_SOURCE -DYOSYS_MXE_HACKS -Wno-attributes
|
||||||
CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS))
|
CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS))
|
||||||
LDFLAGS := $(filter-out -rdynamic,$(LDFLAGS)) -s
|
LDFLAGS := $(filter-out -rdynamic,$(LDFLAGS)) -s
|
||||||
LDLIBS := $(filter-out -lrt,$(LDLIBS))
|
LDLIBS := $(filter-out -lrt,$(LDLIBS))
|
||||||
ABCMKARGS += ARCHFLAGS="-DSIZEOF_VOID_P=4 -DSIZEOF_LONG=4 -DSIZEOF_INT=4 -DWIN32_NO_DLL -DHAVE_STRUCT_TIMESPEC -fpermissive -w"
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H -DWIN32_NO_DLL -DHAVE_STRUCT_TIMESPEC -fpermissive -w"
|
||||||
ABCMKARGS += LIBS="lib/x86/pthreadVC2.lib -s" ABC_USE_NO_READLINE=1 CC="$(CXX)" CXX="$(CXX)"
|
ABCMKARGS += LIBS="lib/x86/pthreadVC2.lib -s" ABC_USE_NO_READLINE=1
|
||||||
EXE = .exe
|
EXE = .exe
|
||||||
|
|
||||||
else ifeq ($(CONFIG),msys2)
|
else ifeq ($(CONFIG),msys2)
|
||||||
|
@ -203,8 +215,8 @@ CXXFLAGS += -std=c++11 -Os -D_POSIX_SOURCE -DYOSYS_WIN32_UNIX_DIR
|
||||||
CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS))
|
CXXFLAGS := $(filter-out -fPIC,$(CXXFLAGS))
|
||||||
LDFLAGS := $(filter-out -rdynamic,$(LDFLAGS)) -s
|
LDFLAGS := $(filter-out -rdynamic,$(LDFLAGS)) -s
|
||||||
LDLIBS := $(filter-out -lrt,$(LDLIBS))
|
LDLIBS := $(filter-out -lrt,$(LDLIBS))
|
||||||
ABCMKARGS += ARCHFLAGS="-DSIZEOF_VOID_P=4 -DSIZEOF_LONG=4 -DSIZEOF_INT=4 -DWIN32_NO_DLL -DHAVE_STRUCT_TIMESPEC -fpermissive -w"
|
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H -DWIN32_NO_DLL -DHAVE_STRUCT_TIMESPEC -fpermissive -w"
|
||||||
ABCMKARGS += LIBS="lib/x86/pthreadVC2.lib -s" ABC_USE_NO_READLINE=0 CC="i686-w64-mingw32-gcc" CXX="$(CXX)"
|
ABCMKARGS += LIBS="lib/x86/pthreadVC2.lib -s" ABC_USE_NO_READLINE=0
|
||||||
EXE = .exe
|
EXE = .exe
|
||||||
|
|
||||||
else ifneq ($(CONFIG),none)
|
else ifneq ($(CONFIG),none)
|
||||||
|
@ -236,9 +248,15 @@ else
|
||||||
ifeq ($(ENABLE_EDITLINE),1)
|
ifeq ($(ENABLE_EDITLINE),1)
|
||||||
CXXFLAGS += -DYOSYS_ENABLE_EDITLINE
|
CXXFLAGS += -DYOSYS_ENABLE_EDITLINE
|
||||||
LDLIBS += -ledit -ltinfo -lbsd
|
LDLIBS += -ledit -ltinfo -lbsd
|
||||||
|
else
|
||||||
|
ABCMKARGS += "ABC_USE_NO_READLINE=1"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DISABLE_ABC_THREADS),1)
|
||||||
|
ABCMKARGS += "ABC_USE_NO_PTHREADS=1"
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(ENABLE_PLUGINS),1)
|
ifeq ($(ENABLE_PLUGINS),1)
|
||||||
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --cflags libffi) -DYOSYS_ENABLE_PLUGINS
|
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --cflags libffi) -DYOSYS_ENABLE_PLUGINS
|
||||||
LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --libs libffi || echo -lffi)
|
LDLIBS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --silence-errors --libs libffi || echo -lffi)
|
||||||
|
@ -288,10 +306,17 @@ endif
|
||||||
|
|
||||||
ifeq ($(ENABLE_ABC),1)
|
ifeq ($(ENABLE_ABC),1)
|
||||||
CXXFLAGS += -DYOSYS_ENABLE_ABC
|
CXXFLAGS += -DYOSYS_ENABLE_ABC
|
||||||
|
ifeq ($(LINK_ABC),1)
|
||||||
|
CXXFLAGS += -DYOSYS_LINK_ABC
|
||||||
|
ifeq ($(DISABLE_ABC_THREADS),0)
|
||||||
|
LDLIBS += -lpthread
|
||||||
|
endif
|
||||||
|
else
|
||||||
ifeq ($(ABCEXTERNAL),)
|
ifeq ($(ABCEXTERNAL),)
|
||||||
TARGETS += yosys-abc$(EXE)
|
TARGETS += yosys-abc$(EXE)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(ENABLE_VERIFIC),1)
|
ifeq ($(ENABLE_VERIFIC),1)
|
||||||
VERIFIC_DIR ?= /usr/local/src/verific_lib_eval
|
VERIFIC_DIR ?= /usr/local/src/verific_lib_eval
|
||||||
|
@ -411,6 +436,10 @@ include techlibs/common/Makefile.inc
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(LINK_ABC),1)
|
||||||
|
OBJS += yosys-libabc.a
|
||||||
|
endif
|
||||||
|
|
||||||
top-all: $(TARGETS) $(EXTRA_TARGETS)
|
top-all: $(TARGETS) $(EXTRA_TARGETS)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo " Build successful."
|
@echo " Build successful."
|
||||||
|
@ -455,7 +484,7 @@ yosys-config: misc/yosys-config.in
|
||||||
-e 's#@BINDIR@#$(strip $(BINDIR))#;' -e 's#@DATDIR@#$(strip $(DATDIR))#;' < $< > yosys-config
|
-e 's#@BINDIR@#$(strip $(BINDIR))#;' -e 's#@DATDIR@#$(strip $(DATDIR))#;' < $< > yosys-config
|
||||||
$(Q) chmod +x yosys-config
|
$(Q) chmod +x yosys-config
|
||||||
|
|
||||||
abc/abc-$(ABCREV)$(EXE):
|
abc/abc-$(ABCREV)$(EXE) abc/libabc-$(ABCREV).a:
|
||||||
$(P)
|
$(P)
|
||||||
ifneq ($(ABCREV),default)
|
ifneq ($(ABCREV),default)
|
||||||
$(Q) if test -d abc/.hg; then \
|
$(Q) if test -d abc/.hg; then \
|
||||||
|
@ -472,15 +501,19 @@ ifneq ($(ABCREV),default)
|
||||||
fi
|
fi
|
||||||
endif
|
endif
|
||||||
$(Q) rm -f abc/abc-[0-9a-f]*
|
$(Q) rm -f abc/abc-[0-9a-f]*
|
||||||
$(Q) cd abc && $(MAKE) $(S) $(ABCMKARGS) PROG="abc-$(ABCREV)$(EXE)" MSG_PREFIX="$(eval P_OFFSET = 5)$(call P_SHOW)$(eval P_OFFSET = 10) ABC: "
|
$(Q) cd abc && $(MAKE) $(S) $(ABCMKARGS) $(if $(filter %.a,$@),PROG="abc-$(ABCREV)",PROG="abc-$(ABCREV)$(EXE)") MSG_PREFIX="$(eval P_OFFSET = 5)$(call P_SHOW)$(eval P_OFFSET = 10) ABC: " $(if $(filter %.a,$@),libabc-$(ABCREV).a)
|
||||||
|
|
||||||
ifeq ($(ABCREV),default)
|
ifeq ($(ABCREV),default)
|
||||||
.PHONY: abc/abc-$(ABCREV)$(EXE)
|
.PHONY: abc/abc-$(ABCREV)$(EXE)
|
||||||
|
.PHONY: abc/libabc-$(ABCREV).a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
yosys-abc$(EXE): abc/abc-$(ABCREV)$(EXE)
|
yosys-abc$(EXE): abc/abc-$(ABCREV)$(EXE)
|
||||||
$(P) cp abc/abc-$(ABCREV)$(EXE) yosys-abc$(EXE)
|
$(P) cp abc/abc-$(ABCREV)$(EXE) yosys-abc$(EXE)
|
||||||
|
|
||||||
|
yosys-libabc.a: abc/libabc-$(ABCREV).a
|
||||||
|
$(P) cp abc/libabc-$(ABCREV).a yosys-libabc.a
|
||||||
|
|
||||||
ifneq ($(SEED),)
|
ifneq ($(SEED),)
|
||||||
SEEDOPT="-S $(SEED)"
|
SEEDOPT="-S $(SEED)"
|
||||||
else
|
else
|
||||||
|
@ -564,7 +597,7 @@ clean:
|
||||||
rm -rf share
|
rm -rf share
|
||||||
if test -d manual; then cd manual && sh clean.sh; fi
|
if test -d manual; then cd manual && sh clean.sh; fi
|
||||||
rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS)
|
rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS)
|
||||||
rm -f kernel/version_*.o kernel/version_*.cc abc/abc-[0-9a-f]*
|
rm -f kernel/version_*.o kernel/version_*.cc abc/abc-[0-9a-f]* abc/libabc-[0-9a-f]*.a
|
||||||
rm -f libs/*/*.d frontends/*/*.d passes/*/*.d backends/*/*.d kernel/*.d techlibs/*/*.d
|
rm -f libs/*/*.d frontends/*/*.d passes/*/*.d backends/*/*.d kernel/*.d techlibs/*/*.d
|
||||||
rm -rf tests/asicworld/*.out tests/asicworld/*.log
|
rm -rf tests/asicworld/*.out tests/asicworld/*.log
|
||||||
rm -rf tests/hana/*.out tests/hana/*.log
|
rm -rf tests/hana/*.out tests/hana/*.log
|
||||||
|
@ -577,7 +610,7 @@ clean:
|
||||||
|
|
||||||
clean-abc:
|
clean-abc:
|
||||||
$(MAKE) -C abc DEP= clean
|
$(MAKE) -C abc DEP= clean
|
||||||
rm -f yosys-abc$(EXE) abc/abc-[0-9a-f]*
|
rm -f yosys-abc$(EXE) yosys-libabc.a abc/abc-[0-9a-f]* abc/libabc-[0-9a-f]*.a
|
||||||
|
|
||||||
mrproper: clean
|
mrproper: clean
|
||||||
git clean -xdf
|
git clean -xdf
|
||||||
|
|
|
@ -85,20 +85,37 @@ USING_YOSYS_NAMESPACE
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
# include <emscripten.h>
|
||||||
|
|
||||||
extern "C" int main(int, char**);
|
extern "C" int main(int, char**);
|
||||||
extern "C" void run(const char*);
|
extern "C" void run(const char*);
|
||||||
extern "C" const char *errmsg();
|
extern "C" const char *errmsg();
|
||||||
extern "C" const char *prompt();
|
extern "C" const char *prompt();
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
EM_ASM(
|
||||||
|
if (ENVIRONMENT_IS_NODE)
|
||||||
|
{
|
||||||
|
FS.mkdir('/hostcwd');
|
||||||
|
FS.mount(NODEFS, { root: '.' }, '/hostcwd');
|
||||||
|
FS.mkdir('/hostfs');
|
||||||
|
FS.mount(NODEFS, { root: '/' }, '/hostfs');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
mkdir("/work", 0777);
|
mkdir("/work", 0777);
|
||||||
chdir("/work");
|
chdir("/work");
|
||||||
log_files.push_back(stdout);
|
log_files.push_back(stdout);
|
||||||
log_error_stderr = true;
|
log_error_stderr = true;
|
||||||
yosys_banner();
|
yosys_banner();
|
||||||
yosys_setup();
|
yosys_setup();
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
// Run the first argument as a script file
|
||||||
|
run_frontend(argv[1], "script", 0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(const char *command)
|
void run(const char *command)
|
||||||
|
|
|
@ -739,7 +739,7 @@ std::string proc_self_dirname()
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
std::string proc_share_dirname()
|
std::string proc_share_dirname()
|
||||||
{
|
{
|
||||||
return "/share";
|
return "/share/";
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::string proc_share_dirname()
|
std::string proc_share_dirname()
|
||||||
|
|
|
@ -60,6 +60,10 @@
|
||||||
|
|
||||||
#include "frontends/blif/blifparse.h"
|
#include "frontends/blif/blifparse.h"
|
||||||
|
|
||||||
|
#ifdef YOSYS_LINK_ABC
|
||||||
|
extern "C" int Abc_RealMain(int argc, char *argv[]);
|
||||||
|
#endif
|
||||||
|
|
||||||
USING_YOSYS_NAMESPACE
|
USING_YOSYS_NAMESPACE
|
||||||
PRIVATE_NAMESPACE_BEGIN
|
PRIVATE_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
@ -546,11 +550,13 @@ std::string replace_tempdir(std::string text, std::string tempdir_name, bool sho
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string selfdir_name = proc_self_dirname();
|
std::string selfdir_name = proc_self_dirname();
|
||||||
while (1) {
|
if (selfdir_name != "/") {
|
||||||
size_t pos = text.find(selfdir_name);
|
while (1) {
|
||||||
if (pos == std::string::npos)
|
size_t pos = text.find(selfdir_name);
|
||||||
break;
|
if (pos == std::string::npos)
|
||||||
text = text.substr(0, pos) + "<yosys-exe-dir>/" + text.substr(pos + GetSize(selfdir_name));
|
break;
|
||||||
|
text = text.substr(0, pos) + "<yosys-exe-dir>/" + text.substr(pos + GetSize(selfdir_name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
@ -943,8 +949,24 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin
|
||||||
buffer = stringf("%s -s -f %s/abc.script 2>&1", exe_file.c_str(), tempdir_name.c_str());
|
buffer = stringf("%s -s -f %s/abc.script 2>&1", exe_file.c_str(), tempdir_name.c_str());
|
||||||
log("Running ABC command: %s\n", replace_tempdir(buffer, tempdir_name, show_tempdir).c_str());
|
log("Running ABC command: %s\n", replace_tempdir(buffer, tempdir_name, show_tempdir).c_str());
|
||||||
|
|
||||||
|
#ifndef YOSYS_LINK_ABC
|
||||||
abc_output_filter filt(tempdir_name, show_tempdir);
|
abc_output_filter filt(tempdir_name, show_tempdir);
|
||||||
int ret = run_command(buffer, std::bind(&abc_output_filter::next_line, filt, std::placeholders::_1));
|
int ret = run_command(buffer, std::bind(&abc_output_filter::next_line, filt, std::placeholders::_1));
|
||||||
|
#else
|
||||||
|
// These needs to be mutable, supposedly due to getopt
|
||||||
|
char *abc_argv[5];
|
||||||
|
string tmp_script_name = stringf("%s/abc.script", tempdir_name.c_str());
|
||||||
|
abc_argv[0] = strdup(exe_file.c_str());
|
||||||
|
abc_argv[1] = strdup("-s");
|
||||||
|
abc_argv[2] = strdup("-f");
|
||||||
|
abc_argv[3] = strdup(tmp_script_name.c_str());
|
||||||
|
abc_argv[4] = 0;
|
||||||
|
int ret = Abc_RealMain(4, abc_argv);
|
||||||
|
free(abc_argv[0]);
|
||||||
|
free(abc_argv[1]);
|
||||||
|
free(abc_argv[2]);
|
||||||
|
free(abc_argv[3]);
|
||||||
|
#endif
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
log_error("ABC: execution of command \"%s\" failed: return code %d.\n", buffer.c_str(), ret);
|
log_error("ABC: execution of command \"%s\" failed: return code %d.\n", buffer.c_str(), ret);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue