Exemplo n.º 1
0
        public 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();
                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return buildSucceeded;
        }
Exemplo n.º 2
0
        public ProtoLanguage.CompileStateTracker Compile(ProtoCore.CompileTime.Context context, ProtoCore.Core core, out int blockId)
        {
            ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(core.Options.IsDeltaExecution);

            core.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;

                Validity.Assert(null != context.SourceCode && String.Empty != context.SourceCode);
                globalBlock.body = context.SourceCode;
                //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.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);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return compileState;
        }
Exemplo n.º 3
0
        private bool Compile(string code, ProtoCore.Core core, ProtoCore.CompileTime.Context context)
        {
            bool buildSucceeded = false;
            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.Associative;
                globalBlock.Code = code;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.Language id = globalBlock.Language;
                int blockId = Constants.kInvalidIndex;
                core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink);

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

            return buildSucceeded;
        }
Exemplo n.º 4
0
 public LanguageBlockNode(LanguageBlockNode rhs) : base(rhs)
 {
     codeblock = new ProtoCore.LanguageCodeBlock(rhs.codeblock);
     Attributes = new List<ImperativeNode>();
     foreach (ImperativeNode aNode in rhs.Attributes)
     {
         ImperativeNode newNode = ProtoCore.Utils.NodeUtils.Clone(aNode);
         Attributes.Add(newNode);
     }
 }
        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;
        }
Exemplo n.º 6
0
        private bool Compile(List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, ProtoCore.CompileTime.Context context)
        {
            bool buildSucceeded = false;
            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
                    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);

                    int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
                    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;
        }
        public ProtoLanguage.CompileStateTracker Compile(string code, ProtoCore.Core core, Dictionary <string, Object> contextData, out int blockId)
        {
            ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(core.Options.IsDeltaExecution, contextData);

            bool buildSucceeded = false;

            core.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     = 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 = buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(compileState);
        }
Exemplo n.º 9
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();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
                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);
        }
Exemplo n.º 10
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();
                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

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

            core.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);

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

                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;
        }
Exemplo n.º 12
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.Compilers[id].Compile(out blockId, null, globalBlock, context);

                core.BuildStatus.ReportBuildResult();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
                core.GenerateExecutable();

            }
            catch (Exception ex)
            {
                Messages.FatalCompileError fce = new Messages.FatalCompileError { Message = ex.ToString() };

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

            return buildSucceeded;
        }
Exemplo n.º 13
0
 public abstract bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock codeblock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink = null, ProtoCore.AST.Node codeBlockNode = null, ProtoCore.AssociativeGraph.GraphNode graphNode = null);
Exemplo n.º 14
0
 public LanguageBlockNode()
 {
     codeblock  = new ProtoCore.LanguageCodeBlock();
     Attributes = new List <ImperativeNode>();
 }
Exemplo n.º 15
0
        private ProtoLanguage.CompileStateTracker Compile(out int blockId)
        {
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            compileState = ProtoScript.CompilerUtils.BuildDebuggertCompilerState();

            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;
        }
Exemplo n.º 16
0
 public LanguageBlockNode()
 {
     codeblock = new ProtoCore.LanguageCodeBlock();
     Attributes = new List<AssociativeNode>();
 }
Exemplo n.º 17
0
        void ProtoScript()
        {
            script = new ProtoCore.Script();
            while (la.kind == 7) {
            ProtoCore.LanguageCodeBlock codeblock = new ProtoCore.LanguageCodeBlock();
            Get();
            Expect(1);
            if (0 == t.val.CompareTo(ProtoCore.DSASM.kw.imperative))
            {
                codeblock.language = ProtoCore.Language.kImperative;
            }
            else if (0 == t.val.CompareTo(ProtoCore.DSASM.kw.associative))
            {
                codeblock.language = ProtoCore.Language.kAssociative;
            }

            while (la.kind == 9) {
                Get();
                string key;
                Expect(1);
                key = t.val;
                Expect(10);
                Expect(4);
                if ("fingerprint" == key)
                {
                codeblock.fingerprint = t.val;
                codeblock.fingerprint = codeblock.fingerprint.Remove(0,1);
                codeblock.fingerprint = codeblock.fingerprint.Remove(codeblock.fingerprint.Length-1,1);
                }
                else if ("version" == key)
                {
                codeblock.version = t.val;
                codeblock.version = codeblock.version.Remove(0,1);
                codeblock.version = codeblock.version.Remove(codeblock.version.Length-1,1);
                }

            }
            Expect(8);
            Expect(6);
            codeblock.body = t.val;
            codeblock.body = codeblock.body.Remove(0, 2);
            codeblock.body = codeblock.body.Remove(codeblock.body.Length - 2, 2);

            script.codeblockList.Add(codeblock);
            }
        }
