2017-12-01 07:30:03 +01:00
|
|
|
#include "externals.hh"
|
|
|
|
|
|
|
|
#include "c-opopt.hh"
|
2017-12-02 10:07:14 +01:00
|
|
|
#include "c-ops.hh"
|
2017-12-01 07:30:03 +01:00
|
|
|
#include "c-sync.hh"
|
|
|
|
|
|
|
|
using namespace ebcl;
|
|
|
|
using namespace opast;
|
|
|
|
using namespace opopt;
|
|
|
|
|
|
|
|
|
2017-12-02 10:40:47 +01:00
|
|
|
/*= T_OptData ================================================================*/
|
|
|
|
|
|
|
|
void T_OptData::findInputDecls(
|
|
|
|
T_OpsParserOutput& program ) noexcept
|
|
|
|
{
|
|
|
|
if ( inputDecls ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputDecls = T_KeyValueTable< T_String , T_Array< T_InputDecl > >{ };
|
|
|
|
visitor.visit( program.root , [this]( A_Node& node , const bool exit ) {
|
|
|
|
if ( exit && node.type( ) == A_Node::OP_INPUT ) {
|
|
|
|
auto& input{ (T_InputInstrNode&) node };
|
|
|
|
auto* da{ inputDecls->get( input.id( ) ) };
|
|
|
|
if ( !da ) {
|
|
|
|
inputDecls->add( input.id( ) , T_Array< T_InputDecl >{ } );
|
|
|
|
da = inputDecls->get( input.id( ) );
|
|
|
|
}
|
|
|
|
da->add( T_InputDecl{ input.location( ) , input.defValue( ) } );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 07:30:03 +01:00
|
|
|
/*= CONSTANT FOLDING =========================================================*/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct T_ConstantFolder_
|
|
|
|
{
|
2017-12-02 10:07:14 +01:00
|
|
|
T_ConstantFolder_( T_OptData& data ) noexcept
|
|
|
|
: oData{ data }
|
|
|
|
{}
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
// Result
|
|
|
|
bool didFold{ false };
|
|
|
|
|
|
|
|
bool operator()( A_Node& node , bool exit ) noexcept;
|
|
|
|
|
|
|
|
private:
|
2017-12-02 10:07:14 +01:00
|
|
|
T_OptData& oData;
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
template<
|
|
|
|
typename T
|
|
|
|
> void handleParentNode(
|
2017-12-01 07:30:03 +01:00
|
|
|
A_Node& node ,
|
2017-12-01 22:10:36 +01:00
|
|
|
std::function< A_ExpressionNode&( T& ) > get ,
|
|
|
|
std::function< void( T& , P_ExpressionNode ) > set ) noexcept;
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
P_ExpressionNode checkExpression(
|
2017-12-01 22:10:36 +01:00
|
|
|
A_ExpressionNode& node ) noexcept;
|
|
|
|
|
|
|
|
// Handle identifiers. If the size is fixed and the identifier is
|
|
|
|
// either width or height, replace it with the appropriate value.
|
|
|
|
P_ExpressionNode doIdExpr(
|
|
|
|
T_IdentifierExprNode& node ) noexcept;
|
|
|
|
|
2017-12-02 10:40:47 +01:00
|
|
|
// Handle reads from inputs. If there's a curve and it is a constant,
|
|
|
|
// or if there's no curve and only one default value, then the
|
|
|
|
// expression is constant.
|
|
|
|
P_ExpressionNode doInputExpr(
|
|
|
|
T_InputExprNode& node ) noexcept;
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
// Transform an unary operator applied to a constant into a constant.
|
|
|
|
P_ExpressionNode doUnaryOp(
|
2017-12-02 10:07:14 +01:00
|
|
|
T_UnaryOperatorNode& node ,
|
2017-12-01 22:10:36 +01:00
|
|
|
double value ) const noexcept;
|
|
|
|
|
|
|
|
// Transform a binary operator applied to a constant into a constant.
|
|
|
|
P_ExpressionNode doBinaryOp(
|
2017-12-02 10:07:14 +01:00
|
|
|
T_BinaryOperatorNode& node ,
|
2017-12-01 22:10:36 +01:00
|
|
|
double left ,
|
|
|
|
double right ) const noexcept;
|
2017-12-01 07:30:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
bool T_ConstantFolder_::operator()(
|
|
|
|
A_Node& node ,
|
|
|
|
const bool exit ) noexcept
|
|
|
|
{
|
|
|
|
if ( exit ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( node.type( ) ) {
|
|
|
|
|
|
|
|
case A_Node::TN_ARG:
|
2017-12-01 22:10:36 +01:00
|
|
|
handleParentNode< T_ArgumentNode >(
|
|
|
|
node ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.expression( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.expression( std::move( e ) ); }
|
|
|
|
);
|
2017-12-01 07:30:03 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case A_Node::TN_CONDITION:
|
2017-12-01 22:10:36 +01:00
|
|
|
handleParentNode< T_CondInstrNode::T_Expression >( node ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.expression( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.expression( std::move( e ) ); }
|
|
|
|
);
|
2017-12-01 07:30:03 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case A_Node::OP_SET:
|
2017-12-01 22:10:36 +01:00
|
|
|
handleParentNode< T_SetInstrNode >( node ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.expression( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.setExpression( std::move( e ) ); } );
|
2017-12-01 07:30:03 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename T
|
|
|
|
> void T_ConstantFolder_::handleParentNode(
|
|
|
|
A_Node& n ,
|
|
|
|
std::function< A_ExpressionNode&( T& ) > get ,
|
|
|
|
std::function< void( T& , P_ExpressionNode ) > set ) noexcept
|
2017-12-01 07:30:03 +01:00
|
|
|
{
|
2017-12-01 22:10:36 +01:00
|
|
|
auto& node{ (T&) n };
|
2017-12-02 12:18:31 +01:00
|
|
|
auto& child{ get( node ) };
|
|
|
|
auto r{ checkExpression( child ) };
|
2017-12-01 07:30:03 +01:00
|
|
|
if ( r ) {
|
2017-12-02 12:18:31 +01:00
|
|
|
oData.logger( [&]() {
|
|
|
|
T_StringBuilder sb;
|
|
|
|
sb << "substituting node at " << child.location( );
|
|
|
|
return sb;
|
|
|
|
} , 2 );
|
2017-12-01 22:10:36 +01:00
|
|
|
r->location( ) = node.location( );
|
2017-12-01 07:30:03 +01:00
|
|
|
set( node , std::move( r ) );
|
|
|
|
didFold = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
P_ExpressionNode T_ConstantFolder_::checkExpression(
|
2017-12-01 22:10:36 +01:00
|
|
|
A_ExpressionNode& node ) noexcept
|
2017-12-01 07:30:03 +01:00
|
|
|
{
|
2017-12-01 22:10:36 +01:00
|
|
|
// Already a constant
|
|
|
|
if ( node.type( ) == A_Node::EXPR_CONST ) {
|
|
|
|
return {};
|
|
|
|
}
|
2017-12-01 07:30:03 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
// Replace $width/$height with value if fixedSize
|
2017-12-01 07:30:03 +01:00
|
|
|
if ( node.type( ) == A_Node::EXPR_ID ) {
|
2017-12-01 22:10:36 +01:00
|
|
|
return doIdExpr( (T_IdentifierExprNode&) node );
|
|
|
|
}
|
2017-12-01 07:30:03 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
// Replace inputs with value if no curve/constant curve
|
|
|
|
if ( node.type( ) == A_Node::EXPR_INPUT ) {
|
2017-12-02 10:40:47 +01:00
|
|
|
return doInputExpr( (T_InputExprNode&) node );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Replace UnOp( Cnst ) with result
|
|
|
|
auto* const asUnary{ dynamic_cast< T_UnaryOperatorNode* >( &node ) };
|
|
|
|
if ( asUnary ) {
|
|
|
|
handleParentNode< T_UnaryOperatorNode >( *asUnary ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.argument( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.setArgument( std::move( e ) ); } );
|
|
|
|
if ( asUnary->argument( ).type( ) == A_Node::EXPR_CONST ) {
|
|
|
|
auto const& cn{ (T_ConstantExprNode const&) asUnary->argument( ) };
|
2017-12-02 10:07:14 +01:00
|
|
|
return doUnaryOp( *asUnary , cn.floatValue( ) );
|
2017-12-01 07:30:03 +01:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
// Replace BinOp( Cnst , Cnst ) with result
|
|
|
|
auto* const asBinary{ dynamic_cast< T_BinaryOperatorNode* >( &node ) };
|
|
|
|
assert( asBinary && "Missing support for some expr subtype" );
|
|
|
|
handleParentNode< T_BinaryOperatorNode >( *asBinary ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.left( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.setLeft( std::move( e ) ); } );
|
|
|
|
handleParentNode< T_BinaryOperatorNode >( *asBinary ,
|
|
|
|
[]( auto& n ) -> A_ExpressionNode& { return n.right( ); } ,
|
|
|
|
[]( auto& n , P_ExpressionNode e ) { n.setRight( std::move( e ) ); } );
|
|
|
|
|
|
|
|
if ( asBinary->left( ).type( ) == A_Node::EXPR_CONST
|
|
|
|
&& asBinary->right( ).type( ) == A_Node::EXPR_CONST ) {
|
|
|
|
auto const& l{ (T_ConstantExprNode const&) asBinary->left( ) };
|
|
|
|
auto const& r{ (T_ConstantExprNode const&) asBinary->right( ) };
|
2017-12-02 10:07:14 +01:00
|
|
|
return doBinaryOp( *asBinary , l.floatValue( ) , r.floatValue( ) );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-12-02 10:40:47 +01:00
|
|
|
P_ExpressionNode T_ConstantFolder_::doInputExpr(
|
|
|
|
T_InputExprNode& node ) noexcept
|
|
|
|
{
|
|
|
|
if ( !oData.curves ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto const* const curve{ oData.curves->curves.get( node.id( ) ) };
|
|
|
|
if ( curve ) {
|
|
|
|
// Curve present, check if it's constant
|
|
|
|
const auto cval{ curve->isConstant( ) };
|
|
|
|
if ( !cval ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) , *cval );
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( oData.inputDecls );
|
|
|
|
auto const* const dva{ oData.inputDecls->get( node.id( ) ) };
|
|
|
|
assert( dva );
|
|
|
|
if ( dva->size( ) == 1 ) {
|
|
|
|
// If there's only one default value, that's a constant.
|
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) ,
|
|
|
|
(*dva)[ 0 ].value );
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
P_ExpressionNode T_ConstantFolder_::doIdExpr(
|
|
|
|
T_IdentifierExprNode& node ) noexcept
|
|
|
|
{
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( !oData.fixedSize ) {
|
2017-12-01 22:10:36 +01:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( node.id( ) == "width" ) {
|
2017-12-02 12:18:31 +01:00
|
|
|
oData.logger( []{
|
|
|
|
return T_StringBuilder{ "replacing $width with fixed width" };
|
|
|
|
} , 2 );
|
2017-12-01 22:10:36 +01:00
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) ,
|
2017-12-02 10:07:14 +01:00
|
|
|
double( oData.fixedSize->first ) );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( node.id( ) == "height" ) {
|
2017-12-02 12:18:31 +01:00
|
|
|
oData.logger( []{
|
|
|
|
return T_StringBuilder{ "replacing $height with fixed height" };
|
|
|
|
} , 2 );
|
2017-12-01 22:10:36 +01:00
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) ,
|
2017-12-02 10:07:14 +01:00
|
|
|
float( oData.fixedSize->second ) );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 07:30:03 +01:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
P_ExpressionNode T_ConstantFolder_::doUnaryOp(
|
2017-12-02 10:07:14 +01:00
|
|
|
T_UnaryOperatorNode& node ,
|
2017-12-01 22:10:36 +01:00
|
|
|
const double value ) const noexcept
|
|
|
|
{
|
2017-12-02 10:07:14 +01:00
|
|
|
const double rVal{ [this]( auto& node , const auto value ) {
|
|
|
|
switch ( node.op( ) ) {
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::NEG:
|
|
|
|
return -value;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::NOT:
|
|
|
|
return value ? 0. : 1.;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::INV:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( value == 0 ) {
|
|
|
|
oData.errors.addNew( "math - 1/x, x=0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return 1. / value;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::COS:
|
|
|
|
return cos( value );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::SIN:
|
|
|
|
return sin( value );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::TAN:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( fabs( value - M_PI / 2 ) <= 1e-6 ) {
|
|
|
|
oData.errors.addNew( "math - tan(x), x=~PI/2" ,
|
|
|
|
node.location( ) , E_SRDErrorType::WARNING );
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return tan( value );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::SQRT:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( value < 0 ) {
|
|
|
|
oData.errors.addNew( "math - sqrt(x), x<0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return sqrt( value );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::LN:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( value <= 0 ) {
|
|
|
|
oData.errors.addNew( "math - ln(x), x<=0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return log( value );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_UnaryOperatorNode::EXP:
|
|
|
|
return exp( value );
|
|
|
|
}
|
2017-12-02 10:07:14 +01:00
|
|
|
|
|
|
|
fprintf( stderr , "invalid operator %d\n" , int( node.op( ) ) );
|
2017-12-01 22:10:36 +01:00
|
|
|
std::abort( );
|
2017-12-02 10:07:14 +01:00
|
|
|
}( node , value ) };
|
2017-12-01 22:10:36 +01:00
|
|
|
|
2017-12-02 10:07:14 +01:00
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) , rVal );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
P_ExpressionNode T_ConstantFolder_::doBinaryOp(
|
2017-12-02 10:07:14 +01:00
|
|
|
T_BinaryOperatorNode& node ,
|
2017-12-01 22:10:36 +01:00
|
|
|
const double left ,
|
|
|
|
const double right ) const noexcept
|
|
|
|
{
|
2017-12-02 10:07:14 +01:00
|
|
|
const double rVal{ [this]( auto& node , const auto l , const auto r ) {
|
|
|
|
switch ( node.op( ) ) {
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_BinaryOperatorNode::ADD:
|
|
|
|
return l + r;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_BinaryOperatorNode::SUB:
|
|
|
|
return l - r;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_BinaryOperatorNode::MUL:
|
|
|
|
return l * r;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_BinaryOperatorNode::DIV:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( r == 0 ) {
|
|
|
|
oData.errors.addNew( "math - l/r, r=0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return l / r;
|
2017-12-02 10:07:14 +01:00
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
case T_BinaryOperatorNode::POW:
|
2017-12-02 10:07:14 +01:00
|
|
|
if ( l == 0 && r == 0 ) {
|
|
|
|
oData.errors.addNew( "math - l^r, l=r=0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
|
|
|
if ( l == 0 && r < 0 ) {
|
|
|
|
oData.errors.addNew( "math - l^r, l=0, r<0" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
|
|
|
if ( l < 0 && fmod( r , 1. ) != 0. ) {
|
|
|
|
oData.errors.addNew( "math - l^r, l<0, r not integer" , node.location( ) );
|
|
|
|
return 0.;
|
|
|
|
}
|
2017-12-01 22:10:36 +01:00
|
|
|
return pow( l , r );
|
2017-12-02 10:07:14 +01:00
|
|
|
|
|
|
|
case T_BinaryOperatorNode::CMP_EQ: return ( l == r ) ? 1. : 0.;
|
|
|
|
case T_BinaryOperatorNode::CMP_NE: return ( l != r ) ? 1. : 0.;
|
|
|
|
case T_BinaryOperatorNode::CMP_GT: return ( l > r ) ? 1. : 0.;
|
|
|
|
case T_BinaryOperatorNode::CMP_GE: return ( l >= r ) ? 1. : 0.;
|
|
|
|
case T_BinaryOperatorNode::CMP_LT: return ( l < r ) ? 1. : 0.;
|
|
|
|
case T_BinaryOperatorNode::CMP_LE: return ( l <= r ) ? 1. : 0.;
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
2017-12-02 10:07:14 +01:00
|
|
|
fprintf( stderr , "invalid operator %d\n" , int( node.op( ) ) );
|
2017-12-01 22:10:36 +01:00
|
|
|
std::abort( );
|
2017-12-02 10:07:14 +01:00
|
|
|
}( node , left , right ) };
|
2017-12-01 22:10:36 +01:00
|
|
|
|
2017-12-02 10:07:14 +01:00
|
|
|
return NewOwned< T_ConstantExprNode >( node.parent( ) , rVal );
|
2017-12-01 22:10:36 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 07:30:03 +01:00
|
|
|
} // namespace <anon>
|
|
|
|
|
2017-12-01 22:10:36 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
bool opopt::FoldConstants(
|
2017-12-02 10:07:14 +01:00
|
|
|
T_OpsParserOutput& program ,
|
|
|
|
T_OptData& oData ) noexcept
|
2017-12-01 07:30:03 +01:00
|
|
|
{
|
2017-12-02 10:07:14 +01:00
|
|
|
T_ConstantFolder_ folder{ oData };
|
2017-12-02 12:18:31 +01:00
|
|
|
oData.logger( []() {
|
|
|
|
return T_StringBuilder{ "constant folding pass" };
|
|
|
|
} , 1 );
|
2017-12-02 10:40:47 +01:00
|
|
|
if ( oData.curves ) {
|
|
|
|
oData.findInputDecls( program );
|
|
|
|
}
|
2017-12-02 12:18:31 +01:00
|
|
|
oData.visitor.visit( program.root , [&]( auto& n , auto x ) {
|
|
|
|
return folder( n , x );
|
|
|
|
} );
|
|
|
|
oData.logger( [&]() {
|
|
|
|
return T_StringBuilder{
|
|
|
|
folder.didFold ? "some constants were folded"
|
|
|
|
: "no constants were folded" };
|
|
|
|
} , 1 );
|
2017-12-01 07:30:03 +01:00
|
|
|
return folder.didFold;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= DEAD CODE REMOVAL ========================================================*/
|
|
|
|
|
2017-12-02 10:07:14 +01:00
|
|
|
bool opopt::RemoveDeadCode(
|
|
|
|
T_OpsParserOutput& program ,
|
|
|
|
T_OptData& oData ) noexcept
|
2017-12-01 07:30:03 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|