Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73477 - in sandbox/tools/profile_templates2: . src
From: dsaritz_at_[hidden]
Date: 2011-08-01 12:41:47


Author: psiha
Date: 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
New Revision: 73477
URL: http://svn.boost.org/trac/boost/changeset/73477

Log:
A first step/attempt towards making a single binary.
Moved all sources to the src directory.
Added the profiler.cpp which holds the single main() function.
Added:
   sandbox/tools/profile_templates2/src/filter.hpp (contents, props changed)
   sandbox/tools/profile_templates2/src/postprocess.hpp (contents, props changed)
   sandbox/tools/profile_templates2/src/preprocess.cpp
      - copied, changed from r73474, /sandbox/tools/profile_templates2/preprocess.cpp
   sandbox/tools/profile_templates2/src/preprocess.hpp (contents, props changed)
   sandbox/tools/profile_templates2/src/profiler.cpp (contents, props changed)
Removed:
   sandbox/tools/profile_templates2/preprocess.cpp
   sandbox/tools/profile_templates2/src/Jamfile.v2
Text files modified:
   sandbox/tools/profile_templates2/profiler.cmake | 57 ++++++++++++++------------
   sandbox/tools/profile_templates2/src/filter.cpp | 10 ---
   sandbox/tools/profile_templates2/src/postprocess.cpp | 4 +
   sandbox/tools/profile_templates2/src/preprocess.cpp | 85 ++++++++++++++++------------------------
   4 files changed, 70 insertions(+), 86 deletions(-)

