예제 #1
0
        public void StartBlock(Scope Scope, Action <CILEmitter> ScopeCode)
        {
            generator.BeginScope();
            CILEmitter next = new CILEmitter(generator, mainType, currentMethod, Scope, parameters, this);

            ScopeCode(next);
            generator.EndScope();
        }
예제 #2
0
 public void EmitIR(CILEmitter Emitter, bool Reference)
 {
     LoadFirst(Emitter, Reference);
     foreach (OperatorPair <T> expr in simpleExpressions)
     {
         expr.Operand.EmitIR(Emitter, Reference);
         expr.Operand.Type.BinaryOperation(expr.Operator).EmitIR(Emitter);
     }
 }
예제 #3
0
 public CILEmitter(ILGenerator Generator, TypeBuilder MainType, MethodBuilder Current, Scope Scope, Parameters Parameters, CILEmitter Previous)
 {
     generator     = Generator;
     mainType      = MainType;
     currentMethod = Current;
     scope         = Scope;
     parameters    = Parameters;
     previous      = Previous;
 }
예제 #4
0
 public void EmitIR(CILEmitter Emitter)
 {
     Emitter.StartBlock(Scope,
                        (emitter) =>
     {
         foreach (IStatement item in statements)
         {
             item.EmitIR(emitter);
         }
     }
                        );
 }
예제 #5
0
        public void GenerateCIL(string Location)
        {
            AssemblyBuilder ab       = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("MiniPascal Assembly"), AssemblyBuilderAccess.Save, Location);
            ModuleBuilder   mb       = ab.DefineDynamicModule(Name);
            TypeBuilder     MainType = mb.DefineType("MainType", TypeAttributes.NotPublic | TypeAttributes.Abstract | TypeAttributes.Sealed);

            MethodBuilder main    = MainType.DefineMethod("main", MethodAttributes.Private | MethodAttributes.Static);
            ILGenerator   emitter = main.GetILGenerator();

            CILEmitter cilEmitter = new CILEmitter(emitter, MainType, main, null, null, null);

            statements.EmitIR(cilEmitter);
            cilEmitter.Return();

            Type mainTypeFinal = MainType.CreateType();

            ab.SetEntryPoint(main, PEFileKinds.ConsoleApplication);
            ab.Save(Name, PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64);
        }
예제 #6
0
        public void EmitIR(CILEmitter Emitter)
        {
            foreach (AssigmentStatement assigment in assigments)
            {
                assigment.EmitIR(Emitter);
            }

            /*
             * foreach (Variable variable in arguments.All)
             * {
             *  if (variable.IsReference)
             *  {
             *      Emitter.LoadVariable(variable.Identifier);
             *  }
             *  else
             *  {
             *      Emitter.LoadVariableAddress(variable.Identifier);
             *  }
             *  if (variable.Type.IsArray)
             *  {
             *      variable.Type.Size.EmitIR(Emitter, false);
             *      Emitter.LoadArrayIndexAddress();
             *  }
             *  //Emitter.CallRead(expr.Type);
             *  //Emitter.SaveReferenceVariable();
             * }
             * /*foreach (Variable prevVar in ToCall.Parameters.PreviousVariables)
             * {
             *  if (current.Variable(prevVar.Identifier).IsReference)
             *  {
             *      Emitter.LoadVariable(prevVar.Identifier);
             *  }
             *  else
             *  {
             *      Emitter.LoadVariableAddress(prevVar.Identifier);
             *  }
             * }*/
        }
예제 #7
0
 public void EmitIR(CILEmitter Emitter)
 {
     if (Type.IsArray)
     {
         foreach (Variable variable in variables)
         {
             Emitter.CreateArrayVariable(variable.Identifier, Type);
             Type.Size.EmitIR(Emitter, false);
             Emitter.PushArray(Type);
             Emitter.SaveVariable(variable.Identifier);
         }
     }
     else
     {
         foreach (Variable variable in variables)
         {
             Emitter.CreateSimpleVariable(variable.Identifier, Type);
             if (Type.Equals(MiniPascalType.Integer))
             {
                 Emitter.PushInt32(0);
             }
             else if (Type.Equals(MiniPascalType.Real))
             {
                 Emitter.PushSingle(0f);
             }
             else if (Type.Equals(MiniPascalType.String))
             {
                 Emitter.PushString("");
             }
             else if (Type.Equals(MiniPascalType.Boolean))
             {
                 Emitter.PushInt32(0);
             }
             Emitter.SaveVariable(variable.Identifier);
         }
     }
 }
예제 #8
0
 protected virtual void LoadFirst(CILEmitter Emitter, bool Reference)
 {
     firstExpression.EmitIR(Emitter, Reference);
 }
예제 #9
0
 public void EmitIR(CILEmitter Emitter)
 {
 }