mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 04:03:39 +00:00
Refactor `mk_mem_initializer_cpp()
` so that it is usable externally via a new
function ``mk_mem_initializer_cpp_internal()`` which is called by a new ``mk_mem_initializer_cpp.py`` script. This will allow other build systems to generate the ``mem_initializer.cpp`` files.
This commit is contained in:
parent
a13438818f
commit
2f7f022605
48
scripts/mk_mem_initializer_cpp.py
Executable file
48
scripts/mk_mem_initializer_cpp.py
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
Scans the source directories for
|
||||||
|
memory initializers and finalizers and
|
||||||
|
emits and implementation of
|
||||||
|
``void mem_initialize()`` and
|
||||||
|
``void mem_finalize()`` into ``mem_initializer.cpp``
|
||||||
|
in the destination directory.
|
||||||
|
"""
|
||||||
|
import mk_util
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def check_dir(path):
|
||||||
|
if not os.path.exists(path):
|
||||||
|
logging.error('"{}" does not exist'.format(path))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
logging.error('"{}" is not a directory'.format(path))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("destination_dir", help="destination directory")
|
||||||
|
parser.add_argument("source_dirs", nargs="+",
|
||||||
|
help="One or more source directories to search")
|
||||||
|
pargs = parser.parse_args(args)
|
||||||
|
|
||||||
|
if check_dir(pargs.destination_dir) != 0:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
for source_dir in pargs.source_dirs:
|
||||||
|
if check_dir(source_dir) != 0:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
mk_util.mk_mem_initializer_cpp_internal(pargs.source_dirs, pargs.destination_dir)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main(sys.argv[1:]))
|
||||||
|
|
|
@ -2752,6 +2752,13 @@ def mk_all_install_tactic_cpps():
|
||||||
# void mem_finalize()
|
# void mem_finalize()
|
||||||
# These procedures are invoked by the Z3 memory_manager
|
# These procedures are invoked by the Z3 memory_manager
|
||||||
def mk_mem_initializer_cpp(cnames, path):
|
def mk_mem_initializer_cpp(cnames, path):
|
||||||
|
component_src_dirs = []
|
||||||
|
for cname in cnames:
|
||||||
|
c = get_component(cname)
|
||||||
|
component_src_dirs.append(c.src_dir)
|
||||||
|
mk_mem_initializer_cpp_internal(component_src_dirs, path)
|
||||||
|
|
||||||
|
def mk_mem_initializer_cpp_internal(component_src_dirs, path):
|
||||||
initializer_cmds = []
|
initializer_cmds = []
|
||||||
finalizer_cmds = []
|
finalizer_cmds = []
|
||||||
fullname = os.path.join(path, 'mem_initializer.cpp')
|
fullname = os.path.join(path, 'mem_initializer.cpp')
|
||||||
|
@ -2761,12 +2768,11 @@ def mk_mem_initializer_cpp(cnames, path):
|
||||||
# ADD_INITIALIZER with priority
|
# ADD_INITIALIZER with priority
|
||||||
initializer_prio_pat = re.compile('[ \t]*ADD_INITIALIZER\(\'([^\']*)\',[ \t]*(-?[0-9]*)\)')
|
initializer_prio_pat = re.compile('[ \t]*ADD_INITIALIZER\(\'([^\']*)\',[ \t]*(-?[0-9]*)\)')
|
||||||
finalizer_pat = re.compile('[ \t]*ADD_FINALIZER\(\'([^\']*)\'\)')
|
finalizer_pat = re.compile('[ \t]*ADD_FINALIZER\(\'([^\']*)\'\)')
|
||||||
for cname in cnames:
|
for component_src_dir in component_src_dirs:
|
||||||
c = get_component(cname)
|
h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(component_src_dir))
|
||||||
h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(c.src_dir))
|
|
||||||
for h_file in h_files:
|
for h_file in h_files:
|
||||||
added_include = False
|
added_include = False
|
||||||
fin = open(os.path.join(c.src_dir, h_file), 'r')
|
fin = open(os.path.join(component_src_dir, h_file), 'r')
|
||||||
for line in fin:
|
for line in fin:
|
||||||
m = initializer_pat.match(line)
|
m = initializer_pat.match(line)
|
||||||
if m:
|
if m:
|
||||||
|
|
Loading…
Reference in a new issue