Builder tool - Load curves and configure optimizer

This commit is contained in:
Emmanuel BENOîT 2017-12-03 10:22:36 +01:00
parent 68ca08ceba
commit dcd149eee5
2 changed files with 96 additions and 53 deletions

View file

@ -100,8 +100,18 @@ T_SRDParserConfig BCLInitDefinitions_( ) noexcept
<< ( Alt( ) << "chooser" << ( Alt( ) << "chooser"
<< ( AtLeast( 1 ) << ( List( ) << Int32( ) << Int32( ) ) ) ) << ( AtLeast( 1 ) << ( List( ) << Int32( ) << Int32( ) ) ) )
<< BCLResolutions_ ) << BCLResolutions_ )
<< ( Rule( ) << "optimizer" << "off" ) << ( Rule( ) << "optimizer" << "off"
<< ( Rule( ) << "optimizer" << "on" << EnterContext( "optim" ) ) << []( T_SRDParserData const& d ) -> bool {
auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) };
bCfg.optimize = false;
return true;
} )
<< ( Rule( ) << "optimizer" << "on" << EnterContext( "optim" )
<< []( T_SRDParserData const& d ) -> bool {
auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) };
bCfg.optimize = true;
return true;
} )
; ;
defs.context( "optim" ) defs.context( "optim" )
@ -128,14 +138,16 @@ T_SRDParserConfig BCLInitDefinitions_( ) noexcept
defs.context( "opt-cf" ) defs.context( "opt-cf" )
<< ( Rule( ) << "fixed-resolution" << Enum( "on-off" ) << ( Rule( ) << "fixed-resolution" << Enum( "on-off" )
<< []( T_SRDParserData const& d ) -> bool { << []( T_SRDParserData const& d ) -> bool {
auto const& in{ *d.input };
auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) }; auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) };
bCfg.cfFixedSize = true; bCfg.cfFixedSize = ( in[ 1 ].stringValue( ) == "on" );
return true; return true;
} ) } )
<< ( Rule( ) << "inputs" << Enum( "on-off" ) << ( Rule( ) << "inputs" << Enum( "on-off" )
<< []( T_SRDParserData const& d ) -> bool { << []( T_SRDParserData const& d ) -> bool {
auto const& in{ *d.input };
auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) }; auto& bCfg{ d.currentData->value< T_BuildConfiguration >( ) };
bCfg.cfInputs = true; bCfg.cfInputs = ( in[ 1 ].stringValue( ) == "on" );
return true; return true;
} ) } )
; ;

View file

