public void StartBlock(Scope Scope, Action <CILEmitter> ScopeCode) { generator.BeginScope(); CILEmitter next = new CILEmitter(generator, mainType, currentMethod, Scope, parameters, this); ScopeCode(next); generator.EndScope(); }
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); } }
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; }
public void EmitIR(CILEmitter Emitter) { Emitter.StartBlock(Scope, (emitter) => { foreach (IStatement item in statements) { item.EmitIR(emitter); } } ); }
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); }
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); * } * }*/ }
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); } } }
protected virtual void LoadFirst(CILEmitter Emitter, bool Reference) { firstExpression.EmitIR(Emitter, Reference); }
public void EmitIR(CILEmitter Emitter) { }