Ejemplo n.º 1
0
 public InstructionStream(ProtoCore.Language langId, ProtoCore.Core core)
 {
     language        = langId;
     entrypoint      = Constants.kInvalidIndex;
     instrList       = new List <Instruction>();
     dependencyGraph = new ProtoCore.AssociativeGraph.DependencyGraph(core);
     xUpdateList     = new List <AssociativeGraph.UpdateNodeRef>();
 }
Ejemplo n.º 2
0
        private ProtoLanguage.CompileStateTracker Compile(out int blockId)
        {
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            compileState = ProtoScript.CompilerUtils.BuildDebuggertCompilerState();
            compileState.CurrentDSFileName = core.CurrentDSFileName;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;



                compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink);

                compileState.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);


                // This is the boundary between compilestate and runtime core
                // Generate the executable
                compileState.GenerateExecutable();

                // Get the executable from the compileState
                core.DSExecutable = compileState.DSExecutable;

                core.Rmem.PushGlobFrame(compileState.GlobOffset);
            }
            catch (Exception ex)
            {
                Messages.FatalCompileError fce = new Messages.FatalCompileError {
                    Message = ex.ToString()
                };

                Console.WriteLine(fce.Message);
                return(null);
            }

            return(compileState);
        }
Ejemplo n.º 3
0
        public CodeBlock(CodeBlockType type, ProtoCore.Language langId, int codeBlockId, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoLanguage.CompileStateTracker compileState = null)
        {
            blockType = type;

            parent   = null;
            children = new List <CodeBlock>();

            language         = langId;
            this.codeBlockId = codeBlockId;
            instrStream      = new InstructionStream(langId, compileState);

            symbolTable    = symbols;
            procedureTable = procTable;

            isBreakable = isBreakableBlock;
        }
        public bool Compile(string code, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            //compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState();

            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = code;

                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;

                compileState.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, compileState);

                // Save the global offset and restore after compilation
                int offsetRestore = compileState.GlobOffset;
                compileState.GlobOffset = Core.Rmem.Stack.Count;

                compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink);

                // Restore the global offset
                compileState.GlobOffset = offsetRestore;

                compileState.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(buildSucceeded);
        }
Ejemplo n.º 5
0
        public bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            if (astList.Count <= 0)
            {
                // Nothing to compile
                buildSucceeded = true;
            }
            else
            {
                try
                {
                    //defining the global Assoc block that wraps the entire .ds source file
                    ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                    globalBlock.language = ProtoCore.Language.kAssociative;
                    globalBlock.body     = string.Empty;
                    //the wrapper block can be given a unique id to identify it as the global scope
                    globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                    //passing the global Assoc wrapper block to the compiler
                    ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                    context.SetData(string.Empty, new Dictionary <string, object>(), null);
                    ProtoCore.Language id = globalBlock.language;


                    ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                    codeblock.Body.AddRange(astList);

                    core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock);

                    core.BuildStatus.ReportBuildResult();

                    buildSucceeded = core.BuildStatus.BuildSucceeded;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            return(buildSucceeded);
        }
        public bool Compile(string code, int currentBlockID, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                //globalBlock.language = ProtoCore.Language.kImperative;
                globalBlock.body = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                context.SetExprInterpreterProperties(currentBlockID, runtimeCore.RuntimeMemory, runtimeCore.watchClassScope, runtimeCore.DebugProps);
                ProtoCore.Language id = globalBlock.language;

                runtimeCore.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, Core);

                // Save the global offset and restore after compilation
                int offsetRestore = Core.GlobOffset;
                Core.GlobOffset = runtimeCore.RuntimeMemory.Stack.Count;

                Core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink);

                // Restore the global offset
                Core.GlobOffset = offsetRestore;

                Core.BuildStatus.ReportBuildResult();

                buildSucceeded = Core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(buildSucceeded);
        }
Ejemplo n.º 7
0
        public ProtoLanguage.CompileStateTracker Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId)
        {
            ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState();

            compileState.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = string.Empty;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;


                ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                codeblock.Body.AddRange(astList);

                compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink, codeblock);

                compileState.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(compileState);
        }
Ejemplo n.º 8
0
        private bool Compile(out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;
                core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink);

                core.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings);
                core.GenerateExecutable();
                core.Rmem.PushGlobFrame(core.GlobOffset);
            }
            catch (Exception ex)
            {
                Messages.FatalCompileError fce = new Messages.FatalCompileError {
                    Message = ex.ToString()
                };

                Console.WriteLine(fce.Message);
                return(false);
            }

            return(buildSucceeded);
        }
Ejemplo n.º 9
0
        private bool Compile(string code, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;


            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                // No More HashAngleReplace for unified parser (Fuqiang)
                //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code);

                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;


                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;
                core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink);

                core.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(buildSucceeded);
        }
Ejemplo n.º 10
0
        public bool CompileToVHDL(string topLevelModule, string filename)
        {
            // Execute and gather program data
            ProtoCore.CompileAndExecutePass.ProgramData programData = null;
            bool compileAndExecuteSuceeded = CompileAndExecutePass(filename, out programData);

            Validity.Assert(compileAndExecuteSuceeded == true);
            Validity.Assert(programData != null);

            ProtoCore.Options options = new ProtoCore.Options();
            options.CompilationTarget = ProtoCore.DSDefinitions.CompileTarget.VHDL;

            // Generate a new core and pass it the data gathered from the previous pass
            ProtoCore.Core core = new ProtoCore.Core(options);
            core.SetProgramData(programData);

            options.ExecutionMode = ProtoCore.ExecutionMode.Serial;
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kVHDL, new ProtoVHDL.Executive(core));
            core.Options.DumpByteCode = true;
            core.Options.Verbose      = true;

            core.VhdlCore = new ProtoCore.VHDL.VHDLCore(topLevelModule);

            System.IO.StreamReader reader = null;
            try
            {
                reader = new System.IO.StreamReader(filename, Encoding.UTF8, true);
            }
            catch (System.IO.IOException)
            {
                throw new Exception("Cannot open file " + filename);
            }

            string strSource = reader.ReadToEnd();

            reader.Dispose();

            core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(filename);
            core.CurrentDSFileName          = core.Options.RootModulePathName;
            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            bool buildSucceeded = false;

            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kVHDL;
                globalBlock.body     = strSource;

                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;
                int blockID = 0;
                core.Executives[id].Compile(out blockID, null, globalBlock, context);

                core.BuildStatus.ReportBuildResult();
                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(buildSucceeded);
        }