From c9ec1e31bcc7d15b86cc10a1febfc8eb12a90e77 Mon Sep 17 00:00:00 2001 From: Zuzana Baranova <xbaranov@fi.muni.cz> Date: Thu, 20 Jun 2019 09:12:53 +0000 Subject: [PATCH] CC: Move compile() into cc/native.{hpp,cpp}, rename to compileFiles(). --- divine/cc/native.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ divine/cc/native.hpp | 33 +++++++++++++++++++++++++++++++++ tools/divcc.cpp | 28 +++++++--------------------- 3 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 divine/cc/native.cpp create mode 100644 divine/cc/native.hpp diff --git a/divine/cc/native.cpp b/divine/cc/native.cpp new file mode 100644 index 000000000..173395f4b --- /dev/null +++ b/divine/cc/native.cpp @@ -0,0 +1,40 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- + +/* + * (c) 2019 Zuzana Baranová <xbaranov@fi.muni.cz> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <divine/cc/codegen.hpp> +#include <divine/cc/link.hpp> +#include <divine/cc/options.hpp> + +#include <brick-proc> + +namespace divine::cc +{ + int compileFiles( cc::ParsedOpts& po, cc::CC1& clang, PairedFiles& objFiles ) + { + for ( auto file : objFiles ) + { + if ( file.first == "lib" ) + continue; + if ( cc::is_object_type( file.first ) ) + continue; + auto mod = clang.compile( file.first, po.opts ); + cc::emit_obj_file( *mod, file.second ); + } + return 0; + } +} diff --git a/divine/cc/native.hpp b/divine/cc/native.hpp new file mode 100644 index 000000000..718506f81 --- /dev/null +++ b/divine/cc/native.hpp @@ -0,0 +1,33 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- +#pragma once + +/* + * (c) 2019 Zuzana Baranová <xbaranov@fi.muni.cz> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <divine/cc/options.hpp> + +namespace divine::cc +{ + /* PairedFiles is used for mapping IN => OUT filenames at compilation, + * or checking whether to compile a given file, + * i.e. file.c => compiled to file.o; file.o => will not be compiled, + * similarly for archives; the naming can further be affected by the -o + * option. + */ + using PairedFiles = std::vector< std::pair< std::string, std::string > >; + + int compileFiles( ParsedOpts& po, CC1& clang, PairedFiles& objFiles ); +} diff --git a/tools/divcc.cpp b/tools/divcc.cpp index d34eab90b..2df23ef54 100644 --- a/tools/divcc.cpp +++ b/tools/divcc.cpp @@ -21,6 +21,7 @@ #include <divine/cc/codegen.hpp> #include <divine/cc/filetype.hpp> #include <divine/cc/link.hpp> +#include <divine/cc/native.hpp> #include <divine/cc/options.hpp> #include <divine/rt/dios-cc.hpp> #include <divine/rt/runtime.hpp> @@ -43,32 +44,15 @@ using namespace divine; using namespace llvm; using namespace brick::types; -using PairedFiles = std::vector< std::pair< std::string, std::string > >; using FileType = cc::FileType; { using namespace brick::fs; -int compile( cc::ParsedOpts& po, cc::CC1& clang, PairedFiles& objFiles ) -{ - for ( auto file : objFiles ) - { - if ( file.first == "lib" ) - continue; - if ( cc::is_object_type( file.first ) ) - continue; - auto mod = clang.compile( file.first, po.opts ); - cc::emit_obj_file( *mod, file.second ); - } - return 0; -} - int compile_and_link( cc::ParsedOpts& po, cc::CC1& clang, PairedFiles& objFiles, bool cxx = false ) { auto diosCC = std::make_unique< rt::DiosCC >( clang.context() ); std::vector< const char * > ld_args_c; - compile( po, clang, objFiles ); - using namespace brick::fs; TempDir tmpdir( ".divcc.XXXXXX", AutoDelete::Yes, UseSystemTemp::Yes ); auto hostlib = tmpdir.path + "/libdios-host.a", @@ -136,7 +120,7 @@ int main( int argc, char **argv ) cc::CC1 clang; clang.allowIncludePath( "/" ); divine::rt::each( [&]( auto path, auto c ) { clang.mapVirtualFile( path, c ); } ); - PairedFiles objFiles; + cc::PairedFiles objFiles; std::vector< std::string > opts; std::copy( argv + 1, argv + argc, std::back_inserter( opts ) ); @@ -219,10 +203,12 @@ int main( int argc, char **argv ) } if ( po.toObjectOnly ) - return compile( po, clang, objFiles ); + return cc::compileFiles( po, clang, objFiles ); else - return compile_and_link( po, clang, objFiles, - brick::string::endsWith( argv[0], "divc++" ) ); + { + cc::compileFiles( po, clang, objFiles ); + return compile_and_link( po, clang, objFiles, brick::string::endsWith( argv[0], "divc++" ) ); + } } catch ( cc::CompileError &err ) { std::cerr << err.what() << std::endl; -- GitLab