From 965496b231d4abe25e43dc5234ad3bc8786bb2f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= <tseeker@nocternity.net>
Date: Sat, 23 Dec 2017 17:29:52 +0100
Subject: [PATCH] Optimizer - Fixed input handling

---
 c-opopt.cc     |  9 ++++-----
 c-opopt.hh     |  2 +-
 test/build.srd | 21 ++++++++++++++++-----
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/c-opopt.cc b/c-opopt.cc
index 4f14c47..ccb1599 100644
--- a/c-opopt.cc
+++ b/c-opopt.cc
@@ -66,10 +66,10 @@ void T_OptData::findInputDecls(
 	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( ) ) };
+			auto* da{ inputDecls.get( input.id( ) ) };
 			if ( !da ) {
-				inputDecls->add( input.id( ) , T_Array< T_InputDecl >{ } );
-				da = inputDecls->get( input.id( ) );
+				inputDecls.add( input.id( ) , T_Array< T_InputDecl >{ } );
+				da = inputDecls.get( input.id( ) );
 			}
 			da->add( T_InputDecl{ input.location( ) , input.defValue( ) } );
 		}
@@ -1275,8 +1275,7 @@ P_ExpressionNode T_ConstantFolder_::doInputExpr(
 		return NewOwned< T_ConstantExprNode >( node.parent( ) , *cval );
 	}
 
-	assert( oData.inputDecls );
-	auto const* const dva{ oData.inputDecls->get( node.id( ) ) };
+	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.
diff --git a/c-opopt.hh b/c-opopt.hh
index 3383938..6c52ab7 100644
--- a/c-opopt.hh
+++ b/c-opopt.hh
@@ -47,7 +47,7 @@ struct T_OptData
 		ebcl::T_SRDLocation location;
 		float value;
 	};
-	T_Optional< T_KeyValueTable< T_String , T_Array< T_InputDecl > > > inputDecls;
+	T_KeyValueTable< T_String , T_Array< T_InputDecl > > inputDecls;
 
 	void findInputDecls( T_OpsParserOutput& program ) noexcept;
 
diff --git a/test/build.srd b/test/build.srd
index 05488c7..40591d0 100644
--- a/test/build.srd
+++ b/test/build.srd
@@ -1,4 +1,4 @@
-(cfg "Optimized"
+(cfg "OptimizedFixed"
 	(resolutions
 		(1280 720)
 		(1920 1080)
@@ -6,6 +6,20 @@
 	(optimizer on
 		(constant-folding on
 			(fixed-resolution on)
+			(inputs on)
+		)
+		(constant-propagation on)
+		(dead-code-elimination on)
+		(function-inlining on)
+	)
+)
+
+(cfg "OptimizedDynamic"
+	(resolutions chooser)
+	(optimizer on
+		(constant-folding on
+			(fixed-resolution off)
+			(inputs on)
 		)
 		(constant-propagation on)
 		(dead-code-elimination on)
@@ -14,9 +28,6 @@
 )
 
 (cfg "Basic"
-	(resolutions
-		(1280 720)
-		(1920 1080)
-	)
+	(resolutions chooser)
 	(optimizer off)
 )