示例#1
0
        public void ReloadRegPool(char type, int[] available_Regs)
        {
            if (type == 'v')
                vRegPool = new RegPool(available_Regs, log);
            else if (type == 's')
                sRegPool = new RegPool(available_Regs, log);
            else
                log.Error("'{0}' is an unknown type for a new RegPool (s or v only).", type);

        }
示例#2
0
 public void ReloadRegPool(char type, int[] available_Regs)
 {
     if (type == 'v')
     {
         vRegPool = new RegPool(available_Regs, log);
     }
     else if (type == 's')
     {
         sRegPool = new RegPool(available_Regs, log);
     }
     else
     {
         log.Error("'{0}' is an unknown type for a new RegPool (s or v only).", type);
     }
 }
示例#3
0
        public Variables(bool UseRegPool, bool CalcRegUsage, Log log)
        {
            this.log = log;

            if (UseRegPool)
            {
                sRegPool = new RegPool(log);
                vRegPool = new RegPool(log);
            }

            if (CalcRegUsage)
            {
                sRegUsageCalc = new RegUsageCalc(true);
                vRegUsageCalc = new RegUsageCalc(true);
            }
        }
示例#4
0
        public Variables(bool UseRegPool, bool CalcRegUsage, Log log)
        {
            this.log = log;

            if (UseRegPool)
            {
                sRegPool = new RegPool(log);
                vRegPool = new RegPool(log);
            }

            if (CalcRegUsage)
            {
                sRegUsageCalc = new RegUsageCalc(true);
                vRegUsageCalc = new RegUsageCalc(true);
            }
        }
示例#5
0
        public void AssignRegNumbers(List <Stmt> gcnStmts)
        {
            foreach (Stmt stmt in gcnStmts)
            {
                // note: When using the 'free' keyword, variables are freed before the previous statement.
                // Also, vars are freed before declarations so registers can be reused in the same instruction.
                log.lineNum = stmt.lineNum;

                ////////////////////// free the vars //////////////////////
                if (UsingRegPools)
                {
                    foreach (Variable v in stmt.freeVars)
                    {
                        if (v.stmtTerminated != v.stmtDeclared)
                        {
                            (v.isScaler ? sRegPool : vRegPool).FreeReg(v.regNo);
                        }
                        else
                        {
                            log.Warning("Variable, {0}, was declared and last used in the same statement.", v.name);
                        }
                    }
                }

                ////////////////////// declare new vars //////////////////////
                // we first add variables that specify a register or variables
                foreach (Variable v in stmt.newVars)
                {
                    if (v.isRegisterNumSpecifed && !v.isRegisterFromAnotherVar)
                    {
                        // Adds a GcnVar to the Vars collection and also makes sure that it is valid.
                        // Lets add mark that register as used in the pool (if it is in the pool)
                        RegPool regPool = v.isScaler ? sRegPool : vRegPool;
                        if (UsingRegPools)
                        {
                            if (regPool.ReserveSpecificRegs(v.regNo, v.RegsRequired) < 0)
                            {
                                log.Error("The registers, {1}, used in '{0}' must was not found in the allowed register pool.", v.regNo, v.name);
                            }
                        }

                        // lets calculate usage
                        RegUsageCalc regUsageCalc = v.isScaler ? sRegUsageCalc : vRegUsageCalc;
                        if (regUsageCalc != null)
                        {
                            regUsageCalc.AddToCalc(v.size, stmt);
                        }
                    }

                    // process declarations with variable as register reference
                    else if (v.isRegisterFromAnotherVar)
                    {
                        Variable lu;
                        if (!varsByName.TryGetValue(v.variablesRegToCopy, out lu))
                        {
                            log.Error("Variable, '{0}', could not be found.", v.variablesRegToCopy);
                        }
                        else if (lu.stmtTerminated == null)
                        {
                            log.Error("Variable, '{0}', can not use the same register as '{1}' because its still in use.", v.name, lu.name);
                        }
                        else
                        {
                            int     regNum  = lu.regNo + v.variablesRegToCopyIndex;
                            RegPool regPool = v.isScaler ? sRegPool : vRegPool;
                            if (UsingRegPools)
                            {
                                v.regNo = regPool.ReserveSpecificRegs(regNum, v.size);
                            }
                        }
                    }
                }

                foreach (Variable v in stmt.newVars)
                {
                    if (!v.isRegisterNumSpecifed) // exclude Registers with specified register numbers
                    {
                        v.regNo = (v.isScaler ? sRegPool : vRegPool).ReserveRegs(v.RegsRequired, v.RegsRequired);
                    }
                }

                // Replace the variables with register numbers.
                //if (stmt.vars.Count > 0)
                for (int i = stmt.vars.Count - 1; i >= 0; i--)
                {
                    VariableUsageLoc v = stmt.vars[i];
                    stmt.options = stmt.options.Remove(v.startPos, v.varLength).Insert(v.startPos, v.RegAsString);
                }
            }
        }