CreateGlobalFunctions() public method

public CreateGlobalFunctions ( ) : void
return void
Beispiel #1
0
    public CodeGen(Stmt stmt, string moduleName)
    {
        if (IO.Path.GetFileName(moduleName) != moduleName)
        {
            throw new System.Exception("can only output into current directory!");
        }

        Reflect.AssemblyName name        = new Reflect.AssemblyName(IO.Path.GetFileNameWithoutExtension(moduleName));
        Emit.AssemblyBuilder asmb        = System.AppDomain.CurrentDomain.DefineDynamicAssembly(name, Emit.AssemblyBuilderAccess.Save);
        Emit.ModuleBuilder   modb        = asmb.DefineDynamicModule(moduleName);
        Emit.TypeBuilder     typeBuilder = modb.DefineType("Foo");

        Emit.MethodBuilder methb = typeBuilder.DefineMethod("Main", Reflect.MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);

        // CodeGenerator
        this.il          = methb.GetILGenerator();
        this.symbolTable = new Collections.Dictionary <string, Emit.LocalBuilder>();

        // Go Compile!
        this.GenStmt(stmt);

        il.Emit(Emit.OpCodes.Ret);
        typeBuilder.CreateType();
        modb.CreateGlobalFunctions();
        asmb.SetEntryPoint(methb);
        asmb.Save(moduleName);
        this.symbolTable = null;
        this.il          = null;
    }
Beispiel #2
0
        private void CompileMainClass(Node ActiveNode)
        {
            Emit.TypeBuilder _TypeBuilder =
                TypeTable[ActiveNode.Nodes[1].Value];

            Emit.MethodBuilder MethBuilder = _TypeBuilder.DefineMethod("Main", Reflect.MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);
            this.AssemblerGenerator = MethBuilder.GetILGenerator();
            CurrentType             = _TypeBuilder;
            OpenBlockVariables();
            CreateCode(ActiveNode.Nodes[14]);


            CreateCode(ActiveNode.Nodes[15]);
            CloseBlockVariables();
            // Отладочные команды
            AssemblerGenerator.Emit(Emit.OpCodes.Ldstr, "Programm was finished. Press Enter key to quit...");
            AssemblerGenerator.Emit(Emit.OpCodes.Call,
                                    typeof(System.Console).GetMethod("WriteLine", new System.Type[] { typeof(string) }));
            AssemblerGenerator.Emit(Emit.OpCodes.Call,
                                    typeof(System.Console).GetMethod("ReadLine", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new System.Type[] { }, null));
            AssemblerGenerator.Emit(Emit.OpCodes.Pop);
            AssemblerGenerator.Emit(Emit.OpCodes.Ret);

            CreatedTypeTable[ActiveNode.Nodes[1].Value] = _TypeBuilder.CreateType();

            ModBuilder.CreateGlobalFunctions();
            AsmBuilder.SetEntryPoint(MethBuilder);
        }
Beispiel #3
0
        public CodeGenerator(Expression pExpression, String pModuleName, ref LogHandler rLogHandler)
        {
            _symbolTable  = new Dictionary <String, Emit.LocalBuilder>();
            _assemblyName = new Reflect.AssemblyName(Path.GetFileNameWithoutExtension(pModuleName));

            _statement = pExpression;

            //Init Assembly
            _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemblyName, Emit.AssemblyBuilderAccess.Save);
            _moduleBuilder   = _assemblyBuilder.DefineDynamicModule(pModuleName);
            _typeBuilder     = _moduleBuilder.DefineType("PascalCompilerType");
            _methodBuilder   = _typeBuilder.DefineMethod
                               (
                "Main",
                Reflect.MethodAttributes.Static,
                typeof(void),
                Type.EmptyTypes
                               );
            _ilGenerator = _methodBuilder.GetILGenerator();

            //Actual Work
            GenerateStatement(_statement, null);
            _ilGenerator.Emit(Emit.OpCodes.Ret);

            //Finalizing Work
            _typeBuilder.CreateType();
            _moduleBuilder.CreateGlobalFunctions();
            _assemblyBuilder.SetEntryPoint(_methodBuilder);
            _assemblyBuilder.Save(pModuleName);
        }
Beispiel #4
0
        private void finalizar(string nombreEjecutable)
        {
            //Asigno una pausa para indicar que finalizo la ejecucion del codigo objetivo generado
            anadirPausa();
            //Creo el assembler .net y defino las ultimas opciones de configuracion
            il.Emit(Emit.OpCodes.Ret);
            Type pp = typeBuilder.CreateType();

            modb.CreateGlobalFunctions();
            asmb.SetEntryPoint(methb, Reflect.Emit.PEFileKinds.ConsoleApplication);
            asmb.Save(IO.Path.GetFileName(nombreEjecutable));
            //Ahora procedo a limpiar la tabla de direcciones para su proximo uso.
            TablaDireccionesSimbolos.Clear();
            this.il = null;
        }
Beispiel #5
0
        public AssemblyGen(TypeDeclaration methodDec, string moduleName, string dllProbeDirectory)
        {
            if (IO.Path.GetFileName(moduleName) != moduleName)
            {
                throw new System.Exception("can only output into current directory!");
            }

            this.dllProbeDirectory = dllProbeDirectory;

            typeList = new List <TypeGen>();

            Reflect.AssemblyName name = new Reflect.AssemblyName(IO.Path.GetFileNameWithoutExtension(moduleName));
            Emit.AssemblyBuilder asmb = System.AppDomain.CurrentDomain.DefineDynamicAssembly(name, Emit.AssemblyBuilderAccess.Save);
            Emit.ModuleBuilder   modb = asmb.DefineDynamicModule(moduleName);
            GenerateType(methodDec, modb, dllProbeDirectory);
            modb.CreateGlobalFunctions();
            asmb.SetEntryPoint(GetEntryPoint());
            asmb.Save(moduleName);
        }
Beispiel #6
0
    public CodeGen(stmt stmt, string moduleName, int count)
    {
        if (IO.Path.GetFileName(moduleName) != moduleName)
        {
            throw new System.Exception("can only output into current directory!");
        }
        stmts = stmt;

        Reflect.AssemblyName name        = new Reflect.AssemblyName("FAJF"); //name of the assembly
        Emit.AssemblyBuilder asmb        = System.AppDomain.CurrentDomain.DefineDynamicAssembly(name, Emit.AssemblyBuilderAccess.Save);
        Emit.ModuleBuilder   modb        = asmb.DefineDynamicModule(moduleName);
        Emit.TypeBuilder     typeBuilder = modb.DefineType("resister"); //name of the class

        Emit.MethodBuilder methb = typeBuilder.DefineMethod("Main", Reflect.MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);

        // CodeGenerator
        this.il          = methb.GetILGenerator();
        this.symbolTable = new Collections.Dictionary <string, Emit.LocalBuilder>();
        counting         = 0;
        counter          = count;
        counters         = 0;



        // Go Compile!
        this.GenStmt(stmt);

        il.Emit(Emit.OpCodes.Ret);
        typeBuilder.CreateType();
        modb.CreateGlobalFunctions();
        asmb.SetEntryPoint(methb);
        asmb.Save(moduleName);
        // this.il.EmitWriteLine("press any key to continue");

        this.symbolTable = null;
        this.il          = null;
        System.Diagnostics.Process.Start(moduleName);
    }