summaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/python')
-rw-r--r--src/python/abc.sh78
-rw-r--r--src/python/abcpy_test.py54
-rw-r--r--src/python/build.txt32
-rw-r--r--src/python/getch.py37
-rw-r--r--src/python/module.make92
-rw-r--r--src/python/package.py176
-rw-r--r--src/python/pyabc.i1319
-rw-r--r--src/python/pyabc_split.py412
-rw-r--r--src/python/reachx_cmd.py108
-rw-r--r--src/python/redirect.py111
-rw-r--r--src/python/setup.py67
11 files changed, 0 insertions, 2486 deletions
diff --git a/src/python/abc.sh b/src/python/abc.sh
deleted file mode 100644
index 688cf567..00000000
--- a/src/python/abc.sh
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/sh
-#
-# Setup the ABC/Py environment and run the ABC/Py executable
-# (ABC/Py stands for ABC with embedded Python)
-#
-# ABC/Py expects the following directory structure
-#
-# abc_root/
-# bin/
-# abc - this script
-# abc_exe - the ABC executable
-# ... - Other scripts
-# lib/
-# pyabc.py - support file for pyabc extension
-# python_library.zip - The Python standard library. Only if not using the system Python interpreter.
-# *.so - Python extensions, Only if not using the system Python interpreter.
-# scripts/
-# *.py - default directory for python scripts
-#
-
-# usage: abspath <dir>
-# get the absolute path of <dir>
-abspath()
-{
- cwd="$(pwd)"
- cd "$1"
- echo "$(pwd)"
- cd "${cwd}"
-}
-
-self=$0
-
-self_dir=$(dirname "${self}")
-self_dir=$(abspath "${self_dir}")
-
-abc_root=$(dirname "${self_dir}")
-
-abc_exe="${abc_root}/bin/abc_exe"
-
-PYTHONPATH="${abc_root}/lib":"${PYTHONPATH}"
-export PYTHONPATH
-
-if [ -d "${abc_root}/scripts" ] ; then
- ABC_PYTHON_SCRIPTS="${abc_root}/scripts"
- export ABC_PYTHON_SCRIPTS
-
- PYTHONPATH="${ABC_PYTHON_SCRIPTS}":"${PYTHONPATH}"
- export PYTHONPATH
-fi
-
-if [ -f "${abc_root}/scripts/abc.rc" ] ; then
- ABC_PYTHON_ABC_RC="${abc_root}/scripts/abc.rc"
- export ABC_PYTHON_ABC_RC
-fi
-
-if [ -f "${abc_root}/lib/python_library.zip" ] ; then
- PYTHONHOME="${abc_root}"
- export PYTHONHOME
-
- PYTHONPATH="${abc_root}/lib/python_library.zip":"${PYTHONPATH}"
- export PYTHONPATH
-fi
-
-PATH="${abc_root}/bin:$PATH"
-export PATH
-
-if [ "$1" = "--debug" ]; then
- shift
- abc_debugger="$1"
- shift
-
- echo export PYTHONHOME=$PYTHONHOME
- echo export PYTHONPATH=$PYTHONPATH
- echo export ABC_PYTHON_SCRIPTS=$ABC_PYTHON_SCRIPTS
- echo export ABC_PYTHON_ABC_RC=$ABC_PYTHON_ABC_RC
-fi
-
-exec ${abc_debugger} "${abc_exe}" "$@"
diff --git a/src/python/abcpy_test.py b/src/python/abcpy_test.py
deleted file mode 100644
index 28c3505b..00000000
--- a/src/python/abcpy_test.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
-import pyabc
-
-# A new command is just a function that accepts a list of string arguments
-# The first argument is always the name of the command
-# It MUST return an integer. -1: user quits, -2: error. Return 0 for success.
-
-# a simple command that just prints its arguments and returns success
-def pytest1_cmd(args):
- print args
- return 0
-
-# registers the command:
-# The first argument is the function
-# The second argument is the category (mainly for the ABC help command)
-# The third argument is the new command name
-# Keet the fourth argument 0, or consult with Alan
-pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)
-
-# a simple command that just prints its arguments and runs the command 'scorr -h'
-def pytest2_cmd(args):
- print args
- pyabc.run_command('scorr -h')
- return 0
-
-pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)
-
-# Now a more complicated command with argument parsing
-# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
-# for more details see the optparse module: http://docs.python.org/library/optparse.html
-
-import optparse
-
-def pytest3_cmd(args):
- usage = "usage: %prog [options]"
-
- parser = optparse.OptionParser(usage, prog="pytest3")
-
- parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for")
- parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")
-
- options, args = parser.parse_args(args)
-
- if options.version:
- print sys.version
- return 0
-
- if options.cmd:
- pyabc.run_command("%s -h"%options.cmd)
- return 0
-
- return 0
-
-pyabc.add_abc_command(pytest3_cmd, "Python-Test", "pytest3", 0)
diff --git a/src/python/build.txt b/src/python/build.txt
deleted file mode 100644
index 60a3a9ba..00000000
--- a/src/python/build.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-On Windows:
-
-python setup.py build
-python setup.py bdist_wininst
-
-On Linux (from the main abc directory)
-
-To build the extensions (make sure -fPIC is added to OPTFLAG in the main ABC Makefile first)
-
-make ABC_PYTHON=/usr/bin/python pyabc_extension_install
-
-To build the ABC with embedded python
-
-make pyabc.tgz
-
-
-
-
-Updating the latest version on mima:
-
-alanmi@mima:~/abc_60$ cp ./src/python/build/lib.linux-x86_64-2.6/_pyabc.so /hd/common/pyabc/builds/101030/_pyabc.so
-alanmi@mima:~/abc_60$ cp ./src/python/build/lib.linux-x86_64-2.6/pyabc.py /hd/common/pyabc/builds/101030/pyabc.py
-
-alanmi@mima:/hd/common/pyabc$ rm current
-alanmi@mima:/hd/common/pyabc$ ln -s builds/101030 current
-alanmi@mima:/hd/common/pyabc$ ls -l
-total 4
-lrwxrwxrwx 1 alanmi common 13 2010-10-30 14:55 current -> builds/101030
-
-
-Latest documentation:
-http://goo.gl/jNV2 \ No newline at end of file
diff --git a/src/python/getch.py b/src/python/getch.py
deleted file mode 100644
index 89e13078..00000000
--- a/src/python/getch.py
+++ /dev/null
@@ -1,37 +0,0 @@
-
-class _Getch:
- """Gets a single character from standard input. Does not echo to the screen."""
- def __init__(self):
- try:
- self.impl = _GetchWindows()
- except ImportError:
- self.impl = _GetchUnix()
-
- def __call__(self): return self.impl()
-
-
-class _GetchUnix:
- def __init__(self):
- import tty, sys
-
- def __call__(self):
- import sys, tty, termios
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(1)
- finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
- return ch
-
-
-class _GetchWindows:
- def __init__(self):
- import msvcrt
-
- def __call__(self):
- import msvcrt
- return msvcrt.getch()
-
-getch = _Getch()
diff --git a/src/python/module.make b/src/python/module.make
deleted file mode 100644
index 51be60af..00000000
--- a/src/python/module.make
+++ /dev/null
@@ -1,92 +0,0 @@
-# To compile with the embedded python interpreter set
-# the variable ABC_PYTHON to point to the python executable
-#
-# Examples:
-# make ABC_PYTHON=/usr/bin/python
-# make ABC_PYTHON=/usr/bin/python2.5
-#
-# To build the Python extension build the target pyabc
-# To create a package of ABC with embedded Python use the target pyabc.tgz
-
-ifdef ABC_PYTHON
-
- # get the directory containing this file
- ABC_PYTHON_FILES_PREFIX := $(CURDIR)/src/python
-
- ABC_SWIG := swig
- ABC_PYTHON_CONFIG := $(ABC_PYTHON)-config
- ABC_PYTHON_CFLAGS := $(shell $(ABC_PYTHON_CONFIG) --includes) -DABC_PYTHON_EMBED=1
- ABC_PYTHON_LDFLAGS := $(shell $(ABC_PYTHON_CONFIG) --ldflags)
-
- CFLAGS += $(ABC_PYTHON_CFLAGS)
- CXXFLAGS += $(ABC_PYTHON_CFLAGS)
- LIBS += $(ABC_PYTHON_LDFLAGS)
-
- ABC_PYTHON_SRC := $(ABC_PYTHON_FILES_PREFIX)/pyabc_wrap.c
-
- SRC += $(ABC_PYTHON_SRC)
-
- GARBAGE += \
- $(ABC_PYTHON_SRC) \
- $(ABC_PYTHON_SRC:_wrap.c=.py) \
- $(ABC_PYTHON_SRC:_wrap.c=.pyc) \
- $(ABC_PYTHON_FILES_PREFIX)/build \
- $(ABC_PYTHON_FILES_PREFIX)/dist \
- pyabc.tgz
-
- ABC_PYABC_DIR ?= pyabc
- ABC_PYABC_TGZ ?= pyabc.tgz
- ABC_PYABC_EXTRA_BIN ?=
- ABC_PYABC_EXTRA_LIB ?=
-
-
-%_wrap.c %.py : %.i
- $(ABC_SWIG) -python -outdir $(<D) $<
-
-.PHONY: pyabc_extension_build
-
-pyabc_extension_build : lib$(PROG).a $(ABC_PYTHON_SRC) $(ABC_PYTHON_SRC:_wrap.c=.py)
- ( cd $(ABC_PYTHON_FILES_PREFIX) && rm -rf build/ )
- ( cd $(ABC_PYTHON_FILES_PREFIX) && $(ABC_PYTHON) setup.py build )
-
-.PHONY: pyabc_extension_install
-
-pyabc_extension_install : pyabc_extension_build
- ( cd $(ABC_PYTHON_FILES_PREFIX) && $(ABC_PYTHON) setup.py install --user )
-
-.PHONY: pyabc_extension_bdist
-
-pyabc_extension_bdist : pyabc_extension_build
- ( cd $(ABC_PYTHON_FILES_PREFIX) && python setup.py bdist )
-
-.PHONY: pyabc_tgz
-
-pyabc_tgz : $(ABC_PYABC_TGZ)
-
-$(ABC_PYABC_TGZ) : $(PROG) $(ABC_PYTHON_SRC:_wrap.c=.py) $(ABC_PYTHON_FILES_PREFIX)/abc.sh $(ABC_PYTHON_FILES_PREFIX)/package.py
- $(ABC_PYTHON) $(ABC_PYTHON_FILES_PREFIX)/package.py \
- --pyabc_dir=$(ABC_PYABC_DIR) \
- --abc=$(PROG) \
- --abc_sh=$(ABC_PYTHON_FILES_PREFIX)/abc.sh \
- --pyabc=$(ABC_PYTHON_FILES_PREFIX) \
- --extra_bin="$(ABC_PYABC_EXTRA_BIN)" \
- --extra_lib="$(ABC_PYABC_EXTRA_LIB)" \
- --out=$@ \
- $(ABC_PYTHON_OPTIONS)
-
-PYABC_INSTALL_TARGET ?= $(shell date +%Y-%m-%d_%H-%M.%N_${USER})
-PYABC_INSTALL_TARGET := $(PYABC_INSTALL_TARGET)
-
-PYABC_INSTALL_DIR ?= /hd/common/pyabc/builds/pyabc_builds/
-
-pyabc_install_target: pyabc_extension_bdist
- mkdir -p "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)"
- tar \
- --directory="$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)" \
- --show-transformed-names \
- --transform='s#^.*/##g' \
- -xvzf "$(ABC_PYTHON_FILES_PREFIX)/dist/pyabc-1.0.linux-x86_64.tar.gz"
- find "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)/"* -type d | xargs rmdir
- echo "Installed at $(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)"
-
-endif
diff --git a/src/python/package.py b/src/python/package.py
deleted file mode 100644
index 2e6ad559..00000000
--- a/src/python/package.py
+++ /dev/null
@@ -1,176 +0,0 @@
-import os
-import sys
-import optparse
-import zipfile
-import tarfile
-import tempfile
-import time
-import py_compile
-
-def zip_library(f, extra_files = []):
- lib = "%s/lib/python%s/"%(sys.prefix,sys.version[:3])
-
- zf = zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED)
-
- for root, _, files in os.walk(lib):
- arcroot = os.path.relpath(root, lib)
- for f in files:
- _, ext = os.path.splitext(f)
- if ext in ['.py']:
- zf.write(os.path.join(root,f), os.path.join(arcroot, f))
-
- for s, r in extra_files:
- zf.write( s, r )
-
- zf.close()
-
-def add_python_lib(tf, lib_dir, lib, mtime):
-
- _, prefix = os.path.split(lib)
-
- for root, _, files in os.walk(lib):
-
- relpath = os.path.relpath(root, lib)
-
- if '.hg' in relpath.split('/'):
- continue
-
- if relpath=='.':
- arcroot = lib_dir
- else:
- arcroot = os.path.join( lib_dir, os.path.relpath(root, lib) )
-
- arcroot = os.path.join(arcroot, prefix)
-
- add_dir(tf, arcroot, mtime)
-
- for f in files:
- _, ext = os.path.splitext(f)
- if ext in ['.py', '.so']:
- add_file( tf, os.path.join(root,f), os.path.join(arcroot, f), 0666, mtime)
-
-def add_dir(tf, dir, mtime):
- ti = tarfile.TarInfo(dir)
- ti.mode = 0777
- ti.mtime = mtime
- ti.type = tarfile.DIRTYPE
-
- tf.addfile(ti)
-
-def add_fileobj(tf, f, arcname, mode, mtime):
- ti = tarfile.TarInfo(arcname)
- ti.mode = mode
- ti.mtime = mtime
-
- f.seek(0, os.SEEK_END)
- ti.size = f.tell()
-
- f.seek(0, os.SEEK_SET)
- tf.addfile(ti, f)
-
-def add_file(tf, fname, arcname, mode, mtime):
- print "\t adding %s as %s"%(fname, arcname)
-
- with open(fname, "rb") as f:
- add_fileobj(tf, f, arcname, mode, mtime)
-
-def package(pyabc_dir, extra_bin, extra_lib, extra_files, abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys):
-
- mtime = time.time()
-
- tf = tarfile.open(ofname, "w:gz")
-
- add_dir(tf, "%s"%pyabc_dir, mtime)
-
- add_dir(tf, "%s/bin"%pyabc_dir, mtime)
-
- add_file(tf, abc_exe, "%s/bin/abc_exe"%pyabc_dir, 0777, mtime)
- add_file(tf, abc_sh, "%s/bin/abc"%pyabc_dir, 0777, mtime)
-
- if scripts_dir:
- for fn in os.listdir(scripts_dir):
- if fn.startswith('.'):
- continue
- fullname = os.path.join(scripts_dir, fn)
- if os.path.isfile(fullname):
- fnroot, fnext = os.path.splitext(fn)
- if fnext==".sh":
- add_file( tf, fullname, os.path.join("%s/bin"%pyabc_dir, fnroot), 0777, mtime)
- elif fnext not in ( '.pyc', '.pyo'):
- add_file( tf, fullname, os.path.join("%s/scripts"%pyabc_dir, fn), 0666, mtime)
-
- for bin in extra_bin:
- add_file( tf, bin, os.path.join("%s/bin"%pyabc_dir, os.path.basename(bin)), 0777, mtime)
-
- lib_dir = "%s/lib"%pyabc_dir
-
- add_dir(tf, lib_dir, mtime)
-
- for lib in extra_lib:
- add_python_lib( tf, lib_dir, lib, mtime)
-
- for file, dest in extra_files:
- add_file(tf, file, '%s/%s'%(pyabc_dir, dest), 0666, mtime)
-
- for entry in os.listdir(pyabc):
- if entry.endswith('.py'):
- add_file( tf, os.path.join(pyabc, entry), os.path.join("%s/lib"%pyabc_dir, entry), 0666, mtime)
-
- if not use_sys:
- # ZIP standard library
- zf = tempfile.NamedTemporaryFile("w+b")
- #zip_library(zf, [(pyabc, "pyabc.py")])
- zip_library(zf, [])
- zf.flush()
-
- add_fileobj(tf, zf, "%s/lib/python_library.zip"%pyabc_dir, 0666, mtime)
-
- zf.close()
-
- # add all extensions
-
- lib_dynload = os.path.join(sys.exec_prefix,"lib", "python%s"%sys.version[:3], "lib-dynload")
-
- for fn in os.listdir(lib_dynload):
- fullname = os.path.join(lib_dynload, fn)
- if os.path.isfile(fullname):
- add_file( tf, fullname, os.path.join("%s/lib"%pyabc_dir, fn), 0666, mtime)
-
- tf.close()
-
-
-def main(args):
-
- usage = "usage: %prog [options]"
-
- parser = optparse.OptionParser(usage)
-
- parser.add_option("-d", "--pyabc_dir", dest="pyabc_dir", help="name of generated directory" )
- parser.add_option("-b", "--extra_bin", dest="extra_bin", help="extra binaries to pack" )
- parser.add_option("-l", "--extra_lib", dest="extra_lib", help="extra directories in lib to pack" )
- parser.add_option("-f", "--extra_files", dest="extra_files", help="additional files (comma separated pairs of file:dest" )
- parser.add_option("-a", "--abc", dest="abc", help="location of the ABC exeutable")
- parser.add_option("-s", "--abc_sh", dest="abc_sh", help="location of the ABC setup script")
- parser.add_option("-p", "--pyabc", dest="pyabc", help="location of pyabc.py")
- parser.add_option("-o", "--out", dest="out", help="location of output tar gzipped file")
- parser.add_option("-x", "--scripts", dest="scripts", default="scripts", help="location of scripts")
- parser.add_option("-S", "--system", action="store_false", dest="sys", default=True, help="use default python installation")
-
- options, args = parser.parse_args(args)
-
- if len(args) > 1:
- parser.print_help()
- return 1
-
- if not options.pyabc_dir or not options.abc or not options.abc_sh or not options.pyabc or not options.out:
- parser.print_help()
- return 1
-
- extra_bin = options.extra_bin.split(',') if options.extra_bin else []
- extra_lib = options.extra_lib.split(',') if options.extra_lib else []
- extra_files = [ s.split(':') for s in options.extra_files.split(',')] if options.extra_files else []
-
- return package(options.pyabc_dir, extra_bin, extra_lib, extra_files, options.abc, options.abc_sh, options.pyabc, options.out, options.scripts, options.sys)
-
-if __name__=="__main__":
- main(sys.argv)
diff --git a/src/python/pyabc.i b/src/python/pyabc.i
deleted file mode 100644
index 0e7b9312..00000000
--- a/src/python/pyabc.i
+++ /dev/null
@@ -1,1319 +0,0 @@
-%module pyabc
-
-// -------------------------------------------------------------------
-// SWIG typemap allowing us to grab a Python callable object
-// -------------------------------------------------------------------
-
-#ifdef SWIG<Python>
-
-%typemap(in) PyObject *PyFunc
-{
-
- if ( !PyCallable_Check($source) )
- {
- PyErr_SetString(PyExc_TypeError, "Need a callable object!");
- return NULL;
- }
-
- $target = $source;
-}
-
-#endif /* #ifdef SWIG<Python> */
-
-%{
-
-#include <base/main/main.h>
-#include <misc/util/utilCex.h>
-
-#include <stdlib.h>
-#include <signal.h>
-
-#include <sys/prctl.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int n_ands()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk && Abc_NtkIsStrash(pNtk) )
- {
- return Abc_NtkNodeNum(pNtk);
- }
-
- return -1;
-}
-
-int n_nodes()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk )
- {
- return Abc_NtkNodeNum(pNtk);
- }
-
- return -1;
-}
-
-int n_pis()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk )
- {
- return Abc_NtkPiNum(pNtk);
- }
-
- return -1;
-}
-
-
-int n_pos()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk )
- {
- return Abc_NtkPoNum(pNtk);
- }
-
- return -1;
-}
-
-int n_latches()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk )
- {
- return Abc_NtkLatchNum(pNtk);
- }
-
- return -1;
-}
-
-int n_levels()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk )
- {
- return Abc_NtkLevel(pNtk);
- }
-
- return -1;
-}
-
-double n_area()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( pNtk && Abc_NtkHasMapping(pNtk) )
- {
- return Abc_NtkGetMappedArea(pNtk);
- }
-
- return -1;
-}
-
-int has_comb_model()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- return pNtk && pNtk->pModel;
-}
-
-int has_seq_model()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- return pNtk && pNtk->pSeqModel;
-}
-
-int n_bmc_frames()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- return Abc_FrameReadBmcFrames(pAbc);
-}
-
-int prob_status()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- return Abc_FrameReadProbStatus(pAbc);
-}
-
-int is_valid_cex()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- return pNtk && Abc_FrameReadCex(pAbc) && Abc_NtkIsValidCex( pNtk, Abc_FrameReadCex(pAbc) );
-}
-
-int is_true_cex()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- return pNtk && Abc_FrameReadCex(pAbc) && Abc_NtkIsTrueCex( pNtk, Abc_FrameReadCex(pAbc) );
-}
-
-int n_cex_pis()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
-
- return Abc_FrameReadCex(pAbc) ? Abc_FrameReadCexPiNum( pAbc ) : -1;
-}
-
-int n_cex_regs()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
-
- return Abc_FrameReadCex(pAbc) ? Abc_FrameReadCexRegNum( pAbc ) : -1;
-}
-
-int cex_po()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
-
- return Abc_FrameReadCex(pAbc) ? Abc_FrameReadCexPo( pAbc ) : -1;
-}
-
-int cex_frame()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
-
- return Abc_FrameReadCex(pAbc) ? Abc_FrameReadCexFrame( pAbc ) : -1;
-}
-
-int n_phases()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- return pNtk ? Abc_NtkPhaseFrameNum(pNtk) : 1;
-}
-
-int is_const_po( int iPoNum )
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- return Abc_FrameCheckPoConst( pAbc, iPoNum );
-}
-
-Abc_Cex_t* _cex_get()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Cex_t* pCex = Abc_FrameReadCex(pAbc);
-
- if ( ! pCex )
- {
- return NULL;
- }
-
- return Abc_CexDup( pCex, -1 );
-}
-
-int _cex_get_vec_len()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Ptr_t* vCexVec = Abc_FrameReadCexVec(pAbc);
-
- if( ! vCexVec )
- {
- return 0;
- }
-
- return Vec_PtrSize(vCexVec);
-}
-
-Abc_Cex_t* _cex_get_vec(int i)
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Ptr_t* vCexVec = Abc_FrameReadCexVec(pAbc);
-
- if( ! vCexVec )
- {
- return NULL;
- }
-
- Abc_Cex_t* pCex = (Abc_Cex_t*)Vec_PtrEntry( vCexVec, i );
-
- if ( ! pCex )
- {
- return NULL;
- }
-
- return Abc_CexDup( pCex, -1 );
-}
-
-int _status_get_vec_len()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Int_t* vStatusVec = Abc_FrameReadStatusVec(pAbc);
-
- if( ! vStatusVec )
- {
- return 0;
- }
-
- return Vec_IntSize(vStatusVec);
-}
-
-int _status_get_vec(int i)
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Int_t* vStatusVec = Abc_FrameReadStatusVec(pAbc);
-
- if( ! vStatusVec )
- {
- return -1;
- }
-
- return Vec_IntEntry( vStatusVec, i );
-}
-
-void _cex_put(Abc_Cex_t* pCex)
-{
- if ( pCex )
- {
- pCex = Abc_CexDup(pCex, -1);
- }
-
- Abc_FrameSetCex( pCex );
-}
-
-void _cex_free(Abc_Cex_t* pCex)
-{
- Abc_CexFree(pCex);
-}
-
-int _cex_n_regs(Abc_Cex_t* pCex)
-{
- return pCex->nRegs;
-}
-
-int _cex_n_pis(Abc_Cex_t* pCex)
-{
- return pCex->nPis;
-}
-
-int _cex_get_po(Abc_Cex_t* pCex)
-{
- return pCex->iPo;
-}
-
-int _cex_get_frame(Abc_Cex_t* pCex)
-{
- return pCex->iFrame;
-}
-
-static PyObject* VecInt_To_PyList(Vec_Int_t* v)
-{
- PyObject* pylist = PyList_New( Vec_IntSize(v) );
-
- int elem, i;
-
- Vec_IntForEachEntry( v, elem, i)
- {
- PyList_SetItem( pylist, i, PyInt_FromLong(elem) );
- }
-
- return pylist;
-}
-
-PyObject* eq_classes()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Ptr_t *vPoEquivs = Abc_FrameReadPoEquivs(pAbc);
-
- PyObject* eq_classes;
- Vec_Int_t* pEntry;
- int i;
-
- if( ! vPoEquivs )
- {
- Py_RETURN_NONE;
- }
-
- eq_classes = PyList_New( Vec_PtrSize(vPoEquivs) );
-
- Vec_PtrForEachEntry( Vec_Int_t*, vPoEquivs, pEntry, i )
- {
- PyList_SetItem( eq_classes, i, VecInt_To_PyList(pEntry) );
- }
-
- return eq_classes;
-}
-
-PyObject* co_supp( int iCo )
-{
- PyObject* co_supp;
- Vec_Int_t * vSupp;
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( !pNtk )
- {
- Py_RETURN_NONE;
- }
-
- vSupp = Abc_NtkNodeSupportInt( pNtk, iCo );
-
- if( !vSupp )
- {
- Py_RETURN_NONE;
- }
-
- co_supp = VecInt_To_PyList( vSupp );
- Vec_IntFree( vSupp );
-
- return co_supp;
-}
-
-int is_func_iso( int iCo1, int iCo2 )
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( !pNtk )
- {
- return 0;
- }
-
- return Abc_NtkFunctionalIso( pNtk, iCo1, iCo2, 0 );
-}
-
-int is_func_iso2( int iCo1, int iCo2 )
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
-
- if ( !pNtk )
- {
- return 0;
- }
-
- return Abc_NtkFunctionalIso( pNtk, iCo1, iCo2, 1 );
-}
-
-void _pyabc_array_clear()
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Int_t *vObjIds = Abc_FrameReadObjIds(pAbc);
- Vec_IntClear( vObjIds );
-}
-
-void _pyabc_array_push(int i)
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Int_t *vObjIds = Abc_FrameReadObjIds(pAbc);
- Vec_IntPush( vObjIds, i );
-}
-
-int pyabc_array_read_entry(int i)
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- Vec_Int_t *vObjIds = Abc_FrameReadObjIds(pAbc);
- if( !vObjIds )
- return -1;
- return Vec_IntEntry( vObjIds, i );
-}
-
-static PyObject* pyabc_internal_python_command_callback = 0;
-
-void pyabc_internal_set_command_callback( PyObject* callback )
-{
- Py_XINCREF(callback);
- Py_XDECREF(pyabc_internal_python_command_callback);
-
- pyabc_internal_python_command_callback = callback;
-}
-
-static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, char ** argv)
-{
- int i;
-
- PyObject* args;
- PyObject* arglist;
- PyObject* res;
-
- PyGILState_STATE gstate;
-
- long lres;
-
- if ( !pyabc_internal_python_command_callback )
- return 0;
-
- gstate = PyGILState_Ensure();
-
- args = PyList_New(argc);
-
- for( i=0 ; i<argc ; i++ )
- PyList_SetItem(args, i, PyString_FromString(argv[i]) );
-
- arglist = Py_BuildValue("(O)", args);
- Py_INCREF(arglist);
-
- res = PyEval_CallObject( pyabc_internal_python_command_callback, arglist );
- Py_DECREF(arglist);
-
- if ( !res )
- {
- PyGILState_Release(gstate);
- return -1;
- }
-
- lres = PyInt_AsLong(res);
- Py_DECREF(res);
-
- PyGILState_Release(gstate);
-
- return lres;
-}
-
-int run_command(char* cmd)
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
- int rc;
-
- Py_BEGIN_ALLOW_THREADS
-
- rc = Cmd_CommandExecute(pAbc, cmd);
-
- Py_END_ALLOW_THREADS
-
- return rc;
-}
-
-void pyabc_internal_register_command( char * sGroup, char * sName, int fChanges )
-{
- Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
-
- Cmd_CommandAdd( pAbc, sGroup, sName, (Cmd_CommandFuncType)pyabc_internal_abc_command_callback, fChanges);
-}
-
-static int sigchld_pipe_fd = -1;
-
-static void sigchld_handler(int signum)
-{
- while( write(sigchld_pipe_fd, "", 1) == -1 && errno==EINTR )
- ;
-}
-
-static void install_sigchld_handler(int sigchld_fd)
-{
- sigchld_pipe_fd = sigchld_fd;
- signal(SIGCHLD, sigchld_handler);
-}
-
-static int sigint_pipe_fd = -1;
-
-static void sigint_handler(int signum)
-{
- unsigned char tmp = (unsigned char)signum;
- while( write(sigint_pipe_fd, &tmp, 1) == -1 && errno==EINTR )
- ;
-}
-
-static void install_sigint_handler(int sigint_fd)
-{
- sigint_pipe_fd = sigint_fd;
-
- signal(SIGINT, sigint_handler);
-
- // try to catch other signals that ask the process to terminate
- signal(SIGABRT, sigint_handler);
- signal(SIGQUIT, sigint_handler);
- signal(SIGTERM, sigint_handler);
-
- // try to ensure cleanup on exceptional conditions
- signal(SIGBUS, sigint_handler);
- signal(SIGILL, sigint_handler);
- signal(SIGSEGV, sigint_handler);
-
- // try to ensure cleanup before being killed due to resource limit
- signal(SIGXCPU, sigint_handler);
- signal(SIGXFSZ, sigint_handler);
-}
-
-sigset_t old_procmask;
-static int nblocks = 0;
-
-void block_sigint()
-{
- sigset_t procmask;
-
- assert(nblocks==0);
- nblocks ++ ;
-
- sigemptyset(&procmask);
- sigaddset(&procmask, SIGINT);
-
- sigprocmask(SIG_BLOCK, &procmask, &old_procmask);
-}
-
-void unblock_sigint()
-{
- assert( nblocks==1);
- nblocks--;
-
- sigprocmask(SIG_SETMASK, &old_procmask, NULL);
-}
-
-static PyObject* pyabc_internal_system_callback = 0;
-static PyObject* pyabc_internal_tmpfile_callback = 0;
-static PyObject* pyabc_internal_tmpfile_remove_callback = 0;
-
-int Util_SignalSystem(const char* cmd)
-{
- PyObject* arglist;
- PyObject* res;
-
- PyGILState_STATE gstate;
-
- long lres;
-
- if ( !pyabc_internal_system_callback )
- return -1;
-
- gstate = PyGILState_Ensure();
-
- arglist = Py_BuildValue("(O)", PyString_FromString(cmd));
- Py_INCREF(arglist);
-
- res = PyEval_CallObject( pyabc_internal_system_callback, arglist );
- Py_DECREF(arglist);
-
- if ( !res )
- {
- PyGILState_Release(gstate);
- return -1;
- }
-
- lres = PyInt_AsLong(res);
- Py_DECREF(res);
-
- PyGILState_Release(gstate);
-
- return lres;
-}
-
-int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name)
-{
- char* str;
- Py_ssize_t size;
-
- PyObject* arglist;
- PyObject* res;
-
- PyGILState_STATE gstate;
-
- *out_name = NULL;
-
- if ( !pyabc_internal_tmpfile_callback )
- return 0;
-
- gstate = PyGILState_Ensure();
-
- arglist = Py_BuildValue("(ss)", prefix, suffix);
- Py_INCREF(arglist);
-
- res = PyEval_CallObject( pyabc_internal_tmpfile_callback, arglist );
- Py_DECREF(arglist);
-
- if ( !res )
- {
- PyGILState_Release(gstate);
- return -1;
- }
-
- PyString_AsStringAndSize(res, &str, &size);
-
- *out_name = ABC_ALLOC(char, size+1);
- strcpy(*out_name, str);
-
- Py_DECREF(res);
-
- PyGILState_Release(gstate);
-
- return open(*out_name, O_WRONLY);
-}
-
-void Util_SignalTmpFileRemove(const char* fname, int fLeave)
-{
- PyObject* arglist;
- PyObject* res;
-
- PyGILState_STATE gstate;
-
- if ( !pyabc_internal_tmpfile_remove_callback )
- return;
-
- gstate = PyGILState_Ensure();
-
- arglist = Py_BuildValue("(si)", fname, fLeave);
- Py_INCREF(arglist);
-
- res = PyEval_CallObject( pyabc_internal_tmpfile_remove_callback, arglist );
- Py_DECREF(arglist);
- Py_XDECREF(res);
-
- PyGILState_Release(gstate);
-}
-
-void pyabc_internal_set_util_callbacks( PyObject* system_callback, PyObject* tmpfile_callback, PyObject* tmpfile_remove_callback )
-{
- Py_XINCREF(system_callback);
- Py_XDECREF(pyabc_internal_system_callback);
-
- pyabc_internal_system_callback = system_callback;
-
- Py_XINCREF(tmpfile_callback);
- Py_XDECREF(pyabc_internal_tmpfile_callback);
-
- pyabc_internal_tmpfile_callback = tmpfile_callback;
-
- Py_XINCREF(tmpfile_remove_callback);
- Py_XDECREF(pyabc_internal_tmpfile_remove_callback);
-
- pyabc_internal_tmpfile_remove_callback = tmpfile_remove_callback;
-}
-
-PyObject* _wait_no_hang()
-{
- int status;
- int pid;
-
- pid = wait3(&status, WNOHANG, NULL);
-
- return Py_BuildValue("(iii)", pid, status, errno);
-}
-
-int _posix_kill(int pid, int signum)
-{
- return kill(pid, signum);
-}
-
-void _set_death_signal()
-{
- // send SIGINT if parent process is dead
- prctl(PR_SET_PDEATHSIG, SIGINT);
-
- // if parent process is already dead (and adopted by init)
- if ( getppid() == 1)
- {
- raise(SIGINT);
- }
-}
-
-%}
-
-%init
-%{
- Abc_Start();
-%}
-
-int n_ands();
-int n_nodes();
-int n_pis();
-int n_pos();
-int n_latches();
-int n_levels();
-double n_area();
-
-int run_command(char* cmd);
-
-int has_comb_model();
-int has_seq_model();
-
-int n_bmc_frames();
-int prob_status();
-
-int is_valid_cex();
-int is_true_cex();
-int n_cex_pis();
-int n_cex_regs();
-int cex_po();
-int cex_frame();
-
-int n_phases();
-int is_const_po( int iPoNum );
-
-Abc_Cex_t* _cex_get();
-int _cex_get_vec_len();
-Abc_Cex_t* _cex_get_vec(int i);
-int _status_get_vec_len();
-int _status_get_vec(int i);
-void _cex_put(Abc_Cex_t* pCex);
-void _cex_free(Abc_Cex_t* pCex);
-int _cex_n_regs(Abc_Cex_t* pCex);
-int _cex_n_pis(Abc_Cex_t* pCex);
-int _cex_get_po(Abc_Cex_t* pCex);
-int _cex_get_frame(Abc_Cex_t* pCex);
-
-PyObject* eq_classes();
-PyObject* co_supp(int iCo);
-int is_func_iso(int iCo1, int iCo2);
-int is_func_iso2(int iCo1, int iCo2);
-
-void _pyabc_array_clear();
-void _pyabc_array_push(int i);
-int pyabc_array_read_entry(int i);
-
-void pyabc_internal_set_command_callback( PyObject* callback );
-void pyabc_internal_register_command( char * sGroup, char * sName, int fChanges );
-
-void install_sigchld_handler(int sigint_fd);
-void install_sigint_handler(int sigint_fd);
-
-void block_sigint();
-void unblock_sigint();
-
-void pyabc_internal_set_util_callbacks( PyObject* system_callback, PyObject* tmpfile_callback, PyObject* tmpfile_remove_callback );
-
-PyObject* _wait_no_hang();
-
-void _set_death_signal();
-
-int _posix_kill(int pid, int signum);
-void _set_death_signal();
-
-%pythoncode
-%{
-
-class _Cex(object):
-
- def __new__(cls, pCex):
-
- if not pCex:
- return None
-
- if int(pCex)==1:
- return True
-
- return object.__new__(cls)
-
- def __init__(self, pCex):
- self.pCex = pCex
-
- def __del__(self):
- if _cex_free:
- _cex_free(self.pCex)
-
- def n_regs(self):
- return _cex_n_regs(self.pCex)
-
- def n_pis(self):
- return _cex_n_pis(self.pCex)
-
- def get_po(self):
- return _cex_get_po(self.pCex)
-
- def get_frame(self):
- return _cex_get_frame(self.pCex)
-
-def cex_get_vector():
-
- return [ _Cex(_cex_get_vec(i)) for i in xrange(_cex_get_vec_len()) ]
-
-def status_get_vector():
-
- return [ _status_get_vec(i) for i in xrange(_status_get_vec_len()) ]
-
-def cex_get():
-
- return _Cex( _cex_get() )
-
-def cex_put(cex):
-
- assert cex is not None
- assert cex.pCex is not None
-
- return _cex_put(cex.pCex)
-
-
-def create_abc_array(List):
- _pyabc_array_clear()
- for ObjId in List:
- _pyabc_array_push(ObjId)
-
-
-import threading
-import select
-import signal
-import tempfile
-import os
-import errno
-import sys, traceback
-import subprocess
-
-_active_lock = threading.Lock()
-_die_flag = False
-
-_active_pids = set()
-_active_temp_files = set()
-
-_terminated_pids_cond = threading.Condition(_active_lock)
-_terminated_pids = {}
-
-def add_temp_file(fname):
- with _active_lock:
- _active_temp_files.add(fname)
-
-def remove_temp_file(fname):
- with _active_lock:
- _active_temp_files.remove(fname)
-
-_old_os_wait3 = os.wait3
-_select_select = select.select
-
-def _retry_select(fd):
- while True:
- try:
- rrdy,_,_ = _select_select([fd],[],[])
- if fd in rrdy:
- return
- except select.error as e:
- if e[0] == errno.EINTR:
- continue
- raise
-
-def _retry_read(fd):
-
- while True:
- try:
- return fd.read(1)
- except OSError as e:
- if e.errno == errno.EINTR:
- continue
- raise
-
-def _retry_os_read(fd):
-
- while True:
- try:
- return os.read(fd, 1)
- except OSError as e:
- if e.errno == errno.EINTR:
- continue
- raise
-
-def _retry_wait():
-
- while True:
-
- pid, status, e = _wait_no_hang()
-
- if pid>0:
- return pid, status
-
- elif pid==0:
- return 0,0
-
- elif pid == -1 and e == errno.ECHILD:
- return 0,0
-
- elif pid==-1 and e != errno.EINTR:
- raise OSError(e, 'unknown error in wait3()')
-
-def _sigint_wait_thread_func(fd):
-
- global _die_flag
-
- while True:
-
- _retry_select(fd)
- _retry_read(fd)
-
- with _active_lock:
-
- if _die_flag:
- os._exit(-1)
-
- _die_flag = True
-
- for pid in _active_pids:
- rc = _posix_kill(pid, signal.SIGINT)
-
- for fname in _active_temp_files:
- os.remove(fname)
-
- os._exit(-1)
-
-def _child_wait_thread_func(fd):
-
- while True:
-
- _retry_select(fd)
- rc = _retry_read(fd)
-
- with _active_lock:
-
- while True:
-
- pid, status = _retry_wait()
-
- if pid==0:
- break
-
- if pid in _active_pids:
- _active_pids.remove(pid)
-
- _terminated_pids[pid] = status
- os.write(_wait_fd_write, "1")
- _terminated_pids_cond.notifyAll()
-
-_sigint_pipe_read_fd = -1
-_sigint_pipe_write_fd = -1
-
-_sigchld_pipe_read_fd = -1
-_sigchld_pipe_write_fd = -1
-
-wait_fd = -1
-_wait_fd_write = -1
-
-def _start_threads():
-
- global wait_fd, _wait_fd_write
- wait_fd, _wait_fd_write = os.pipe()
-
- global _sigint_pipe_read_fd, _sigint_pipe_write_fd
-
- _sigint_pipe_read_fd, _sigint_pipe_write_fd = os.pipe()
- sigint_read = os.fdopen(_sigint_pipe_read_fd, "r", 0 )
-
- sigint_wait_thread = threading.Thread(target=_sigint_wait_thread_func, name="SIGINT wait thread", args=(sigint_read,))
- sigint_wait_thread.setDaemon(True)
- sigint_wait_thread.start()
-
- install_sigint_handler(_sigint_pipe_write_fd)
-
- global _sigchld_pipe_read_fd, _sigchld_pipe_write_fd
-
- _sigchld_pipe_read_fd, _sigchld_pipe_write_fd = os.pipe()
- sigchld_read = os.fdopen(_sigchld_pipe_read_fd, "r", 0 )
-
- child_wait_thread = threading.Thread(target=_child_wait_thread_func, name="child process wait thread", args=(sigchld_read,))
- child_wait_thread.setDaemon(True)
- child_wait_thread.start()
-
- install_sigchld_handler(_sigchld_pipe_write_fd)
-
-_close_on_fork = []
-
-def close_on_fork(fd):
- _close_on_fork.append(fd)
-
-def after_fork():
-
- _set_death_signal()
-
- global _close_on_fork
-
- for fd in _close_on_fork:
- os.close(fd)
-
- _close_on_fork = []
-
- os.close(wait_fd)
- os.close(_wait_fd_write)
-
- os.close(_sigint_pipe_read_fd)
- os.close(_sigint_pipe_write_fd)
-
- os.close(_sigchld_pipe_read_fd)
- os.close(_sigchld_pipe_write_fd)
-
- global _active_lock
- _active_lock = threading.Lock()
-
- global _terminated_pids_cond
- _terminated_pids_cond = threading.Condition(_active_lock)
-
- global _terminated_pids
- _terminated_pids = {}
-
- global _active_pids
- _active_pids = set()
-
- global _active_temp_files
- _active_temp_files = set()
-
- _start_threads()
-
-class _sigint_block_section(object):
- def __init__(self):
- self.blocked = False
-
- def __enter__(self):
- block_sigint()
- self.blocked = True
-
- def __exit__(self, type, value, traceback):
- self.release()
-
- def release(self):
- if self.blocked:
- self.blocked = False
- unblock_sigint()
-
-_old_os_fork = os.fork
-
-def _fork():
-
- ppid = os.getpid()
-
- with _sigint_block_section() as cs:
-
- with _active_lock:
-
- if _die_flag:
- os._exit(-1)
-
- pid = _old_os_fork()
-
- if pid == 0:
- after_fork()
-
- if pid > 0:
- _active_pids.add(pid)
-
- return pid
-
-def _waitpid(pid, options=0):
-
- while True:
-
- with _active_lock:
-
- if pid in _terminated_pids:
- _retry_os_read(wait_fd)
- status = _terminated_pids[pid]
- del _terminated_pids[pid]
- return pid, status
-
- if options==os.WNOHANG:
- return 0, 0
-
- _terminated_pids_cond.wait()
-
-def _wait(options=0):
-
- while True:
-
- with _active_lock:
-
- for pid, status in _terminated_pids.iteritems():
- _retry_os_read(wait_fd)
- del _terminated_pids[pid]
- return pid, status
-
- if options==os.WNOHANG:
- return 0, 0
-
- _terminated_pids_cond.wait()
-
-_old_os_kill = os.kill
-
-def _kill(pid, sig):
-
- with _active_lock:
-
- if pid in _terminated_pids:
- return None
-
- return _old_os_kill(pid,sig)
-
-os.kill = _kill
-os.fork = _fork
-os.wait = _wait
-os.waitpid = _waitpid
-
-def _split_command_line(cmd):
-
- args = []
-
- i=0
-
- while i<len(cmd):
-
- while i<len(cmd) and cmd[i] in [' ','\t','\f']:
- i += 1
-
- if i >= len(cmd):
- break
-
- arg = []
-
- in_quotes = None
-
- while i<len(cmd):
-
- if not in_quotes and cmd[i] in ['\'','\"','\'']:
- in_quotes = cmd[i]
-
- elif in_quotes and cmd[i]==in_quotes:
- in_quotes = None
-
- elif cmd[i] == '\\' and i<(len(cmd)+1):
-
- i += 1
-
- if cmd[i]=='\\':
- arg.append('\\')
- elif cmd[i]=='\'':
- arg.append('\'')
- elif cmd[i]=='\"':
- arg.append('\'')
- elif cmd[i]=='\"':
- arg.append('\"')
- elif cmd[i]=='a':
- arg.append('\a')
- elif cmd[i]=='b':
- arg.append('\b')
- elif cmd[i]=='n':
- arg.append('\n')
- elif cmd[i]=='f':
- arg.append('\f')
- elif cmd[i]=='r':
- arg.append('\r')
- elif cmd[i]=='t':
- arg.append('\t')
- elif cmd[i]=='v':
- arg.append('\v')
- else:
- arg.append(cmd[i])
-
- elif not in_quotes and cmd[i] in [' ','\t','\f']:
- break
-
- else:
- arg.append(cmd[i])
-
- i += 1
-
- args.append( "".join(arg) )
-
- return args
-
-
-def system(cmd):
-
- args = _split_command_line(cmd)
-
- if args[-2] == '>':
-
- with open(args[-1],'w') as fout:
- p = subprocess.Popen(args[:-2], stdout=fout)
- rc = p.wait()
- return rc
-
- else:
- p = subprocess.Popen(args)
- return p.wait()
-
-def tmpfile(prefix, suffix):
-
- with _active_lock:
- with tempfile.NamedTemporaryFile(delete=False, prefix=prefix, suffix=suffix) as file:
- _active_temp_files.add(file.name)
- return file.name
-
-def tmpfile_remove(fname, leave):
-
- with _active_lock:
- os.remove(fname)
- _active_temp_files.remove(fname)
-
-pyabc_internal_set_util_callbacks( system, tmpfile,tmpfile_remove )
-
-
-_start_threads()
-
-
-_registered_commands = {}
-
-def _cmd_callback(args):
- try:
- assert len(args) > 0
-
- cmd = args[0]
- assert cmd in _registered_commands
-
- res = _registered_commands[cmd](args)
-
- assert type(res) == int, "User-defined Python command must return an integer."
-
- return res
-
- except Exception, e:
- import traceback
- traceback.print_exc()
-
- except SystemExit, se:
- pass
-
- return 0
-
-pyabc_internal_set_command_callback( _cmd_callback )
-
-def add_abc_command(fcmd, group, cmd, change):
- _registered_commands[ cmd ] = fcmd
- pyabc_internal_register_command( group, cmd, change)
-
-import optparse
-
-xxx = {}
-
-def cmd_python(cmd_args):
-
- usage = "usage: %prog [options] <Python files>"
-
- parser = optparse.OptionParser(usage, prog="python")
-
- parser.add_option("-c", "--cmd", dest="cmd", help="Execute Python command directly")
- parser.add_option("-v", "--version", action="store_true", dest="version", help="Display Python Version")
-
- options, args = parser.parse_args(cmd_args)
-
- if options.version:
- print sys.version
- return 0
-
- if options.cmd:
- exec options.cmd in xxx
- return 0
-
- scripts_dir = os.getenv('ABC_PYTHON_SCRIPTS', ".")
- scripts_dirs = scripts_dir.split(':')
-
- for fname in args[1:]:
- if os.path.isabs(fname):
- execfile(fname, xxx)
- else:
- for d in scripts_dirs:
- fname = os.path.join(scripts_dir, fname)
- if os.path.exists(fname):
- execfile(fname, xxx)
- break
-
- return 0
-
-add_abc_command(cmd_python, "Python", "python", 0)
-
-
-%}
diff --git a/src/python/pyabc_split.py b/src/python/pyabc_split.py
deleted file mode 100644
index 89038a2c..00000000
--- a/src/python/pyabc_split.py
+++ /dev/null
@@ -1,412 +0,0 @@
-"""
-module pyabc_split
-
-Executes python functions and their arguements as separate processes and returns their return values through pickling. This modules offers a single function:
-
-Function: split_all(funcs)
-
-The function returns a generator objects that allowes iteration over the results,
-
-Arguments:
-
-funcs: a list of tuples (f, args) where f is a python function and args is a collection of arguments for f.
-
-Caveats:
-
-1. Global variables in the parent process are not affected by the child processes.
-2. The functions can only return simple types, see the pickle module for details
-
-Usage:
-
-Assume you would like to run the function f_1(1), f_2(1,2), f_3(1,2,3) in different processes.
-
-def f_1(i):
- return i+1
-
-def f_2(i,j):
- return i*10+j+1
-
-def f_3(i,j,k):
- return i*100+j*10+k+1
-
-Construct a tuple of the function and arguments for each function
-
-t_1 = (f_1, [1])
-t_2 = (f_2, [1,2])
-t_3 = (f_3, [1,2,3])
-
-Create a list containing these tuples:
-
-funcs = [t_1, t_2, t_3]
-
-Use the function split_all() to run these functions in separate processes:
-
-for res in split_all(funcs):
- print res
-
-The output will be:
-
-2
-13
-124
-
-(The order may be different, except that in this case the processes are so fast that they terminate before the next one is created)
-
-Alternatively, you may quite in the middle, say after the first process returns:
-
-for res in split_all(funcs):
- print res
- break
-
-This will kill all processes not yet finished.
-
-To run ABC operations, that required saving the child process state and restoring it at the parent, use abc_split_all().
-
- import pyabc
-
- def abc_f(truth):
- import os
- print "pid=%d, abc_f(%s)"%(os.getpid(), truth)
- pyabc.run_command('read_truth %s'%truth)
- pyabc.run_command('strash')
-
- funcs = [
- defer(abc_f)("1000"),
- defer(abc_f)("0001")
- ]
-
- for _ in abc_split_all(funcs):
- pyabc.run_command('write_verilog /dev/stdout')
-
-Author: Baruch Sterin <sterin@berkeley.edu>
-"""
-
-import os
-import select
-import fcntl
-import errno
-import sys
-import cPickle as pickle
-import signal
-import cStringIO
-
-import traceback
-
-from contextlib import contextmanager
-
-import pyabc
-
-def _retry_select(rlist):
- while True:
- try:
- rrdy,_,_ = select.select(rlist,[],[])
- if rrdy:
- return rrdy
- except select.error as e:
- if e[0] == errno.EINTR:
- continue
- raise
-
-class _splitter(object):
-
- def __init__(self):
- self.pids = []
- self.fds = {}
- self.buffers = {}
- self.results = {}
-
- def is_done(self):
- return len(self.fds) == 0
-
- def _kill(self, pids):
-
- # close pipes and kill child processes
- for pid in pids:
-
- if pid == -1:
- continue
-
- i, fd = self.fds[pid]
-
- del self.buffers[fd]
- del self.fds[pid]
-
- self.pids[i] = -1
- self.results[pid] = None
-
- os.close(fd)
-
- try:
- os.kill( pid, signal.SIGINT)
- except Exception as e:
- print >>sys.stderr, 'exception while trying to kill pid=%d: '%pid, e
- raise
-
- # wait for termination and update result
- for pid in pids:
- os.waitpid( pid, 0 )
-
- def kill(self, ids):
-
- self._kill( [ self.pids[i] for i in ids ] )
-
- def cleanup(self):
- self._kill( self.fds.keys() )
-
- def child( self, fdw, f):
-
- # call function
- try:
- res = f()
- except:
- traceback.print_exc()
- raise
-
- # write return value into pipe
- with os.fdopen( fdw, "w" ) as fout:
- pickle.dump(res, fout)
-
- return 0
-
- def _fork_one(self, f):
-
- # create a pipe to communicate with the child process
- pr,pw = os.pipe()
-
- # set pr to be non-blocking
- fcntl.fcntl(pr, fcntl.F_SETFL, os.O_NONBLOCK)
-
- parentpid = os.getpid()
- rc = 1
-
- try:
-
- # create child process
- pid = os.fork()
-
- if pid == 0:
- # child process:
- os.close(pr)
- pyabc.close_on_fork(pw)
-
- rc = self.child( pw, f)
- os._exit(rc)
- else:
- # parent process:
- os.close(pw)
- return (pid, pr)
-
- finally:
- if os.getpid() != parentpid:
- os._exit(rc)
-
- def fork_one(self, func):
- pid, fd = self._fork_one(func)
- i = len(self.pids)
- self.pids.append(pid)
- self.fds[pid] = (i, fd)
- self.buffers[fd] = cStringIO.StringIO()
- return i
-
- def fork_all(self, funcs):
- return [ self.fork_one(f) for f in funcs ]
-
- def communicate(self):
-
- rlist = [ fd for _, (_,fd) in self.fds.iteritems() ]
- rlist.append(pyabc.wait_fd)
-
- stop = False
-
- while not stop:
-
- rrdy = _retry_select( rlist )
-
- for fd in rrdy:
-
- if fd == pyabc.wait_fd:
- stop = True
- continue
-
- self.buffers[fd].write( os.read(fd, 16384) )
-
- def get_next_result(self):
-
- # read from the pipes as needed, while waiting for the next child process to terminate
- self.communicate()
-
- # wait for the next child process to terminate
- pid, rc = os.wait()
- assert pid in self.fds
-
- # retrieve the pipe file descriptor
- i, fd = self.fds[pid]
- del self.fds[pid]
-
- # remove the pid
- self.pids[i] = -1
-
- # retrieve the buffer
- buffer = self.buffers[fd]
- del self.buffers[fd]
-
- # fill the buffer
- while True:
- s = os.read(fd, 16384)
- if not s:
- break
- buffer.write(s)
-
- os.close(fd)
-
- try:
- return (i, pickle.loads(buffer.getvalue()))
- except EOFError, pickle.UnpicklingError:
- return (i, None)
-
- def __iter__(self):
- def iterator():
- while not self.is_done():
- yield self.get_next_result()
- return iterator()
-
-@contextmanager
-def make_splitter():
- # ensure cleanup of child processes
- s = _splitter()
- try:
- yield s
- finally:
- s.cleanup()
-
-def split_all_full(funcs):
- # provide an iterator for child process result
- with make_splitter() as s:
-
- s.fork_all(funcs)
-
- for res in s:
- yield res
-
-def defer(f):
- return lambda *args, **kwargs: lambda : f(*args,**kwargs)
-
-def split_all(funcs):
- for _, res in split_all_full( ( defer(f)(*args) for f,args in funcs ) ):
- yield res
-
-import tempfile
-
-@contextmanager
-def temp_file_names(suffixes):
- names = []
- try:
- for suffix in suffixes:
- with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as file:
- names.append( file.name )
- yield names
- finally:
- for name in names:
- os.unlink(name)
-
-class abc_state(object):
- def __init__(self):
- with tempfile.NamedTemporaryFile(delete=False, suffix='.aig') as file:
- self.aig = file.name
- with tempfile.NamedTemporaryFile(delete=False, suffix='.log') as file:
- self.log = file.name
- pyabc.run_command(r'write_status %s'%self.log)
- pyabc.run_command(r'write_aiger %s'%self.aig)
-
- def __del__(self):
- os.unlink( self.aig )
- os.unlink( self.log )
-
- def restore(self):
- pyabc.run_command(r'read_aiger %s'%self.aig)
- pyabc.run_command(r'read_status %s'%self.log)
-
-def abc_split_all(funcs):
- import pyabc
-
- def child(f, aig, log):
- res = f()
- pyabc.run_command(r'write_status %s'%log)
- pyabc.run_command(r'write_aiger %s'%aig)
- return res
-
- def parent(res, aig, log):
- pyabc.run_command(r'read_aiger %s'%aig)
- pyabc.run_command(r'read_status %s'%log)
- return res
-
- with temp_file_names( ['.aig','.log']*len(funcs) ) as tmp:
-
- funcs = [ defer(child)(f, tmp[2*i],tmp[2*i+1]) for i,f in enumerate(funcs) ]
-
- for i, res in split_all_full(funcs):
- yield i, parent(res, tmp[2*i],tmp[2*i+1])
-
-if __name__ == "__main__":
-
- # define some functions to run
-
- def f_1(i):
- return i+1
-
- def f_2(i,j):
- return i*10+j+1
-
- def f_3(i,j,k):
- return i*100+j*10+k+1
-
- # Construct a tuple of the function and arguments for each function
-
- t_1 = (f_1, [1])
- t_2 = (f_2, [1,2])
- t_3 = (f_3, [1,2,3])
-
- # Create a list containing these tuples:
-
- funcs = [t_1, t_2, t_3]
-
- # Use the function split_all() to run these functions in separate processes:
-
- for res in split_all(funcs):
- print res
-
- # Alternatively, quit after the first process returns:
-
- for res in split_all(funcs):
- print res
- break
-
- # For operations with ABC that save and restore status
-
- import pyabc
-
- def abc_f(truth):
- import os
- print "pid=%d, abc_f(%s)"%(os.getpid(), truth)
- pyabc.run_command('read_truth %s'%truth)
- pyabc.run_command('strash')
- return 100
-
- funcs = [
- defer(abc_f)("1000"),
- defer(abc_f)("0001")
- ]
-
- best = None
-
- for i, res in abc_split_all(funcs):
- print i, res
- if best is None:\
- # save state
- best = abc_state()
- pyabc.run_command('write_verilog /dev/stdout')
-
- # if there is a saved state, restore it
- if best is not None:
- best.restore()
- pyabc.run_command('write_verilog /dev/stdout')
diff --git a/src/python/reachx_cmd.py b/src/python/reachx_cmd.py
deleted file mode 100644
index 8461cb1d..00000000
--- a/src/python/reachx_cmd.py
+++ /dev/null
@@ -1,108 +0,0 @@
-# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
-
-import sys
-import optparse
-import subprocess
-import tempfile
-import threading
-import os
-import os.path
-from contextlib import contextmanager, nested
-
-import pyabc
-
-
-def popen_and_wait_with_timeout(timeout,cmd, *args, **kwargs):
- """ Wait for a subprocess.Popen object to terminate, or until timeout (in seconds) expires. """
-
- p = None
- t = None
-
- try:
- p = subprocess.Popen(cmd, *args, **kwargs)
-
- if timeout <= 0:
- timeout = None
-
- t = threading.Thread(target=lambda: p.communicate())
- t.start()
-
- t.join(timeout)
-
- finally:
-
- if p is not None and p.poll() is None:
- p.kill()
-
- if t is not None and t.is_alive():
- t.join()
-
- if p is not None:
- return p.returncode
-
- return -1
-
-@contextmanager
-def temp_file_name(suffix=""):
- file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
- name = file.name
- file.close()
-
- try:
- yield name
- finally:
- os.unlink(name)
-
-def cygpath(path):
- if sys.platform == "win32":
- if os.path.isabs(path):
- drive, tail = os.path.splitdrive(path)
- drive = drive.lower()
- tail = tail.split(os.path.sep)
- return '/cygdrive/%s'%drive[0] + '/'.join(tail)
- else:
- path = path.split(os.path.sep)
- return "/".join(path)
- return path
-
-def run_reachx_cmd(effort, timeout):
- with nested(temp_file_name(suffix=".aig"), temp_file_name()) as (tmpaig_name, tmplog_name):
- pyabc.run_command("write %s"%tmpaig_name)
-
- cmdline = [
- 'read %s'%cygpath(tmpaig_name),
- 'qua_ffix -effort %d -L %s'%(effort, cygpath(tmplog_name)),
- 'quit'
- ]
-
- cmd = ["jabc", "-c", " ; ".join(cmdline)]
-
- rc = popen_and_wait_with_timeout(timeout, cmd, shell=False, stdout=sys.stdout, stderr=sys.stderr)
-
- if rc != 0:
- # jabc failed or stopped. Write a status file to update the status to unknown
- with open(tmplog_name, "w") as f:
- f.write('snl_UNK -1 unknown\n')
- f.write('NULL\n')
- f.write('NULL\n')
-
- pyabc.run_command("read_status %s"%tmplog_name)
-
- return rc
-
-def reachx_cmd(argv):
- usage = "usage: %prog [options]"
-
- parser = optparse.OptionParser(usage, prog="reachx")
-
- parser.add_option("-e", "--effort", dest="effort", type=int, default=0, help="effort level. [default=0, means unlimited]")
- parser.add_option("-t", "--timeout", dest="timeout", type=int, default=0, help="timeout in seconds [default=0, unlimited]")
-
- options, args = parser.parse_args(argv)
-
- rc = run_reachx_cmd(options.effort, options.timeout)
- print "%s command: jabc returned: %d"%(argv[0], rc)
-
- return 0
-
-pyabc.add_abc_command(reachx_cmd, "Verification", "reachx", 0)
diff --git a/src/python/redirect.py b/src/python/redirect.py
deleted file mode 100644
index 0afccb77..00000000
--- a/src/python/redirect.py
+++ /dev/null
@@ -1,111 +0,0 @@
-"""
-
-A simple context manager for redirecting streams in Python.
-The streams are redirected at the the C runtime level so that the output of C extensions
-that use stdio will also be redirected.
-
-null_file : a stream representing the null device (e.g. /dev/null on Unix)
-redirect: a context manager for redirecting streams
-
-Author: Baruch Sterin (sterin@berkeley.edu)
-
-"""
-
-import os
-import sys
-
-from contextlib import contextmanager
-
-null_file = open( os.devnull, "w" )
-
-@contextmanager
-def _dup( f ):
- fd = os.dup( f.fileno() )
- yield fd
- os.close(fd)
-
-@contextmanager
-def save_stdout( src = sys.stdout ):
- """
- Redirect
- """
- fd = os.dup( src.fileno() )
- own = True
-
- try:
- with os.fdopen( fd, "w", 0) as f:
- own = False
- yield f
- except:
- if own:
- os.close(fd)
- raise
-
-@contextmanager
-def redirect(dst = null_file, src = sys.stdout):
-
- """
- Redirect the src stream into dst.
-
- Example:
- with redirect( open("somefile.txt", sys.stdout ) ):
- do some stuff ...
- """
-
- if src.fileno() == dst.fileno():
- yield
- return
-
- with _dup( src ) as fd_dup_src:
-
- dst.flush()
-
- src.flush()
- os.close( src.fileno() )
- os.dup2( dst.fileno(), src.fileno() )
-
- yield
-
- src.flush()
- os.close( src.fileno() )
- os.dup2( fd_dup_src, src.fileno() )
-
-def start_redirect(dst = null_file, src = sys.stdout):
-
- """
- Start redirection of src stream into dst. Return the duplicated file handle of the source.
-
- Example:
- fd = start_redirect( open("somefile.txt"), sys.stdout )
- ... do some stuff ...
- end_redirect(sys.stdout, fd)
- """
-
- if src.fileno() == dst.fileno():
- return None
-
- fd_dup_src = os.dup( src.fileno() )
-
- dst.flush()
- src.flush()
-
- os.close( src.fileno() )
- os.dup2( dst.fileno(), src.fileno() )
-
- return fd_dup_src
-
-def end_redirect(src, fd_dup_src):
-
- """
- End redirection of stream src.Redirect the src stream into dst. src is the source stream and fd_dup_src is the value returned by
- start_redirect()
- """
-
- if fd_dup_src is None:
- return
-
- src.flush()
- os.close( src.fileno() )
- os.dup2( fd_dup_src, src.fileno() )
-
- os.close(fd_dup_src)
diff --git a/src/python/setup.py b/src/python/setup.py
deleted file mode 100644
index 560262d4..00000000
--- a/src/python/setup.py
+++ /dev/null
@@ -1,67 +0,0 @@
-import sys
-
-from distutils.core import setup, Extension
-from distutils.sysconfig import get_config_vars
-from distutils import util
-from distutils.command.build_ext import build_ext
-from distutils import sysconfig
-
-define_macros = []
-libraries = []
-library_dirs = []
-
-if sys.platform == "win32":
-
- src_file = [ 'pyabc.i' ]
-
- define_macros.append( ('WIN32', 1) )
- define_macros.append( ('ABC_DLL', 'ABC_DLLEXPORT') )
-
- libraries.append('abcr')
- library_dirs.append('./../../lib')
-
-else:
-
- src_file = [ 'pyabc_wrap.c' ]
-
- if get_config_vars()['SIZEOF_VOID_P'] > 4:
- define_macros.append( ('LIN64', 1) )
- else:
- define_macros.append( ('LIN', 1) )
-
- libraries.append( 'abc' )
- libraries.append( 'rt' )
- libraries.append( 'readline' )
- library_dirs.append('./../../')
-
-
-# ugly hack to silence strict-prototype warnings
-
-class build_ext_subclass( build_ext ):
-
- def build_extensions(self):
-
- CC = sysconfig.get_config_var("CC")
-
- if self.compiler.compiler_type == 'unix' and ( 'gcc' in CC or 'g++' in CC):
- for e in self.extensions:
- e.extra_compile_args.append( '-Wno-strict-prototypes' )
-
- build_ext.build_extensions(self)
-
-ext = Extension(
- '_pyabc',
- src_file,
- define_macros=define_macros,
- include_dirs = ["../../src"],
- library_dirs=library_dirs,
- libraries=libraries
- )
-
-setup(
- name='pyabc',
- version='1.0',
- ext_modules=[ext],
- py_modules=['pyabc','getch','pyabc_split','redirect', 'reachx_cmd'],
- cmdclass = {'build_ext': build_ext_subclass }
-)