Bläddra i källkod

* InputVariableDeclaration#directFeedthrough attribute added.
* C code generator fixes.

au@andreasunger.net 14 år sedan
förälder
incheckning
2c6539ffeb

+ 21 - 42
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.codegen.c/src/org/eclipselabs/mscript/codegen/c/MscriptGenerator.java

@@ -12,6 +12,7 @@
 package org.eclipselabs.mscript.codegen.c;
 
 import java.io.PrintWriter;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.eclipselabs.mscript.codegen.c.internal.VariableAccessStrategy;
@@ -22,6 +23,7 @@ import org.eclipselabs.mscript.language.il.InputVariableDeclaration;
 import org.eclipselabs.mscript.language.il.InstanceVariableDeclaration;
 import org.eclipselabs.mscript.language.il.OutputVariableDeclaration;
 import org.eclipselabs.mscript.language.il.StatefulVariableDeclaration;
+import org.eclipselabs.mscript.language.il.util.ILUtil;
 import org.eclipselabs.mscript.typesystem.DataType;
 
 /**
@@ -191,10 +193,8 @@ public class MscriptGenerator {
 	 */
 	private void generateComputeOutputsFunctionHeader() {
 		writer.printf("void %s(%s_Context *context", functionDefinition.getName(), functionDefinition.getName());
-		for (InputVariableDeclaration inputVariableDeclaration : functionDefinition.getInputVariableDeclarations()) {
-			if (consumesInput(inputVariableDeclaration, true)) {
-				writer.printf(", %s", MscriptGeneratorUtil.getCVariableDeclaration(context.getComputationModel(), inputVariableDeclaration.getDataType(), inputVariableDeclaration.getName(), false));
-			}
+		for (InputVariableDeclaration inputVariableDeclaration : ILUtil.getDirectFeedthroughInputs(functionDefinition)) {
+			writer.printf(", %s", MscriptGeneratorUtil.getCVariableDeclaration(context.getComputationModel(), inputVariableDeclaration.getDataType(), inputVariableDeclaration.getName(), false));
 		}
 		for (OutputVariableDeclaration outputVariableDeclaration: functionDefinition.getOutputVariableDeclarations()) {
 			writer.printf(", %s", MscriptGeneratorUtil.getCVariableDeclaration(context.getComputationModel(), outputVariableDeclaration.getDataType(), outputVariableDeclaration.getName(), true));
@@ -211,13 +211,15 @@ public class MscriptGenerator {
 		for (ComputationCompound compound : functionDefinition.getComputationCompounds()) {
 			if (!compound.getOutputs().isEmpty()) {
 				compoundGenerator.generate(context, variableAccessStrategy, compound);
-				for (InputVariableDeclaration inputVariableDeclaration : compound.getInputs()) {
-					if (inputVariableDeclaration.getCircularBufferSize() > 1) {
-						generateUpdateInputContextStatement(inputVariableDeclaration);
-					}
-				}
 			}
 		}
+		
+		for (InputVariableDeclaration inputVariableDeclaration : ILUtil.getDirectFeedthroughInputs(functionDefinition)) {
+			if (inputVariableDeclaration.getCircularBufferSize() > 1) {
+				generateUpdateInputContextStatement(inputVariableDeclaration);
+			}
+		}
+		
 		for (OutputVariableDeclaration outputVariableDeclaration : functionDefinition.getOutputVariableDeclarations()) {
 			if (outputVariableDeclaration.getCircularBufferSize() > 1) {
 				String name = outputVariableDeclaration.getName();
@@ -232,10 +234,8 @@ public class MscriptGenerator {
 	 */
 	private void generateUpdateFunctionHeader() {
 		writer.printf("void %s_update(%s_Context *context", functionDefinition.getName(), functionDefinition.getName());
-		for (InputVariableDeclaration inputVariableDeclaration : functionDefinition.getInputVariableDeclarations()) {
-			if (consumesInput(inputVariableDeclaration, false) || updatesInputContext(inputVariableDeclaration)) {
-				writer.printf(", %s", MscriptGeneratorUtil.getCVariableDeclaration(context.getComputationModel(), inputVariableDeclaration.getDataType(), inputVariableDeclaration.getName(), false));
-			}
+		for (InputVariableDeclaration inputVariableDeclaration : getUpdateCodeInputs()) {
+			writer.printf(", %s", MscriptGeneratorUtil.getCVariableDeclaration(context.getComputationModel(), inputVariableDeclaration.getDataType(), inputVariableDeclaration.getName(), false));
 		}
 		writer.print(")");
 	}
@@ -251,8 +251,8 @@ public class MscriptGenerator {
 				compoundGenerator.generate(context, variableAccessStrategy, compound);
 			}
 		}
-		for (InputVariableDeclaration inputVariableDeclaration : functionDefinition.getInputVariableDeclarations()) {
-			if (updatesInputContext(inputVariableDeclaration)) {
+		for (InputVariableDeclaration inputVariableDeclaration : getUpdateCodeInputs()) {
+			if (inputVariableDeclaration.getCircularBufferSize() > 1) {
 				generateUpdateInputContextStatement(inputVariableDeclaration);
 			}
 		}
@@ -262,35 +262,14 @@ public class MscriptGenerator {
 		writer.println("}");
 	}
 	
-	private boolean consumesInput(InputVariableDeclaration inputVariableDeclaration, boolean feedsOutputs) {
-		for (ComputationCompound compound : inputVariableDeclaration.getFeedingCompounds()) {
-			if (compound.getOutputs().isEmpty() != feedsOutputs) {
-				return true;
-			}
-		}
-		return false;
+	private List<InputVariableDeclaration> getUpdateCodeInputs() {
+		List<InputVariableDeclaration> inputs = new ArrayList<InputVariableDeclaration>(functionDefinition.getInputVariableDeclarations());
+		inputs.removeAll(ILUtil.getDirectFeedthroughInputs(functionDefinition));
+		return inputs;
 	}
 
-	/**
-	 * @param inputVariableDeclaration
-	 * @return
-	 */
-	private boolean updatesInputContext(InputVariableDeclaration inputVariableDeclaration) {
-		if (inputVariableDeclaration.getCircularBufferSize() > 1) {
-			if (inputVariableDeclaration.getFeedingCompounds().isEmpty()) {
-				return true;
-			}
-			for (ComputationCompound compound : functionDefinition.getComputationCompounds()) {
-				if (compound.getOutputs().isEmpty()) {
-					return true;
-				}
-			}
-		}
-		return false;
-	}
-	
-	private void generateUpdateInputContextStatement(InputVariableDeclaration variableDeclaration) {
-		String name = variableDeclaration.getName();
+	private void generateUpdateInputContextStatement(InputVariableDeclaration inputVariableDeclaration) {
+		String name = inputVariableDeclaration.getName();
 		writer.printf("context->%s[context->%s_index] = %s;\n", name, name, name);
 	}
 

+ 3 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/model/IL.ecore

@@ -48,6 +48,9 @@
   <eClassifiers xsi:type="ecore:EClass" name="InputVariableDeclaration" eSuperTypes="#//StatefulVariableDeclaration">
     <eStructuralFeatures xsi:type="ecore:EReference" name="feedingCompounds" upperBound="-1"
         eType="#//ComputationCompound" eOpposite="#//ComputationCompound/inputs"/>
+    <eStructuralFeatures xsi:type="ecore:EAttribute" name="directFeedthrough" lowerBound="1"
+        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" changeable="false"
+        volatile="true" transient="true" derived="true"/>
   </eClassifiers>
   <eClassifiers xsi:type="ecore:EClass" name="OutputVariableDeclaration" eSuperTypes="#//StatefulVariableDeclaration"/>
   <eClassifiers xsi:type="ecore:EClass" name="InstanceVariableDeclaration" eSuperTypes="#//StatefulVariableDeclaration"/>

+ 1 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/model/IL.genmodel

@@ -38,6 +38,7 @@
     </genClasses>
     <genClasses ecoreClass="IL.ecore#//InputVariableDeclaration">
       <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference IL.ecore#//InputVariableDeclaration/feedingCompounds"/>
+      <genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute IL.ecore#//InputVariableDeclaration/directFeedthrough"/>
     </genClasses>
     <genClasses ecoreClass="IL.ecore#//OutputVariableDeclaration"/>
     <genClasses ecoreClass="IL.ecore#//InstanceVariableDeclaration"/>

+ 29 - 1
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/src/org/eclipselabs/mscript/language/il/ILPackage.java

@@ -459,6 +459,15 @@ public interface ILPackage extends EPackage {
 	 */
 	int INPUT_VARIABLE_DECLARATION__FEEDING_COMPOUNDS = STATEFUL_VARIABLE_DECLARATION_FEATURE_COUNT + 0;
 
+	/**
+	 * The feature id for the '<em><b>Direct Feedthrough</b></em>' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 * @ordered
+	 */
+	int INPUT_VARIABLE_DECLARATION__DIRECT_FEEDTHROUGH = STATEFUL_VARIABLE_DECLARATION_FEATURE_COUNT + 1;
+
 	/**
 	 * The number of structural features of the '<em>Input Variable Declaration</em>' class.
 	 * <!-- begin-user-doc -->
@@ -466,7 +475,7 @@ public interface ILPackage extends EPackage {
 	 * @generated
 	 * @ordered
 	 */
-	int INPUT_VARIABLE_DECLARATION_FEATURE_COUNT = STATEFUL_VARIABLE_DECLARATION_FEATURE_COUNT + 1;
+	int INPUT_VARIABLE_DECLARATION_FEATURE_COUNT = STATEFUL_VARIABLE_DECLARATION_FEATURE_COUNT + 2;
 
 	/**
 	 * The feature id for the '<em><b>Name</b></em>' attribute.
@@ -1256,6 +1265,17 @@ public interface ILPackage extends EPackage {
 	 */
 	EReference getInputVariableDeclaration_FeedingCompounds();
 
+	/**
+	 * Returns the meta object for the attribute '{@link org.eclipselabs.mscript.language.il.InputVariableDeclaration#isDirectFeedthrough <em>Direct Feedthrough</em>}'.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @return the meta object for the attribute '<em>Direct Feedthrough</em>'.
+	 * @see org.eclipselabs.mscript.language.il.InputVariableDeclaration#isDirectFeedthrough()
+	 * @see #getInputVariableDeclaration()
+	 * @generated
+	 */
+	EAttribute getInputVariableDeclaration_DirectFeedthrough();
+
 	/**
 	 * Returns the meta object for class '{@link org.eclipselabs.mscript.language.il.OutputVariableDeclaration <em>Output Variable Declaration</em>}'.
 	 * <!-- begin-user-doc -->
@@ -1838,6 +1858,14 @@ public interface ILPackage extends EPackage {
 		 */
 		EReference INPUT_VARIABLE_DECLARATION__FEEDING_COMPOUNDS = eINSTANCE.getInputVariableDeclaration_FeedingCompounds();
 
+		/**
+		 * The meta object literal for the '<em><b>Direct Feedthrough</b></em>' attribute feature.
+		 * <!-- begin-user-doc -->
+		 * <!-- end-user-doc -->
+		 * @generated
+		 */
+		EAttribute INPUT_VARIABLE_DECLARATION__DIRECT_FEEDTHROUGH = eINSTANCE.getInputVariableDeclaration_DirectFeedthrough();
+
 		/**
 		 * The meta object literal for the '{@link org.eclipselabs.mscript.language.il.impl.OutputVariableDeclarationImpl <em>Output Variable Declaration</em>}' class.
 		 * <!-- begin-user-doc -->

+ 16 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/src/org/eclipselabs/mscript/language/il/InputVariableDeclaration.java

@@ -18,6 +18,7 @@ import org.eclipse.emf.common.util.EList;
  * The following features are supported:
  * <ul>
  *   <li>{@link org.eclipselabs.mscript.language.il.InputVariableDeclaration#getFeedingCompounds <em>Feeding Compounds</em>}</li>
+ *   <li>{@link org.eclipselabs.mscript.language.il.InputVariableDeclaration#isDirectFeedthrough <em>Direct Feedthrough</em>}</li>
  * </ul>
  * </p>
  *
@@ -44,4 +45,19 @@ public interface InputVariableDeclaration extends StatefulVariableDeclaration {
 	 * @generated
 	 */
 	EList<ComputationCompound> getFeedingCompounds();
+
+	/**
+	 * Returns the value of the '<em><b>Direct Feedthrough</b></em>' attribute.
+	 * <!-- begin-user-doc -->
+	 * <p>
+	 * If the meaning of the '<em>Direct Feedthrough</em>' attribute isn't clear,
+	 * there really should be more of a description here...
+	 * </p>
+	 * <!-- end-user-doc -->
+	 * @return the value of the '<em>Direct Feedthrough</em>' attribute.
+	 * @see org.eclipselabs.mscript.language.il.ILPackage#getInputVariableDeclaration_DirectFeedthrough()
+	 * @model required="true" transient="true" changeable="false" volatile="true" derived="true"
+	 * @generated
+	 */
+	boolean isDirectFeedthrough();
 } // InputVariableDeclaration

+ 11 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/src/org/eclipselabs/mscript/language/il/impl/ILPackageImpl.java

@@ -480,6 +480,15 @@ public class ILPackageImpl extends EPackageImpl implements ILPackage {
 		return (EReference)inputVariableDeclarationEClass.getEStructuralFeatures().get(0);
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated
+	 */
+	public EAttribute getInputVariableDeclaration_DirectFeedthrough() {
+		return (EAttribute)inputVariableDeclarationEClass.getEStructuralFeatures().get(1);
+	}
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
@@ -844,6 +853,7 @@ public class ILPackageImpl extends EPackageImpl implements ILPackage {
 
 		inputVariableDeclarationEClass = createEClass(INPUT_VARIABLE_DECLARATION);
 		createEReference(inputVariableDeclarationEClass, INPUT_VARIABLE_DECLARATION__FEEDING_COMPOUNDS);
+		createEAttribute(inputVariableDeclarationEClass, INPUT_VARIABLE_DECLARATION__DIRECT_FEEDTHROUGH);
 
 		outputVariableDeclarationEClass = createEClass(OUTPUT_VARIABLE_DECLARATION);
 
@@ -980,6 +990,7 @@ public class ILPackageImpl extends EPackageImpl implements ILPackage {
 
 		initEClass(inputVariableDeclarationEClass, InputVariableDeclaration.class, "InputVariableDeclaration", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEReference(getInputVariableDeclaration_FeedingCompounds(), this.getComputationCompound(), this.getComputationCompound_Inputs(), "feedingCompounds", null, 0, -1, InputVariableDeclaration.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+		initEAttribute(getInputVariableDeclaration_DirectFeedthrough(), ecorePackage.getEBoolean(), "directFeedthrough", null, 1, 1, InputVariableDeclaration.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 
 		initEClass(outputVariableDeclarationEClass, OutputVariableDeclaration.class, "OutputVariableDeclaration", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 

+ 29 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/src/org/eclipselabs/mscript/language/il/impl/InputVariableDeclarationImpl.java

@@ -26,6 +26,7 @@ import org.eclipselabs.mscript.language.il.InputVariableDeclaration;
  * The following features are implemented:
  * <ul>
  *   <li>{@link org.eclipselabs.mscript.language.il.impl.InputVariableDeclarationImpl#getFeedingCompounds <em>Feeding Compounds</em>}</li>
+ *   <li>{@link org.eclipselabs.mscript.language.il.impl.InputVariableDeclarationImpl#isDirectFeedthrough <em>Direct Feedthrough</em>}</li>
  * </ul>
  * </p>
  *
@@ -42,6 +43,16 @@ public class InputVariableDeclarationImpl extends StatefulVariableDeclarationImp
 	 */
 	protected EList<ComputationCompound> feedingCompounds;
 
+	/**
+	 * The default value of the '{@link #isDirectFeedthrough() <em>Direct Feedthrough</em>}' attribute.
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @see #isDirectFeedthrough()
+	 * @generated
+	 * @ordered
+	 */
+	protected static final boolean DIRECT_FEEDTHROUGH_EDEFAULT = false;
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
@@ -73,6 +84,20 @@ public class InputVariableDeclarationImpl extends StatefulVariableDeclarationImp
 		return feedingCompounds;
 	}
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated NOT
+	 */
+	public boolean isDirectFeedthrough() {
+		for (ComputationCompound compound : getFeedingCompounds()) {
+			if (!compound.getOutputs().isEmpty()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	/**
 	 * <!-- begin-user-doc -->
 	 * <!-- end-user-doc -->
@@ -112,6 +137,8 @@ public class InputVariableDeclarationImpl extends StatefulVariableDeclarationImp
 		switch (featureID) {
 			case ILPackage.INPUT_VARIABLE_DECLARATION__FEEDING_COMPOUNDS:
 				return getFeedingCompounds();
+			case ILPackage.INPUT_VARIABLE_DECLARATION__DIRECT_FEEDTHROUGH:
+				return isDirectFeedthrough();
 		}
 		return super.eGet(featureID, resolve, coreType);
 	}
@@ -158,6 +185,8 @@ public class InputVariableDeclarationImpl extends StatefulVariableDeclarationImp
 		switch (featureID) {
 			case ILPackage.INPUT_VARIABLE_DECLARATION__FEEDING_COMPOUNDS:
 				return feedingCompounds != null && !feedingCompounds.isEmpty();
+			case ILPackage.INPUT_VARIABLE_DECLARATION__DIRECT_FEEDTHROUGH:
+				return isDirectFeedthrough() != DIRECT_FEEDTHROUGH_EDEFAULT;
 		}
 		return super.eIsSet(featureID);
 	}

+ 15 - 0
org.eclipselabs.mscript/plugins/org.eclipselabs.mscript.language/src/org/eclipselabs/mscript/language/il/util/ILUtil.java

@@ -11,8 +11,13 @@
 
 package org.eclipselabs.mscript.language.il.util;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipselabs.mscript.language.ast.Expression;
+import org.eclipselabs.mscript.language.il.ILFunctionDefinition;
+import org.eclipselabs.mscript.language.il.InputVariableDeclaration;
 import org.eclipselabs.mscript.language.internal.il.transform.DataTypeAdapter;
 import org.eclipselabs.mscript.typesystem.DataType;
 
@@ -36,4 +41,14 @@ public class ILUtil {
 		adapter.setDataType(dataType);
 	}
 	
+	public static List<InputVariableDeclaration> getDirectFeedthroughInputs(ILFunctionDefinition functionDefinition) {
+		List<InputVariableDeclaration> inputs = new ArrayList<InputVariableDeclaration>();
+		for (InputVariableDeclaration inputVariableDeclaration : functionDefinition.getInputVariableDeclarations()) {
+			if (inputVariableDeclaration.isDirectFeedthrough()) {
+				inputs.add(inputVariableDeclaration);
+			}
+		}
+		return inputs;
+	}
+
 }