Exemplo n.º 1
0
        public IEnumerable <EntryData> GetEntries()
        {
            //First we need the chain head.
            var chainhead = new ChainHead(FactomD);

            chainhead.Run(ChainID);

            //Now we can get the last entry block
            var eblock = new EntryBlock(FactomD);

            eblock.Run(chainhead.Result.result.chainHead);

            while (true)
            {
                //iterate each entry hash
                foreach (var entryitem in eblock.Result.result.entrylist)
                {
                    //Get the entry, and yield
                    var entry = new Entry(FactomD);
                    entry.Run(entryitem.Entryhash);
                    yield return(entry.Result.result.EntryData);
                }

                //Is there a previous entry/block to read?
                if (String.IsNullOrEmpty(eblock.Result.result.header.Prevkeymr))
                {
                    break;
                }
                //Request block
                eblock.Run(eblock.Result.result.header.Prevkeymr);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates LLVM code for the current method.
        /// </summary>
        public void GenerateCode()
        {
            // Seal the entry block
            EntryBlock.Seal();

            // Generate code for all blocks
            processedBasicBlocks.Clear();
            for (int blockIdx = postOrder.Count - 1; blockIdx >= 0; --blockIdx)
            {
                GenerateCodeForBlock(postOrder[blockIdx]);
            }
        }
Exemplo n.º 3
0
 public bool IsSimpleIf() =>
 HasElseBlock
     ? EntryBlock.HasSuccessor(IfBlock) &&
 EntryBlock.HasSuccessor(ElseBlock) &&
 // Check direct connection of the exit node
 IfBlock.Successors.Length == 1 &&
 IfBlock.Successors[0] == ExitBlock &&
 ElseBlock.Successors.Length == 1 &&
 ElseBlock.Successors[0] == ExitBlock
     : EntryBlock.HasSuccessor(IfBlock) &&
 EntryBlock.HasSuccessor(ExitBlock) &&
 // Check direct connection of the exit node
 IfBlock.Successors.Length == 1 &&
 IfBlock.Successors[0] == ExitBlock;
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Board board = new Board();

            EntryBlock           entry    = new EntryBlock(board);
            DeclareVariableBlock declare1 = new DeclareVariableBlock(board)
            {
                Variable = new Variable("a", 1)
            };
            DeclareVariableBlock declare2 = new DeclareVariableBlock(board)
            {
                Variable = new Variable("i", 1)
            };
            ConditionBlock small = new ConditionBlock(board, null, new ConditionBoolBlock(board, null)
            {
                Condition = new Condition()
                {
                    LType   = Condition.ValueType.Var,
                    L       = "i",
                    RType   = Condition.ValueType.Num,
                    R       = 10,
                    Compare = Condition.CompareType.Smaller
                }
            });
            ChangeVariableValueBlock change = new ChangeVariableValueBlock(board, null, "a", (a, i) => (dynamic)a * (dynamic)i)
            {
            };
            ChangeVariableValueBlock change2 = new ChangeVariableValueBlock(board, null, "i", (i, v) => (dynamic)i + (dynamic)v)
            {
            };

            Block.Connect(entry, declare1);
            Block.Connect(declare1, declare2);
            Block.Connect(declare2, small);
            Block.Connect(small, change);
            Block.Connect(change, change2);
            Block.Connect(change2, small);

            board.Entry = entry;
            board.Initialize();

            while (!board.Ended)
            {
                board.RunStep();
                board.PrintAllVariables();
            }

            Console.ReadLine();
        }
Exemplo n.º 5
0
        public MainForm()
        {
            InitializeComponent();
            EntryBlock entry = new EntryBlock();

            this.Controls.Add(entry.DrawPanel());
            manager = new BlockManager(entry);

            BlockManager.CurrentBlockManager = manager;
            DeclareVarBlock block = new DeclareVarBlock();

            entry.Connect(block);

            manager.Start();
            while (manager.ExecuteOneTime())
            {
                ;
            }
        }
Exemplo n.º 6
0
        public Form1()
        {
            //이것도 커밋해 보시지!!
            InitializeComponent();
            _board            = new Board();
            _control          = new BoardControl(_board);
            _control.Location = new Point(0, 0);
            _control.Size     = new Size(hScrollBar1.Maximum * 30 + Width, vScrollBar1.Maximum * 30 + Height);
            this.Controls.Add(_control);

            _control.Printed += _control_Printed;

            this.KeyDown += Form1_KeyDown;
            KeyPreview    = true;

            EntryBlock entry = new EntryBlock(_board);

            entry.Location = new Point(00, 50);
            _control.AddBlocks(entry);
            _board.Entry = entry;
        }
Exemplo n.º 7
0
 /// <summary cref="AssertCleared()"/>
 readonly partial void AssertCleared()
 {
     blockSet.Clear();
     EntryBlock.Assert(!HasAny && blockSet.Count == 0);
 }
Exemplo n.º 8
0
 /// <summary cref="AssertRemoved(BasicBlock, bool)"/>
 readonly partial void AssertRemoved(BasicBlock block, bool removed) =>
 EntryBlock.Assert(blockSet.Remove(block) == removed);
Exemplo n.º 9
0
 /// <summary cref="AssertContained(BasicBlock, bool)"/>
 readonly partial void AssertContained(BasicBlock block, bool contained) =>
 EntryBlock.Assert(blockSet.Contains(block) == contained);
Exemplo n.º 10
0
 /// <summary cref="AssertAdd(BasicBlock, bool)"/>
 readonly partial void AssertAdd(BasicBlock block, bool added) =>
 EntryBlock.Assert(blockSet.Add(block) == added);
Exemplo n.º 11
0
        /// <summary>
        /// Initializes args and locals for the current method.
        /// </summary>
        private void InitArgsAndLocals()
        {
            // Check for ssa variables
            for (int i = 0, e = disassembledMethod.Count; i < e; ++i)
            {
                var instruction = disassembledMethod[i];
                switch (instruction.InstructionType)
                {
                case ILInstructionType.Ldarga:
                    variables[new VariableRef(instruction.GetArgumentAs <int>(), VariableRefType.Argument)] =
                        default(Value);
                    break;

                case ILInstructionType.Ldloca:
                    variables[new VariableRef(instruction.GetArgumentAs <int>(), VariableRefType.Local)] =
                        default(Value);
                    break;
                }
            }

            CurrentBlock = EntryBlock;
            PositionBuilderAtEnd(Builder, CurrentBlock.LLVMBlock);

            // Init params
            var @params = GetParams(Function);

            if (Method.IsInstance)
            {
                // Broken, wegen ldarga.0 bei instance methods?
                // Da muss noch eine adresse her... nur woher genau?
                EntryBlock.SetValue(
                    new VariableRef(0, VariableRefType.Argument),
                    new Value(MethodBase.DeclaringType.MakePointerType(), @params[0]));
            }
            var methodParams = Method.MethodBase.GetParameters();

            for (int i = Method.ParameterOffset, e = @params.Length; i < e; ++i)
            {
                var param       = @params[i];
                var methodParam = methodParams[i - Method.ParameterOffset];
                var paramType   = methodParam.ParameterType.GetLLVMTypeRepresentation();
                var argRef      = new VariableRef(i, VariableRefType.Argument);
                if (variables.ContainsKey(argRef))
                {
                    // Address was taken... emit a temporary alloca and store the arg value to it
                    var alloca = BuildAlloca(Builder, TypeOf(param), methodParam.Name);
                    BuildStore(Builder, param, alloca);
                    variables[argRef] = new Value(paramType, alloca);
                }
                else
                {
                    // Use the current arg value to set the value in the first block
                    EntryBlock.SetValue(argRef, new Value(paramType, param));
                }
                variableTypes[argRef] = paramType;
            }

            // Init locals
            var localVariables = MethodBase.GetMethodBody().LocalVariables;

            for (int i = 0, e = localVariables.Count; i < e; ++i)
            {
                var variable     = localVariables[i];
                var variableType = variable.LocalType.GetLLVMTypeRepresentation();
                var localType    = Unit.GetType(variableType);
                var localRef     = new VariableRef(i, VariableRefType.Local);
                var initValue    = ConstNull(localType);
                if (variables.ContainsKey(localRef))
                {
                    // Address was taken... emit a temporary alloca and store empty value to it
                    var alloca = BuildAlloca(Builder, localType, string.Empty);
                    BuildStore(Builder, initValue, alloca);
                    variables[localRef] = new Value(variableType, alloca);
                }
                else
                {
                    EntryBlock.SetValue(localRef, new Value(variableType, initValue));
                }
                variableTypes[localRef] = variableType;
            }
        }
Exemplo n.º 12
0
 // Create the special blocks attached to the method entry / exit.
 private void CreateEntryAndExitBlocks(Method method, StatementList blocks) {
   entry_point       = new EntryBlock(new MethodHeader(method));
   exit_point        = new ExitBlock();
   normal_exit_point = new NormalExitBlock();
   excp_exit_point   = new ExcpExitBlock(method);
 }
Exemplo n.º 13
0
 public EntryBlockControl(EntryBlock block)
 {
     InitializeComponent();
     _block = block;
 }