-
Notifications
You must be signed in to change notification settings - Fork 168
Refactoring compiler #914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactoring compiler #914
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4689a28
Refactoring compiler to codecompiler, and moving to new compilation d…
erikvansebille 83f5559
Fixing a bug where lib pathnames were set wrongly
erikvansebille 83f8a11
Fixing compilation for rng.py too
erikvansebille 907d75a
Removing codeinterface and multi-file codecompiler classes, as they a…
erikvansebille 8cdc391
Fixing random number unt test in kernel_language
erikvansebille 6f564a4
Minor code cleanup
erikvansebille eaaa1d3
Fixing suggestions from @angus-g
erikvansebille 39fc90f
Update parcels/compilation/codecompiler.py
CKehl 85fe370
Refactoring compiler to codecompiler, and moving to new compilation d…
erikvansebille e37eb39
Fixing a bug where lib pathnames were set wrongly
erikvansebille 6c93923
Fixing compilation for rng.py too
erikvansebille 1bc0d93
Removing codeinterface and multi-file codecompiler classes, as they a…
erikvansebille d816270
Fixing random number unt test in kernel_language
erikvansebille e7c1a2c
Minor code cleanup
erikvansebille c72eed9
Fixing suggestions from @angus-g
erikvansebille 46d751d
Merge branch 'master' into refactoring_compiler
CKehl 5281b73
#914 - corrected botched merge in rng.py
CKehl a8414a2
Merge branch 'refactoring_compiler' of github.com:OceanParcels/parcel…
CKehl 641aec7
Merge branch 'master' into refactoring_compiler
erikvansebille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from .codegenerator import * # noqa | ||
| from .codecompiler import * # noqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,271 @@ | ||
| import os | ||
| import subprocess | ||
| from struct import calcsize | ||
|
|
||
| try: | ||
| from mpi4py import MPI | ||
| except: | ||
| MPI = None | ||
|
|
||
|
|
||
| class Compiler_parameters(object): | ||
| def __init__(self): | ||
| self._compiler = "" | ||
| self._cppargs = [] | ||
| self._ldargs = [] | ||
| self._incdirs = [] | ||
| self._libdirs = [] | ||
| self._libs = [] | ||
| self._dynlib_ext = "" | ||
| self._stclib_ext = "" | ||
| self._obj_ext = "" | ||
| self._exe_ext = "" | ||
|
|
||
| @property | ||
| def compiler(self): | ||
| return self._compiler | ||
|
|
||
| @property | ||
| def cppargs(self): | ||
| return self._cppargs | ||
|
|
||
| @property | ||
| def ldargs(self): | ||
| return self._ldargs | ||
|
|
||
| @property | ||
| def incdirs(self): | ||
| return self._incdirs | ||
|
|
||
| @property | ||
| def libdirs(self): | ||
| return self._libdirs | ||
|
|
||
| @property | ||
| def libs(self): | ||
| return self._libs | ||
|
|
||
| @property | ||
| def dynlib_ext(self): | ||
| return self._dynlib_ext | ||
|
|
||
| @property | ||
| def stclib_ext(self): | ||
| return self._stclib_ext | ||
|
|
||
| @property | ||
| def obj_ext(self): | ||
| return self._obj_ext | ||
|
|
||
| @property | ||
| def exe_ext(self): | ||
| return self._exe_ext | ||
|
|
||
|
|
||
| class GNU_parameters(Compiler_parameters): | ||
| def __init__(self, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None): | ||
| super(GNU_parameters, self).__init__() | ||
| if cppargs is None: | ||
| cppargs = [] | ||
| if ldargs is None: | ||
| ldargs = [] | ||
| if incdirs is None: | ||
| incdirs = [] | ||
| if libdirs is None: | ||
| libdirs = [] | ||
| if libs is None: | ||
| libs = [] | ||
|
|
||
| Iflags = [] | ||
| if isinstance(incdirs, list): | ||
| for i, dir in enumerate(incdirs): | ||
| Iflags.append("-I"+dir) | ||
| Lflags = [] | ||
| if isinstance(libdirs, list): | ||
| for i, dir in enumerate(libdirs): | ||
| Lflags.append("-L"+dir) | ||
| lflags = [] | ||
| if isinstance(libs, list): | ||
| for i, lib in enumerate(libs): | ||
| lflags.append("-l" + lib) | ||
|
|
||
| cc_env = os.getenv('CC') | ||
| self._compiler = "mpicc" if MPI else "gcc" if cc_env is None else cc_env | ||
| opt_flags = ['-g', '-O3'] | ||
| arch_flag = ['-m64' if calcsize("P") == 8 else '-m32'] | ||
| self._cppargs = ['-Wall', '-fPIC'] | ||
| self._cppargs += Iflags | ||
| self._cppargs += opt_flags + cppargs + arch_flag | ||
| self._ldargs = ['-shared'] | ||
| self._ldargs += Lflags | ||
| self._ldargs += lflags | ||
| self._ldargs += ldargs | ||
| if len(Lflags) > 0: | ||
| self._ldargs += ['-Wl, -rpath=%s' % (":".join(libdirs))] | ||
erikvansebille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self._ldargs += arch_flag | ||
| self._incdirs = incdirs | ||
| self._libdirs = libdirs | ||
| self._libs = libs | ||
| self._dynlib_ext = "so" | ||
| self._stclib_ext = "a" | ||
| self._obj_ext = "o" | ||
| self._exe_ext = "" | ||
|
|
||
|
|
||
| class Clang_parameters(Compiler_parameters): | ||
| def __init__(self, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None): | ||
| super(Clang_parameters, self).__init__() | ||
| if cppargs is None: | ||
| cppargs = [] | ||
| if ldargs is None: | ||
| ldargs = [] | ||
| if incdirs is None: | ||
| incdirs = [] | ||
| if libdirs is None: | ||
| libdirs = [] | ||
| if libs is None: | ||
| libs = [] | ||
angus-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self._compiler = "cc" | ||
angus-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self._cppargs = cppargs | ||
| self._ldargs = ldargs | ||
| self._incdirs = incdirs | ||
| self._libdirs = libdirs | ||
| self._libs = libs | ||
| self._dynlib_ext = "dynlib" | ||
| self._stclib_ext = "a" | ||
| self._obj_ext = "o" | ||
| self._exe_ext = "exe" | ||
|
|
||
|
|
||
| class MinGW_parameters(Compiler_parameters): | ||
| def __init__(self, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None): | ||
| super(MinGW_parameters, self).__init__() | ||
| if cppargs is None: | ||
| cppargs = [] | ||
| if ldargs is None: | ||
| ldargs = [] | ||
| if incdirs is None: | ||
| incdirs = [] | ||
| if libdirs is None: | ||
| libdirs = [] | ||
| if libs is None: | ||
| libs = [] | ||
| self._compiler = "gcc" | ||
| self._cppargs = cppargs | ||
| self._ldargs = ldargs | ||
| self._incdirs = incdirs | ||
| self._libdirs = libdirs | ||
| self._libs = libs | ||
| self._dynlib_ext = "so" | ||
| self._stclib_ext = "a" | ||
| self._obj_ext = "o" | ||
| self._exe_ext = "exe" | ||
|
|
||
|
|
||
| class VS_parameters(Compiler_parameters): | ||
| def __init__(self, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None): | ||
| super(VS_parameters, self).__init__() | ||
| if cppargs is None: | ||
| cppargs = [] | ||
| if ldargs is None: | ||
| ldargs = [] | ||
| if incdirs is None: | ||
| incdirs = [] | ||
| if libdirs is None: | ||
| libdirs = [] | ||
| if libs is None: | ||
| libs = [] | ||
| self._compiler = "cl" | ||
| self._cppargs = cppargs | ||
| self._ldargs = ldargs | ||
| self._incdirs = incdirs | ||
| self._libdirs = libdirs | ||
| self._libs = libs | ||
| self._dynlib_ext = "dll" | ||
| self._stclib_ext = "lib" | ||
| self._obj_ext = "obj" | ||
| self._exe_ext = "exe" | ||
|
|
||
|
|
||
| class CCompiler(object): | ||
| """A compiler object for creating and loading shared libraries. | ||
|
|
||
| :arg cc: C compiler executable (uses environment variable ``CC`` if not provided). | ||
| :arg cppargs: A list of arguments to the C compiler (optional). | ||
| :arg ldargs: A list of arguments to the linker (optional).""" | ||
|
|
||
| def __init__(self, cc=None, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None, tmp_dir=os.getcwd()): | ||
| if cppargs is None: | ||
| cppargs = [] | ||
| if ldargs is None: | ||
| ldargs = [] | ||
|
|
||
| self._cc = os.getenv('CC') if cc is None else cc | ||
| self._cppargs = cppargs | ||
| self._ldargs = ldargs | ||
| self._dynlib_ext = "" | ||
| self._stclib_ext = "" | ||
| self._obj_ext = "" | ||
| self._exe_ext = "" | ||
| self._tmp_dir = tmp_dir | ||
|
|
||
| def compile(self, src, obj, log): | ||
| pass | ||
|
|
||
| def _create_compile_process_(self, cmd, src, log): | ||
| with open(log, 'w') as logfile: | ||
| try: | ||
| subprocess.check_call(cmd, stdout=logfile, stderr=logfile) | ||
| except OSError: | ||
| err = """OSError during compilation | ||
| Please check if compiler exists: %s""" % self._cc | ||
| raise RuntimeError(err) | ||
| except subprocess.CalledProcessError: | ||
| with open(log, 'r') as logfile2: | ||
| err = """Error during compilation: | ||
| Compilation command: %s | ||
| Source/Destination file: %s | ||
| Log file: %s | ||
|
|
||
| Log output: %s""" % (" ".join(cmd), src, logfile.name, logfile2.read()) | ||
| raise RuntimeError(err) | ||
| return True | ||
|
|
||
|
|
||
| class CCompiler_SS(CCompiler): | ||
| """ | ||
| single-stage C-compiler; used for a SINGLE source file | ||
| """ | ||
| def __init__(self, cc=None, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None, tmp_dir=os.getcwd()): | ||
| super(CCompiler_SS, self).__init__(cc=cc, cppargs=cppargs, ldargs=ldargs, incdirs=incdirs, libdirs=libdirs, libs=libs, tmp_dir=tmp_dir) | ||
|
|
||
| def compile(self, src, obj, log): | ||
| cc = [self._cc] + self._cppargs + ['-o', obj, src] + self._ldargs | ||
| with open(log, 'w') as logfile: | ||
| logfile.write("Compiling: %s\n" % " ".join(cc)) | ||
| self._create_compile_process_(cc, src, log) | ||
|
|
||
|
|
||
| class GNUCompiler_SS(CCompiler_SS): | ||
| """A compiler object for the GNU Linux toolchain. | ||
|
|
||
| :arg cppargs: A list of arguments to pass to the C compiler | ||
| (optional). | ||
| :arg ldargs: A list of arguments to pass to the linker (optional).""" | ||
| def __init__(self, cppargs=None, ldargs=None, incdirs=None, libdirs=None, libs=None, tmp_dir=os.getcwd()): | ||
| c_params = GNU_parameters(cppargs, ldargs, incdirs, libdirs, libs) | ||
| super(GNUCompiler_SS, self).__init__(c_params.compiler, cppargs=c_params.cppargs, ldargs=c_params.ldargs, incdirs=c_params.incdirs, libdirs=c_params.libdirs, libs=c_params.libs, tmp_dir=tmp_dir) | ||
| self._dynlib_ext = c_params.dynlib_ext | ||
| self._stclib_ext = c_params.stclib_ext | ||
| self._obj_ext = c_params.obj_ext | ||
| self._exe_ext = c_params.exe_ext | ||
|
|
||
| def compile(self, src, obj, log): | ||
| lib_pathfile = os.path.basename(obj) | ||
| lib_pathdir = os.path.dirname(obj) | ||
| obj = os.path.join(lib_pathdir, lib_pathfile) | ||
|
|
||
| super(GNUCompiler_SS, self).compile(src, obj, log) | ||
|
|
||
|
|
||
| GNUCompiler = GNUCompiler_SS | ||
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.