コード例 #1
0
        /// <summary>
        /// Writes code for return m_name.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Specification of algebra.</param>
        /// <param name="cgd">Not used yet.</param>
        public override void Write(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd)
        {
            if (m_type is G25.FloatType)
            {
                AppendTabs(SB);

                // Temp hack to override the float type:
                G25.FloatType FT = m_floatType; //m_type as G25.FloatType;

                // Should postops still be applied?  ApplyPostOp(S, plugins, cog, BL, valueStr);
                // Not required so far?
                SB.AppendLine(CodeUtil.GenerateScalarReturnCode(S, FT, m_mustCast, m_value));
            }
            else if (m_type is G25.SMV)
            {
                if (S.OutputC())
                {
                    bool ptr             = true;
                    bool declareVariable = false;
                    new AssignInstruction(m_nbTabs, m_type, m_floatType, m_mustCast, m_value, G25.fgs.RETURN_ARG_NAME, ptr, declareVariable, m_postOp, m_postOpValue).Write(SB, S, cgd);
                }
                else
                {
                    G25.SMV            smv = m_type as G25.SMV;
                    RefGA.BasisBlade[] BL  = BasisBlade.GetNonConstBladeList(smv);
                    bool     writeZeros    = true;
                    string[] valueStr      = CodeUtil.GetAssignmentStrings(S, m_floatType, m_mustCast, BL, m_value, writeZeros);

                    // apply post operation (like "/ n2")
                    ApplyPostOp(S, cgd, BL, valueStr);

                    SB.AppendLine(CodeUtil.GenerateReturnCode(S, smv, m_floatType, valueStr, m_nbTabs, writeZeros));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Writes code for m_name = m_value.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Specification of algebra.</param>
        /// <param name="cgd">Not used yet.</param>
        public override void Write(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd)
        {
            if (m_type is G25.SMV)
            {
                G25.SMV dstSmv = m_type as G25.SMV;

                if (m_declareVariable)
                {
                    SB.AppendLine("/* cannot yet assign and declare SMV type at the same time */");
                }

                RefGA.BasisBlade[] BL        = BasisBlade.GetNonConstBladeList(dstSmv);
                string[]           accessStr = CodeUtil.GetAccessStr(S, dstSmv, m_name, m_ptr);
                bool     writeZeros          = true;
                string[] valueStr            = CodeUtil.GetAssignmentStrings(S, m_floatType, m_mustCast, BL, m_value, writeZeros);

                // apply post operation (like "/ n2")
                ApplyPostOp(S, cgd, BL, valueStr);

                SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, m_nbTabs, writeZeros));
            }
            else if (m_type is G25.FloatType)
            {
                // temp hack to override float type.
                G25.FloatType FT = this.m_floatType; // m_type as G25.FloatType;

                AppendTabs(SB);

                if (m_declareVariable)
                { // also declare the variable right here?
                    // output "/t type "
                    SB.Append(FT.type + " ");
                }

                // output name = ....;
                RefGA.BasisBlade[] BL = new RefGA.BasisBlade[1] {
                    RefGA.BasisBlade.ONE
                };
                String[] accessStr = new String[1] {
                    m_name
                };
                bool     writeZeros = true;
                String[] valueStr   = CodeUtil.GetAssignmentStrings(S, FT, m_mustCast, BL, m_value, writeZeros);

                // apply post operation (like "/ n2")
                ApplyPostOp(S, cgd, BL, valueStr);

                SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, 0, writeZeros));
            }
            else
            {
                SB.AppendLine("/* to do: implement " + GetType().ToString() + " for type " + m_type.GetType().ToString() + " */");
            }
        }