コード例 #1
0
ファイル: Program.cs プロジェクト: mango007/JOSSystem
        /// <summary>
        /// for Output, Anti, Flow dependency, only need to check if the dependent statement is evaluated
        /// for Loop dependency, need further thinking
        /// </summary>
        /// <returns></returns>
        public bool IsIndependent(IntermediateCode ic)
        {
            foreach (var entry in ic.inEdge)
            {
                foreach (var type in entry.Value)
                {
                    switch (type)
                    {
                    case DependencyType.Output:
                    case DependencyType.Anti:
                    case DependencyType.Flow:
                    case DependencyType.Any:
                        if (!evaluatedIC.ContainsKey(entry.Key))
                        {
                            return(false);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: mango007/JOSSystem
 public void Translate()
 {
     IntermediateCode.ResetCount();
     EVariable.ResetCount();
     foreach (var stat in stats.GetStatementsList())
     {
         icList.AddRange(TranslateStatement(stat, this));
     }
     icList.Add(new ICAssignment(OperationType.Return, null, null, null));
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: mango007/JOSSystem
        // tranform intermediate code at runtime
        public static ICSequence TransformIntermediateCode(ETerminal condition, IntermediateCode code, Program program)
        {
            ICSequence re = new ICSequence();

            if (code is ICAssignment)
            {
                ICAssignment ica = (ICAssignment)code;
                if (ReferenceEquals(condition, null))
                {
                    re.Add(code);
                }
                else
                {
                    EVariable
                        result = ica.result,
                        temp1  = new EVariable(program, "$ICA_1_" + code.index),
                        temp2  = new EVariable(program, "$ICA_2_" + code.index),
                        temp3  = new EVariable(program, "$ICA_3_" + code.index),
                        temp4  = new EVariable(program, "$ICA_4_" + code.index);
                    ICAssignment
                    // condition * newResult + !condition * oldResult
                    // Command index is the same as the old command
                    // such that EVH and KH can receive the correct message.
                    // Commands generated at runtime cannot be run in parallel.
                        newCode      = new ICAssignment(ica.op, temp1, ica.operand1, ica.operand2, code.index),
                        notCondition = new ICAssignment(OperationType.NOT, temp2, condition, null, code.index),
                        term1Exp     = new ICAssignment(OperationType.Multiplication, temp3, condition, temp1, code.index),
                        term2Exp     = new ICAssignment(OperationType.Multiplication, temp4, temp2, result, code.index),
                        term3Exp     = new ICAssignment(OperationType.Addition, result, temp3, temp4, code.index);

                    re.AddRange(new ICAssignment[] { newCode, notCondition, term1Exp, term2Exp, term3Exp });
                }
            }
            else if (code is ICIfElse)
            {
                // for if-else statement, simply set the outerCondition
                ICIfElse icie = (ICIfElse)code;
                icie.outerCondition = condition;
                re.Add(icie);
            }
            else if (code is ICWhile)
            {
                ICWhile icw = (ICWhile)code;
                // outerCondition && while condition. This command will be executed very time condition codes are evaluated
                if (!ReferenceEquals(condition, null))
                {
                    EVariable temp1 = new EVariable(program, "&ICW_1_" + code.index);
                    icw.conditionCodes.Add(new ICAssignment(OperationType.AND, temp1, icw.condition, condition, icw.conditionCodes[icw.conditionCodes.Count - 1].index));
                    icw.condition = temp1;
                }
                ICSequence icwCodes = new ICSequence();
                foreach (var entry in icw.codes.GetCodes())
                {
                    // if statement is Assignment and result is a temporarily variable, no need to transform
                    if (entry is ICAssignment && ((ICAssignment)entry).result.isTemporary)
                    {
                        icwCodes.Add(entry);
                        continue;
                    }
                    icwCodes.AddRange(TransformIntermediateCode(icw.condition, entry, program));
                }
                icw.codes = icwCodes;
                re.Add(icw);
            }
            return(re);
        }
コード例 #4
0
 public void Add(IntermediateCode code)
 {
     icCodes.Add(code);
 }