Beispiel #1
0
        public override Expr reduce()
        {
            Expr x = gen();
            Temp t = new Temp(Type);

            CurrentGenerator.Temp(t);
            CurrentGenerator.Set(t, x);
            return(t);
        }
Beispiel #2
0
        public override Expr reduce()
        {
            foreach (var item in FunParams)
            {
                CurrentGenerator.Param(item);
            }
            Temp t = new Temp(Func.Params.ReturnType);

            CurrentGenerator.Temp(t);
            CurrentGenerator.Call(t, Func);
            CurrentGenerator.CallEnd();
            return(t);
        }
Beispiel #3
0
        public override Expr gen()
        {
            int  f = CurrentGenerator.AllocLabel();
            int  a = CurrentGenerator.AllocLabel();
            Temp t = new Temp(Type);

            CurrentGenerator.Temp(t);
            jumping(0, f);
            CurrentGenerator.Set(t, Constant.True);
            CurrentGenerator.Goto(a);
            CurrentGenerator.Label(f);
            CurrentGenerator.Set(t, Constant.False);
            CurrentGenerator.Label(a);
            return(t);
        }
Beispiel #4
0
 public override void gen(int begin, int after)
 {
     if (Parent.Params.ReturnType != ReserveType.Void)
     {
         if (!ReserveType.ConvertableT1T2(Parent.Params.ReturnType, ReturnVal.Type))
         {
             throw new TypeMisMatchException(this.lexline, ReturnVal.Type, Parent.Params.ReturnType.ToString());
         }
         Temp t = new Temp(Parent.Params.ReturnType);
         CurrentGenerator.Temp(t);
         new Set(t, ReturnVal).gen(begin, after);
         CurrentGenerator.Return(t);
     }
     else
     {
         CurrentGenerator.Return(null);
     }
     //emitLabel(Parent.ExitLabel);
 }
Beispiel #5
0
 public override void gen(int begin, int after)
 {
     if (Caller.FunParams.Count() > 0)
     {
         foreach (var item in Caller.FunParams)
         {
             if (item.Param is FuncCall)
             {
                 Temp t = new Temp(Caller.Func.Params.ReturnType);
                 CurrentGenerator.Temp(t);
                 emitfunSet(item.Param, t);
                 CurrentGenerator.Param(t);
             }
             else
             {
                 CurrentGenerator.Param(item);
             }
         }
     }
     CurrentGenerator.Label(CurrentGenerator.AllocLabel());
     CurrentGenerator.Call(Caller);
     CurrentGenerator.CallEnd();
 }
Beispiel #6
0
        //public int newlabel()
        //{
        //    return CurrentGenerator.AllocLabel();
        //}

        //public void emitLabel(int i)
        //{
        //    CurrentGenerator.Label("L" + i.ToString());

        //}

        //public void emit(string s)
        //{
        //    CurrentIO.EmitLine(s);
        //}

        //public void emitSrc(string s)
        //{
        //    CurrentIO.EmitSource(s);
        //}

        public void emitfunSet(Expr exp, Expr toVar)
        {
            FuncCall c = exp as FuncCall;

            if (c.FunParams?.Count() > 0)
            {
                foreach (PassParam item in c.FunParams)
                {
                    if (item.Param is FuncCall)
                    {
                        Temp t = new Temp(toVar.Type);
                        CurrentGenerator.Temp(t);
                        emitfunSet(item.Param, t);
                        CurrentGenerator.Param(t);
                    }
                    else
                    {
                        CurrentGenerator.Param(item);
                    }
                }
            }
            CurrentGenerator.Call(toVar, c.Func);
            CurrentGenerator.CallEnd();
        }