Deleted: sandbox/tools/profile_templates2/preprocess.cpp
==============================================================================
--- sandbox/tools/profile_templates2/preprocess.cpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
+++ (empty file)
@@ -1,198 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-///
-/// \file preprocess.cpp
-/// --------------------
-///
-/// Copyright (c) 2008.-2009. Steven Watanabe (preprocess.pl)
-/// Copyright (c) 2011. Domagoj Saric
-///
-/// Use, modification and distribution is subject to the
-/// Boost Software License, Version 1.0.
-/// (See accompanying file LICENSE_1_0.txt or copy at
-/// http://www.boost.org/LICENSE_1_0.txt)
-///
-/// For more information, see http://www.boost.org
-///
-////////////////////////////////////////////////////////////////////////////////
-//------------------------------------------------------------------------------
-#undef BOOST_ENABLE_ASSERT_HANDLER
-
-#define BOOST_XPRESSIVE_USE_C_TRAITS
-
-#include "boost/assert.hpp"
-#include "boost/concept_check.hpp"
-#include "boost/interprocess/file_mapping.hpp"
-#include "boost/interprocess/mapped_region.hpp"
-#include "boost/range/iterator_range_core.hpp"
-#include "boost/xpressive/xpressive.hpp"
-
-#include <cassert>
-#include <iterator>
-#include <iostream>
-//------------------------------------------------------------------------------
-
-namespace regex
-{
- using namespace boost::xpressive;
-
- cregex make_parens()
- {
- cregex parens;// parens = keep( '(' >> *keep( keep( +keep( ignored | ~(set= '(',')') ) | ( -!by_ref( parens ) ) ) ) >> ')' );
- parens =
- '(' // is an opening parenthesis ...
- >> // followed by ...
- *( // zero or more ...
- keep( +~(set='(',')') ) // of a bunch of things that are not parentheses ...
- | // or ...
- by_ref(parens) // a balanced set of parentheses
- ) // (ooh, recursion!) ...
- >> // followed by ...
- ')' // a closing parenthesis
- ;
- return parens;
- }
-
- //cregex const backslashed_lines = keep( keep( *( '\\' >> keep( _ln ) | ~_ln ) ) ); //...zzz...!?
- cregex const string = keep( '"' >> *keep( as_xpr( "\\\\" ) | "\\\"" | ~(set='"') ) >> '"' | '\'' >> *keep( as_xpr( "\\\\" ) | "\\'" | ~(set='\'') ) >> '\'' );
- cregex const comment = keep( "//" /*>> backslashed_lines*/ | "/*" >> keep( *( ~(set='*') | '*' >> ~before('/') ) ) >> "*/" );
- cregex const pp = keep( '#' >> /*backslashed_lines*/ -*~_ln >> _ln );
- cregex const ignored = keep( string | comment | pp );
- cregex const parens = make_parens();
- cregex const ws = comment | pp | _s | _ln;
-
- cregex const class_header =
- keep
- (
- keep( _b >> ( as_xpr( "class" ) | "struct" ) ) >>
- keep( +ws >> +_w ) >>
- keep( *keep( ~(set= '(',')','{',';','=') | parens | ignored ) ) >>
- '{'
- );
-
- cregex const control = ( _b >> ( as_xpr( "__attribute__" ) | "__if_exists" | "__if_not_exists" | "for" | "while" | "if" | "catch" | "switch" ) >> _b );
- cregex const modifiers = ( _b >> ( as_xpr( "try" ) | "const" | "volatile" ) >> _b );
- cregex const start = ( bos /*| cregex::compile( "\\G" )*/ | after( (set= '{','}',';') ) ) >> keep( *ws );
- cregex const body = ~before( control ) >> keep( ignored | ~(set= '{','}',';') );
- cregex const end = parens | ']';
- cregex const body_start = keep( *ws >> *(modifiers >> *ws) >> '{' );
-
- cregex const function_header = keep( start >> ( *body >> end ) >> body_start );
-}
-
-struct formatter : boost::noncopyable
-{
- template<typename Out>
- Out operator()( regex::cmatch const & what, Out out ) const
- {
- using namespace regex;
-
- typedef cmatch::value_type sub_match;
-
- BOOST_ASSERT( what.size() == 5 );
-
- cmatch::const_iterator const p_match( std::find_if( what.begin() + 1, what.end(), []( sub_match const & match ){ return match.matched; } ) );
- BOOST_ASSERT_MSG( p_match != what.end(), "Something should have matched." );
- sub_match const & match( *p_match );
-
- enum match_type_t
- {
- ignore = 1,
- header,
- open_brace,
- close_brace
- };
-
- unsigned int const match_type( p_match - what.begin() );
- switch ( match_type )
- {
- case ignore:
- out = std::copy( match.first, match.second, out );
- break;
-
- case header:
- {
- braces.push_back( " TEMPLATE_PROFILE_EXIT() }" );
- static char const tail[] = " TEMPLATE_PROFILE_ENTER()";
- out = std::copy( match.first , match.second , out );
- out = std::copy( boost::begin( tail ), boost::end( tail ) - 1, out );
- break;
- }
-
- case open_brace:
- braces.push_back( "}" );
- out = std::copy( match.first, match.second, out );
- break;
-
- case close_brace:
- out = std::copy( braces.back().begin(), braces.back().end(), out );
- braces.pop_back();
- break;
-
- default:
- BOOST_ASSERT( false );
- break;
- }
-
- return out;
- }
-
- mutable std::vector<std::string> braces;
-};
-
-
-int main( int const argc, char * * const argv )
-{
- if ( argc != 2 )
- return EXIT_FAILURE;
-
- try
- {
- using namespace boost;
-
- interprocess::mapped_region const input_file_view
- (
- interprocess::file_mapping
- (
- argv[ 1 ],
- interprocess::read_only
- ),
- interprocess::read_only
- );
-
- iterator_range<char const *> input
- (
- static_cast<char const *>( input_file_view.get_address() ),
- static_cast<char const *>( input_file_view.get_address() ) + input_file_view.get_size()
- );
-
- using namespace regex;
- cregex const main_regex( (s1= ignored) | (s2=keep( class_header | function_header )) | (s3='{') | (s4='}') );
- match_results<char const *> search_results;
-
- std::cout << "#include <template_profiler.hpp>\n" << std::endl;
-
- // Implementation note:
- // The whole file has to be searched at once in order to handle class/
- // function definitions over several lines.
- // (01.08.2011.) (Domagoj Saric)
- regex_replace
- (
- std::ostream_iterator<char>( std::cout ),
- input.begin(),
- input.end(),
- main_regex,
- formatter()
- );
-
- return EXIT_SUCCESS;
- }
- catch ( std::exception const & e )
- {
- std::puts( e.what() );
- return EXIT_FAILURE;
- }
- catch ( ... )
- {
- return EXIT_FAILURE;
- }
-}