Exemplo n.º 18
0
        public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Validity.Assert(langBlock != null);
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            bool buildSucceeded = false;

            try
            {
                ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(core, callContext, parentBlock);

                codegen.context             = callContext;
                codegen.codeBlock.EventSink = sink;
                blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode);
            }
            catch (ProtoCore.BuildHaltException)
            {
            }

            buildSucceeded = core.BuildStatus.BuildSucceeded;
            return(buildSucceeded);
        }
Exemplo n.º 19
0
        public override bool Compile(ProtoLanguage.CompileStateTracker compileState, out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Debug.Assert(langBlock != null);
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            bool buildSucceeded      = false;
            bool isLanguageSignValid = isLanguageSignValid = compileState.Langverify.Verify(langBlock);

            if (isLanguageSignValid)
            {
                try
                {
                    ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(compileState, parentBlock);

                    codegen.context             = callContext;
                    codegen.codeBlock.EventSink = sink;
                    blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode);
                }
                catch (ProtoCore.BuildHaltException e)
                {
#if DEBUG
                    //core.BuildStatus.LogSemanticError(e.errorMsg);
#endif
                }

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            return(buildSucceeded);
        }
Exemplo n.º 20
0
        /// <summary>
        /// A list of the current known breakpoints
        /// Interact with through register and unregister methods
        /// </summary>
        

        #endregion

        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.Associative;
                globalBlock.Code = code;

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

                core.BuildStatus.ReportBuildResult();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
                core.GenerateExecutable();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }

            return buildSucceeded;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Does the first pass of compilation and returns a list of wanrnings in compilation
        /// </summary>
        /// <param name="code"></param>
        /// <param name="core"></param>
        /// <param name="blockId"></param>
        /// <returns></returns>
        public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlockNode codeBlock, out int blockId)
        {
            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.Associative;
                globalBlock.Code = code;

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

                core.Compilers[id].Compile(out blockId, null, globalBlock, context, codeBlockNode: codeBlock);

                core.BuildStatus.ReportBuildResult();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                if (!(ex is ProtoCore.BuildHaltException))
                {
                    throw ex;
                }
            }

            return core.BuildStatus;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Does the first pass of compilation and returns a list of wanrnings in compilation
        /// </summary>
        /// <param name="code"></param>
        /// <param name="core"></param>
        /// <param name="blockId"></param>
        /// <returns></returns>
        private static ProtoCore.BuildStatus PreCompile(string code, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;

            core.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 = 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);

                core.BuildStatus.ReportBuildResult();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                if (!(ex is ProtoCore.BuildHaltException))
                {
                    throw ex;
                }
            }

            return core.BuildStatus;
        }
Exemplo n.º 23
0
        public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Debug.Assert(langBlock != null);
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            bool buildSucceeded      = false;
            bool isLanguageSignValid = isLanguageSignValid = core.Langverify.Verify(langBlock);

            if (isLanguageSignValid)
            {
                try
                {
                    ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(core, parentBlock);

                    //(Fuqiang, Ayush) : The below code is to parse an Imperative code block. An imoerative code block should
                    // never need to be parsed at this stage, as it would be parsed by the Assoc parser.

                    //System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(langBlock.body));
                    //ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
                    //ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core);
                    //System.IO.StringWriter parseErrors = new System.IO.StringWriter();
                    //p.errors.errorStream = parseErrors;
                    //p.Parse();
                    //if (parseErrors.ToString() != String.Empty)
                    //{
                    //    core.BuildStatus.LogSyntaxError(parseErrors.ToString());
                    //}
                    //core.BuildStatus.errorCount += p.errors.count;

                    codegen.context             = callContext;
                    codegen.codeBlock.EventSink = sink;
                    blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode);
                }
                catch (ProtoCore.BuildHaltException e)
                {
#if DEBUG
                    //core.BuildStatus.LogSemanticError(e.errorMsg);
#endif
                }

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            return(buildSucceeded);
        }
Exemplo n.º 24
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);
        }