Ejemplo n.º 1
0
        protected override string Translate(Computation.Rand node, CLike.Context context)
        {
            if (node.Empty)
            {
                return("");
            }

            StringBuilder ret = new StringBuilder();

            foreach (Computation.Rand.IndexRange range in node.Ranges(context.Program.StateTable))
            {
                ret.AppendFormat("\tfor ({0} = {1}; i <= {2}; ++i)",
                                 context.DeclareValueVariable("int", "i"),
                                 range.Start,
                                 range.End);

                ret.AppendLine();
                ret.AppendLine("\t{");

                ret.AppendFormat("\t\t{0}[i] = Cdn.Math.rand();",
                                 context.This(context.Program.StateTable));
                ret.AppendLine();
                ret.AppendLine("\t}");
            }

            ret.Append("}");

            return(ret.ToString());
        }
Ejemplo n.º 2
0
        protected override string Translate(InstructionRand instruction, CLike.Context context)
        {
            var val = base.Translate(instruction, context);

            if (val == null)
            {
                val = "Cdn.Math.rand";
            }

            return(val);
        }
Ejemplo n.º 3
0
        protected override string TranslateOperator(InstructionFunction instruction, CLike.Context context)
        {
            switch ((Cdn.MathFunctionType)instruction.Id)
            {
            case MathFunctionType.Modulo:
                return(SimpleOperator(context, instruction, " % "));

            default:
                return(base.TranslateOperator(instruction, context));
            }
        }
Ejemplo n.º 4
0
 protected override string Translate(Computation.ZeroMemory node, CLike.Context context)
 {
     if (node.Name == null)
     {
         return("this._clear_data();");
     }
     else
     {
         return(base.Translate(node, context));
     }
 }
Ejemplo n.º 5
0
        protected override string Translate(InstructionRand instruction, CLike.Context context)
        {
            string val = base.Translate(instruction, context);

            if (val == null)
            {
                val = "CDN_MATH_RAND()";
            }

            return(val);
        }
Ejemplo n.º 6
0
 protected override string Translate(Computation.ZeroMemory node, CLike.Context context)
 {
     // Override default copy loop for more efficient memset
     if (node.Name == null)
     {
         return(String.Format("memset (network, 0, CDN_RAWC_NETWORK_{0}_SIZE);", context.Options.CPrefixUp));
     }
     else
     {
         return(base.Translate(node, context));
     }
 }
Ejemplo n.º 7
0
        protected override string Translate(Computation.Rand node, CLike.Context context)
        {
            if (node.Empty)
            {
                return("");
            }

            StringBuilder ret = new StringBuilder();

            ret.AppendLine("{");
            ret.AppendLine("\tint i;");
            ret.AppendLine();

            foreach (Computation.Rand.IndexRange range in node.Ranges(context.Program.StateTable))
            {
                ret.AppendFormat("\tfor (i = {0}; i <= {1}; ++i)", range.Start, range.End);
                ret.AppendLine();
                ret.AppendLine("\t{");

                if (Cdn.RawC.Options.Instance.Validate)
                {
                    if (context.Program.NodeIsInitialization(node))
                    {
                        ret.AppendLine();
                        ret.AppendFormat("\t\tinitstate (rand_seeds[i - {0}], rand_states[i - {0}], sizeof(RandState));",
                                         range.ZeroOffset);
                    }
                    else
                    {
                        ret.AppendFormat("\t\tsetstate (rand_states[i - {0}]);", range.ZeroOffset);
                    }

                    ret.AppendLine();
                }

                ret.AppendFormat("\t\t{0}[i] = CDN_MATH_RAND ();",
                                 context.Program.StateTable.Name);
                ret.AppendLine();
                ret.AppendLine("\t}");
            }

            ret.Append("}");

            return(ret.ToString());
        }
Ejemplo n.º 8
0
 protected override string Translate(InstructionNumber instruction, CLike.Context context)
 {
     return(NumberTranslator.Translate(instruction.Value, (Context)context));
 }