Modified: sandbox/tools/profile_templates2/profiler.cmake
==============================================================================
--- sandbox/tools/profile_templates2/profiler.cmake (original)
+++ sandbox/tools/profile_templates2/profiler.cmake 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -12,20 +12,24 @@
 ################################################################################
 
 ################################################################################
-# Add the target to build filter and postprocess
+# Add the target to build profiler
 ################################################################################
-FIND_FILE(PROFILER_PATH profiler ${CMAKE_MODULE_PATH})
+find_file(PROFILER_PATH profiler ${CMAKE_MODULE_PATH})
 
-ADD_EXECUTABLE(template.profiler.filter ${PROFILER_PATH}/filter.cpp)
-set_property(TARGET template.profiler.filter PROPERTY RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tools)
-
-INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
-ADD_EXECUTABLE(template.profiler.preprocess ${PROFILER_PATH}/preprocess.cpp)
-set_property(TARGET template.profiler.preprocess PROPERTY RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tools)
-ADD_EXECUTABLE(template.profiler.postprocess ${PROFILER_PATH}/postprocess.cpp)
-set_property(TARGET template.profiler.postprocess PROPERTY RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tools)
+include_directories( ${Boost_INCLUDE_DIRS} )
+add_executable(
+ template.profiler
+ ${PROFILER_PATH}/src/preprocess.cpp
+ ${PROFILER_PATH}/src/preprocess.hpp
+ ${PROFILER_PATH}/src/filter.cpp
+ ${PROFILER_PATH}/src/filter.hpp
+ ${PROFILER_PATH}/src/postprocess.cpp
+ ${PROFILER_PATH}/src/postprocess.hpp
+ ${PROFILER_PATH}/src/profiler.cpp
+)
+set_property(TARGET template.profiler PROPERTY RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tools)
 if (NOT MSVC) # Use autolink for MSVC
- target_link_libraries(template.profiler.postprocess ${Boost_LIBRARIES})
+ target_link_libraries(template.profiler ${Boost_LIBRARIES})
 endif()
 
 ################################################################################
@@ -47,21 +51,22 @@
   foreach(INCLUDE ${INCLUDES})
     set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES} -I\"${INCLUDE}\"" )
   endforeach()
