Ejemplo n.º 1
0
        /// <summary>
        /// Construct a ForExpr with an attribute and an unroll depth.
        /// </summary>
        /// <param name="initializer">Initializer expression.</param>
        /// <param name="test">Test expression, must evaluate to a scalar boolean.</param>
        /// <param name="update">Update expression.</param>
        /// <param name="attributes">Loop attribute.</param>
        /// <param name="unrollDepth">Depth with which to unroll the loop, used with LoopAttributes.UNROLL</param>
        public ForExpr(DeclExpr initializer, Expr test, Expr update, LoopAttributes attributes, int unrollDepth)
        {
            if (!test.HasValue())
                throw new HlslDomException("Test expression doesn't return a value!");

            if (!(test.Value.ValueType is BoolType))
                throw new HlslDomException("Test expression does not return a boolean value!");

            Initializer = initializer;
            Test = test;
            Update = update;
            Attributes = attributes;
            UnrollDepth = unrollDepth;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs an IfExpr with the provided test expression.
        /// </summary>
        /// <param name="test">The condition to test.</param>
        public IfExpr(Expr test)
        {
            if (!test.HasValue())
                throw new HlslDomException("Test expression doesn't return a value!");

            if (!(test.Value.ValueType is BoolType))
                throw new HlslDomException("Test expression doesn't evaluate to a boolean type!");

            Test = test;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Construct a ForExpr.
 /// </summary>
 /// <param name="initializer">Initializer expression.</param>
 /// <param name="test">Test expression, must evaluate to a scalar boolean.</param>
 /// <param name="update">Update expression.</param>
 public ForExpr(DeclExpr initializer, Expr test, Expr update)
     : this(initializer, test, update, (int)LoopAttributes.NO_ATTRIBUTE, 0)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a ForExpr with an attribute.
 /// </summary>
 /// <param name="initializer">Initializer expression.</param>
 /// <param name="test">Test expression, must evaluate to a scalar boolean.</param>
 /// <param name="update">Update expression.</param>
 /// <param name="attributes">Loop attribute.</param>
 public ForExpr(DeclExpr initializer, Expr test, Expr update, LoopAttributes attributes)
     : this(initializer, test, update, attributes, 0)
 {
     if (attributes == LoopAttributes.UNROLL)
         throw new HlslDomException("Unroll attribute specified without an unroll depth!");
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a variable declaration initialized to the value of the given expression.
        /// </summary>
        /// <param name="expression">Expression; must resolve to a value.</param>
        public DeclExpr(Expr expression)
        {
            if (!expression.HasValue())
                throw new HlslDomException("Provided expression must resolve to a value!");

            Type = expression.Value.ValueType;
            Name = string.Format("var{0}", Counter++);
            InitValue = expression.Value;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a named variable declaration initialized to the value of the given expression.
        /// </summary>
        /// <param name="expression">Expression; must resolve to a value.</param>
        /// <param name="name">Variable name.</param>
        public DeclExpr(Expr expression, string name)
        {
            if (!expression.HasValue())
                throw new HlslDomException("Provided expression must resolve to a value!");

            Type = expression.Value.ValueType;
            Name = name;
            InitValue = expression.Value;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Add an expression to the body of this compound expression.
 /// </summary>
 /// <param name="expr">The expression to add</param>
 public void Add(Expr expr)
 {
     Body.Add(expr);
 }
Ejemplo n.º 8
0
        public CommaExpr(Expr lhs, Expr rhs)
        {
            if (!lhs.HasValue() || !rhs.HasValue())
                throw new HlslDomException("Both the left and right hand sides of the comma expression must have a value!");

            LHS = lhs;
            RHS = rhs;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Construct a CallExpr to the specified function with the specified parameters.
        /// </summary>
        /// <param name="fn">Function to call.</param>
        /// <param name="parameters">Parameters for function.</param>
        public CallExpr(Function fn, Expr[] parameters)
        {
            Fn = fn;
            Parameters = new Value[parameters.Length];

            for (int i = 0; i < parameters.Length; ++i)
                Parameters[i] = parameters[i].Value;

            if (!fn.IsValidCall(Parameters))
                throw new HlslDomException(string.Format("Call to {0} is not valid!", fn.Name));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Construct a ternary expression.
        /// </summary>
        /// <param name="testExpr">The value to perform the test on.</param>
        /// <param name="ifTrue">Expression value if the test evaluates to true.</param>
        /// <param name="ifFalse">Expression value if the test evaluates to false.</param>
        public TernaryExpr(Expr testExpr, Expr ifTrue, Expr ifFalse)
        {
            if (!(testExpr.Value.ValueType is BoolType))
                throw new HlslDomException("Ternary expression test must evaluate to a boolean type!");

            if (ifTrue.Value.ValueType != ifFalse.Value.ValueType)
                throw new HlslDomException("Both sides of the ternary expression must evaluate to the same type!");

            TestExpr = testExpr;
            IfTrue = ifTrue;
            IfFalse = ifFalse;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Construct a ReturnExpr.
 /// </summary>
 /// <param name="value">Value to return.</param>
 public ReturnExpr(Expr value)
 {
     ReturnValue = value;
 }