@ -29,7 +29,7 @@ const struct option CmdLineOpts_[] = {
void PrintStreamError( void PrintStreamError(
char const* const prefix , char const* const prefix ,
T_String const& name , T_String const& name ,
X_StreamError const& error ) X_StreamError const& error ) noexcept
{ {
T_StringBuilder sb; T_StringBuilder sb;
sb << prefix << " '" << name << "': " << error.what( ); sb << prefix << " '" << name << "': " << error.what( );
@ -42,7 +42,7 @@ void PrintStreamError(
void WriteSRDError( void WriteSRDError(
T_StringBuilder& sb , T_StringBuilder& sb ,
T_SRDError const& error ) T_SRDError const& error ) noexcept
{ {
switch ( error.type( ) ) { switch ( error.type( ) ) {
case E_SRDErrorType::ERROR: case E_SRDErrorType::ERROR:
@ -58,6 +58,35 @@ void WriteSRDError(
sb << '(' << error.location( ) << ")] " << error.error( ) << '\n'; sb << '(' << error.location( ) << ")] " << error.error( ) << '\n';
} }
void WriteSRDErrors(
char const* const title ,
T_SRDErrors const& errors ) noexcept
{
T_StringBuilder sb;
sb << "===== " << title << '\n';
const auto nErrors( errors.size( ) );
for ( auto i = 0u ; i < nErrors ; i ++ ) {
WriteSRDError( sb , errors[ i ] );
}
sb << '\0';
fprintf( stderr , "%s" , sb.data( ) );
}
T_String FilePath(
T_String const& path ,
char const* const name ) noexcept
{
T_StringBuilder sb;
if ( path ) {
sb << path;
if ( !path.endsWith( "/" ) ) {
sb << '/';
}
}
sb << name;
return T_String{ std::move( sb ) };
}
/*============================================================================*/ /*============================================================================*/
@ -108,17 +137,8 @@ int main( int argc , char** argv )
} }; } };
// Build configurations // Build configurations
const T_String bcfgFile( [&]() { logger( [](){ return T_StringBuilder{ "Loading build configurations" }; } , 1 );
T_StringBuilder sb; const T_String bcfgFile{ FilePath( oSrcPath , "build.srd" ) };
if ( oSrcPath ) {
sb << oSrcPath;
if ( !oSrcPath.endsWith( "/" ) ) {
sb << '/';
}
}
sb << "build.srd";
return T_String{ std::move( sb ) };
}( ) );
const T_BuildConfiguration cfg{ [&]() { const T_BuildConfiguration cfg{ [&]() {
try { try {
T_BuildConfigurationLoader bcfgLoader; T_BuildConfigurationLoader bcfgLoader;
@ -142,30 +162,13 @@ int main( int argc , char** argv )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} catch ( X_SRDErrors const& e ) { } catch ( X_SRDErrors const& e ) {
T_StringBuilder sb; WriteSRDErrors( "BUILD CONFIGURATIONS" , e.errors );
sb << "===== BUILD CONFIGURATIONS\n";
const auto nErrors( e.errors.size( ) );
for ( auto i = 0u ; i < nErrors ; i ++ ) {
WriteSRDError( sb , e.errors[ i ] );
}
sb << '\0';
fprintf( stderr , "%s" , sb.data( ) );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} () }; } () };
// Open file // Open file
const T_String inputName( [&]() { const T_String inputName{ FilePath( oSrcPath , "demo.srd" ) };
T_StringBuilder sb;
if ( oSrcPath ) {
sb << oSrcPath;
if ( !oSrcPath.endsWith( "/" ) ) {
sb << '/';
}
}
sb << "demo.srd";
return T_String{ std::move( sb ) };
}( ) );
T_File input( inputName , E_FileMode::READ_ONLY ); T_File input( inputName , E_FileMode::READ_ONLY );
try { try {
input.open( ); input.open( );
@ -174,7 +177,23 @@ int main( int argc , char** argv )
return 1; return 1;
} }
// Load SRD data // Load curves
logger( [](){ return T_StringBuilder{ "Loading curves data" }; } , 1 );
const T_String curvesFile{ FilePath( oSrcPath , "curves.srd" ) };
T_SyncCurvesIO::T_Data p;
try {
p = T_SyncCurvesIO{}.load( curvesFile );
} catch ( ebcl::X_StreamError const& e ) {
fprintf( stderr , "===== CURVES DATA\n" );
PrintStreamError( "Could not open" , curvesFile , e );
exit( EXIT_FAILURE );
} catch ( ebcl::X_SRDErrors const& e ) {
WriteSRDErrors( "CURVES DATA" , e.errors );
exit( EXIT_FAILURE );
}
// Load script
T_SRDMemoryTarget srdOut; T_SRDMemoryTarget srdOut;
srdOut.clearComments( true ).clearFlushToken( true ); srdOut.clearComments( true ).clearFlushToken( true );
try { try {
@ -182,17 +201,12 @@ int main( int argc , char** argv )
T_FileInputStream fis{ input }; T_FileInputStream fis{ input };
srdReader.read( inputName , fis ); srdReader.read( inputName , fis );
} catch ( X_StreamError const& e ) { } catch ( X_StreamError const& e ) {
fprintf( stderr , "===== SCRIPT\n" );
PrintStreamError( "Could not open" , inputName , e ); PrintStreamError( "Could not open" , inputName , e );
return 1; return 1;
} catch ( X_SRDErrors const& e ) { } catch ( X_SRDErrors const& e ) {
T_StringBuilder sb; WriteSRDErrors( "SCRIPT" , e.errors );
const auto nErrors( e.errors.size( ) ); exit( EXIT_FAILURE );
for ( auto i = 0u ; i < nErrors ; i ++ ) {
WriteSRDError( sb , e.errors[ i ] );
}
sb << "No parsing happened due to format errors\n" << '\0';
fprintf( stderr , "%s" , sb.data( ) );
return 2;
} }
// Parse // Parse
@ -210,14 +224,31 @@ int main( int argc , char** argv )
auto parsed{ parser.result( ) }; auto parsed{ parser.result( ) };
// Optimize // Optimize
opopt::T_OptData od; if ( cfg.optimize ) {
od.logger = logger; opopt::T_OptData od;
//od.fixedSize = std::make_pair( 1280u , 720u ); od.logger = logger;
bool doneStuff{ false }; if ( !cfg.resolutionChooser && cfg.cfFixedSize ) {
do { od.fixedSize = cfg.resolutions[ 0 ]; // FIXME
doneStuff = opopt::FoldConstants( *parsed , od ); }
doneStuff = opopt::RemoveDeadCode( *parsed , od ) || doneStuff; if ( cfg.cfInputs ) {
} while ( doneStuff ); od.curves = &p.curves;
}
bool doneStuff;
do {
doneStuff = false;
if ( cfg.constantFolding ) {
while ( opopt::FoldConstants( *parsed , od ) ) {
doneStuff = true;
}
}
if ( cfg.deadCodeElimination ) {
while ( opopt::RemoveDeadCode( *parsed , od ) ) {
doneStuff = true;
}
}
} while ( doneStuff );
}
// Compile // Compile
T_OpsCompiler compiler; T_OpsCompiler compiler;