- message( "${CMAKE_CXX_COMPILER} ${profiler_cxx_flags} ${INCLUDE_DIRECTORIES} -E \"${CMAKE_CURRENT_SOURCE_DIR}/${src}\" > ${target}.compiler.preprocessed.cpp && \"${PROJECT_BINARY_DIR}/tools/${CMAKE_CFG_INTDIR}/template.profiler.preprocess\" ${target}.compiler.preprocessed.cpp > ${target}.preprocessed.cpp" )
- add_custom_command(OUTPUT ${target}.preprocessed.cpp
- COMMAND ${CMAKE_CXX_COMPILER} ${profiler_cxx_flags} ${INCLUDE_DIRECTORIES} -E "${CMAKE_CURRENT_SOURCE_DIR}/${src}" > ${target}.compiler.preprocessed.cpp
- && \"${PROJECT_BINARY_DIR}/tools/${CMAKE_CFG_INTDIR}/template.profiler.preprocess\" ${target}.compiler.preprocessed.cpp > ${target}.preprocessed.cpp
+
+ if ( NOT EXISTS ${CMAKE_CXX_COMPILER} )
+ if ( MSVC )
+ get_filename_component( devenv_path ${CMAKE_MAKE_PROGRAM} PATH )
+ set( full_compiler_path "${devenv_path}/../../VS/bin/${CMAKE_CXX_COMPILER}" )
+ file( TO_NATIVE_PATH ${full_compiler_path} full_compiler_path )
+ set( ENV{PATH} "$ENV{PATH};$(ExecutablePath)" )
+ elseif()
+ find_program( full_compiler_path "${CMAKE_CXX_COMPILER}" )
+ endif()
+ endif()
+
+ add_custom_command(OUTPUT ${target}.template_profile
+ COMMAND echo "${profiler_cxx_flags} ${INCLUDE_DIRECTORIES}" > ${target}.compiler_options.rsp
+ COMMAND "${PROJECT_BINARY_DIR}/tools/${CMAKE_CFG_INTDIR}/template.profiler" "${full_compiler_path}" ${target}.compiler_options.rsp "${CMAKE_CURRENT_SOURCE_DIR}/${src}"
                      DEPENDS ${src}
                    )
- add_custom_command(OUTPUT ${target}.template_profile
- COMMAND ${CMAKE_CXX_COMPILER} ${profiler_cxx_flags} -I${PROFILER_PATH} ${INCLUDE_DIRECTORIES} -c -DPROFILE_TEMPLATES ${target}.preprocessed.cpp 2>&1
- | \"${PROJECT_BINARY_DIR}/tools/${CMAKE_CFG_INTDIR}/template.profiler.filter\" ${ARGN} > ${target}.filtered && \"${PROJECT_BINARY_DIR}/tools/${CMAKE_CFG_INTDIR}/template.profiler.postprocess\" ${ARGN} ${target}.filtered > ${target}.template_profile
- DEPENDS ${target}.preprocessed.cpp
- template.profiler.preprocess
- template.profiler.filter
- template.profiler.postprocess
- )
- add_custom_target (${target}
- DEPENDS ${target}.template_profile
- )
+ add_custom_target( ${target} DEPENDS ${target}.template_profile )
 endfunction()

Deleted: sandbox/tools/profile_templates2/src/Jamfile.v2
==============================================================================
--- sandbox/tools/profile_templates2/src/Jamfile.v2 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
+++ (empty file)
@@ -1,14 +0,0 @@
-# Jamfile.v2
-#
-# Copyright (c) 2008
-# Steven Watanabe
-#
-# Distributed under the Boost Software License, Version 1.0. (See
-# accompanying file LICENSE_1_0.txt or copy at
-# http://www.boost.org/LICENSE_1_0.txt)
-
-project src : :
- requirements <link>static ;
-
-exe postprocess : postprocess.cpp /boost//regex : <variant>release ;
-exe filter : filter.cpp /boost//regex : <variant>release ;

Modified: sandbox/tools/profile_templates2/src/filter.cpp
==============================================================================
--- sandbox/tools/profile_templates2/src/filter.cpp (original)
+++ sandbox/tools/profile_templates2/src/filter.cpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -7,6 +7,8 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#undef BOOST_ENABLE_ASSERT_HANDLER
+
 #include <string>
 #include <cstdio>
 #include <cstring>
@@ -134,11 +136,3 @@
     #error Unknown compiler
 #endif
 }
-
-int main(int argc, char** argv) {
- if(argc == 2 && std::strcmp(argv[1], "--call-graph") == 0) {
- copy_call_graph();
- } else {
- copy_flat_only();
- }
-}

Added: sandbox/tools/profile_templates2/src/filter.hpp
==============================================================================
--- (empty file)
+++ sandbox/tools/profile_templates2/src/filter.hpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -0,0 +1,3 @@
+
+void copy_call_graph();
+void copy_flat_only ();
\ No newline at end of file

Modified: sandbox/tools/profile_templates2/src/postprocess.cpp
==============================================================================
--- sandbox/tools/profile_templates2/src/postprocess.cpp (original)
+++ sandbox/tools/profile_templates2/src/postprocess.cpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -7,6 +7,8 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#undef BOOST_ENABLE_ASSERT_HANDLER
+
 #include <boost/regex.hpp>
 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
@@ -150,7 +152,7 @@
     node root;
 };
 
-int main(int argc, char** argv) {
+int postprocess(int argc, char** argv) {
     const char* input_file_name = 0;
     bool use_call_graph = false;
     for(int i = 1; i < argc; ++i) {

Added: sandbox/tools/profile_templates2/src/postprocess.hpp
==============================================================================
--- (empty file)
+++ sandbox/tools/profile_templates2/src/postprocess.hpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -0,0 +1,2 @@
+
+void postprocess();
\ No newline at end of file

Copied: sandbox/tools/profile_templates2/src/preprocess.cpp (from r73474, /sandbox/tools/profile_templates2/preprocess.cpp)
==============================================================================
--- /sandbox/tools/profile_templates2/preprocess.cpp (original)
+++ sandbox/tools/profile_templates2/src/preprocess.cpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -140,59 +140,42 @@
 };
 
 
-int main( int const argc, char * * const argv )
+void preprocess( char const * const p_filename )
 {
- if ( argc != 2 )
- return EXIT_FAILURE;
+ using namespace boost;
 
- try
- {
- using namespace boost;
-
- interprocess::mapped_region const input_file_view
+ interprocess::mapped_region const input_file_view
+ (
+ interprocess::file_mapping
         (
- interprocess::file_mapping
- (
- argv[ 1 ],
- interprocess::read_only
- ),
+ p_filename,
             interprocess::read_only
- );
-
- iterator_range<char const *> input
- (
- static_cast<char const *>( input_file_view.get_address() ),
- static_cast<char const *>( input_file_view.get_address() ) + input_file_view.get_size()
- );
-
- using namespace regex;
- cregex const main_regex( (s1= ignored) | (s2=keep( class_header | function_header )) | (s3='{') | (s4='}') );
- match_results<char const *> search_results;
-
- std::cout << "#include <template_profiler.hpp>\n" << std::endl;
-
- // Implementation note:
- // The whole file has to be searched at once in order to handle class/
- // function definitions over several lines.
- // (01.08.2011.) (Domagoj Saric)
- regex_replace
- (
- std::ostream_iterator<char>( std::cout ),
- input.begin(),
- input.end(),
- main_regex,
- formatter()
- );
-
- return EXIT_SUCCESS;
- }
- catch ( std::exception const & e )
- {
- std::puts( e.what() );
- return EXIT_FAILURE;
- }
- catch ( ... )
- {
- return EXIT_FAILURE;
- }
+ ),
+ interprocess::read_only
+ );
+
+ iterator_range<char const *> input
+ (
+ static_cast<char const *>( input_file_view.get_address() ),
+ static_cast<char const *>( input_file_view.get_address() ) + input_file_view.get_size()
+ );
+
+ using namespace regex;
+ cregex const main_regex( (s1= ignored) | (s2=keep( class_header | function_header )) | (s3='{') | (s4='}') );
+ match_results<char const *> search_results;
+
+ std::cout << "#include <template_profiler.hpp>\n" << std::endl;
+
+ // Implementation note:
+ // The whole file has to be searched at once in order to handle class/
+ // function definitions over several lines.
+ // (01.08.2011.) (Domagoj Saric)
+ regex_replace
+ (
+ std::ostream_iterator<char>( std::cout ),
+ input.begin(),
+ input.end(),
+ main_regex,
+ formatter()
+ );
 }

Added: sandbox/tools/profile_templates2/src/preprocess.hpp
==============================================================================
--- (empty file)
+++ sandbox/tools/profile_templates2/src/preprocess.hpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -0,0 +1,2 @@
+
+void preprocess( char const * const p_filename );
\ No newline at end of file

Added: sandbox/tools/profile_templates2/src/profiler.cpp
==============================================================================
--- (empty file)
+++ sandbox/tools/profile_templates2/src/profiler.cpp 2011-08-01 12:41:46 EDT (Mon, 01 Aug 2011)
@@ -0,0 +1,50 @@
+#undef BOOST_ENABLE_ASSERT_HANDLER
+
+#include <cstdio>
+#include <cstdlib>
+#include <exception>
+#include "process.h"
+
+extern "C"
+int main( int const argc, char const * const argv[] )
+{
+ for ( unsigned i( 0 ); i < argc; ++i )
+ std::puts( argv[ i ] );
+ if ( argc != ( 1 + 3 ) )
+ {
+ std::puts
+ (
+ "Incorrect number of arguments.\n"
+ "Use:\n"
+ "profiler\n"
+ "\t<compiler binary path>\n"
+ "\t<compiler response file with options to build the target source with>\n"
+ "\t<source to profile>."
+ );
+ return EXIT_FAILURE;
+ }
+
+ {
+ char const * const compiler_argv[] = { "-E", argv[ 3 ], NULL };
+ int const result( /*std*/::execv( argv[ 1 ], compiler_argv ) );
+ if ( result != 0 )
+ {
+ std::puts( "Failed generating compiler preprocessed file." );
+ return EXIT_FAILURE;
+ }
+ }
+
+ try
+ {
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const & e )
+ {
+ std::puts( e.what() );
+ return EXIT_FAILURE;
+ }
+ catch ( ... )
+ {
+ return EXIT_FAILURE;
+ }
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk