예제 #1
0
        /// <summary>
        /// Adds an instruction to this prologue.
        /// </summary>
        /// <param name="Instruction">The instruction to add to the prologue.</param>
        /// <returns>A unique tag that can be used to retrieve the instruction's codegen value.</returns>
        public UniqueTag AddInstruction(CodeBlock Instruction)
        {
            var tag = new UniqueTag();

            taggedInstructions.Add(new KeyValuePair <UniqueTag, CodeBlock>(tag, Instruction));
            return(tag);
        }
예제 #2
0
 /// <summary>
 /// Tags the given break and continue blocks with the given tag.
 /// </summary>
 /// <param name="Tag">The tag for a flow block.</param>
 /// <param name="BreakBlock">The 'break' basic block for the flow block.</param>
 /// <param name="ContinueBlock">The 'continue' basic block for the flow block.</param>
 public void TagFlowBlock(
     UniqueTag Tag,
     LLVMBasicBlockRef BreakBlock,
     LLVMBasicBlockRef ContinueBlock)
 {
     breakBlocks.Add(Tag, BreakBlock);
     continueBlocks.Add(Tag, ContinueBlock);
 }
예제 #3
0
        public IUnmanagedEmitVariable DeclareUnmanagedLocal(UniqueTag Tag, IVariableMember VariableMember)
        {
            var alloca      = new AllocaBlock(this, VariableMember.VariableType);
            var valueTag    = Prologue.AddInstruction(alloca);
            var taggedValue = new TaggedValueBlock(this, valueTag, alloca.Type);

            locals.Add(Tag, taggedValue);
            return(new AtAddressEmitVariable(taggedValue));
        }
예제 #4
0
 public TaggedValueBlock(
     ICodeGenerator CodeGenerator,
     UniqueTag Tag,
     IType Type)
 {
     this.codeGen = CodeGenerator;
     this.Tag     = Tag;
     this.valType = Type;
 }
예제 #5
0
 /// <summary>
 /// Creates a branching block from a tag and a Boolean
 /// that distinguishes between 'break' and 'continue' blocks.
 /// </summary>
 /// <param name="CodeGenerator">The code generator that creates the block.</param>
 /// <param name="Tag">The tag of the target block.</param>
 /// <param name="IsBreak"><c>true</c> creates a 'break' block, <c>false</c> creates a 'continue' block.</param>
 public BranchBlock(
     ICodeGenerator CodeGenerator,
     UniqueTag Tag,
     bool IsBreak)
 {
     this.codeGen = CodeGenerator;
     this.Tag     = Tag;
     this.IsBreak = IsBreak;
 }
예제 #6
0
 /// <summary>
 /// Creates a tagged flow block from the given tag and body.
 /// </summary>
 /// <param name="CodeGenerator">The code generator that creates the block.</param>
 /// <param name="Tag">A tag to which 'break' and 'continue' blocks can refer.</param>
 /// <param name="Body">The contents of the block.</param>
 public TaggedFlowBlock(
     ICodeGenerator CodeGenerator,
     UniqueTag Tag,
     CodeBlock Body)
 {
     this.codeGen = CodeGenerator;
     this.Tag     = Tag;
     this.Body    = Body;
 }
예제 #7
0
        /// <summary>
        /// Gets or creates the labeled block with the given label.
        /// </summary>
        /// <param name="Label">The labeled block's label, as a unique tag.</param>
        /// <returns>A basic block builder for the labeled block.</returns>
        public BasicBlockBuilder GetOrCreateLabeledBlock(UniqueTag Label)
        {
            BasicBlockBuilder result;

            if (!labeledBlocks.TryGetValue(Label, out result))
            {
                result = AppendBasicBlock(Label.Name);
                labeledBlocks[Label] = result;
            }
            return(result);
        }
예제 #8
0
        public IUnmanagedEmitVariable GetUnmanagedLocal(UniqueTag Tag)
        {
            TaggedValueBlock address;

            if (locals.TryGetValue(Tag, out address))
            {
                return(new AtAddressEmitVariable(address));
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
 public ICodeBlock EmitMarkLabel(UniqueTag Label)
 {
     return(new MarkLabelBlock(this, Label));
 }
예제 #10
0
 public IEmitVariable GetLocal(UniqueTag Tag)
 {
     return(GetUnmanagedLocal(Tag));
 }
예제 #11
0
 /// <summary>
 /// Gets the tagged value with the given tag.
 /// </summary>
 /// <param name="Tag">The tag of the value to retrieve.</param>
 /// <returns>The tagged value.</returns>
 public LLVMValueRef GetTaggedValue(UniqueTag Tag)
 {
     return(taggedValues[Tag]);
 }
예제 #12
0
 public ICodeBlock EmitBreak(UniqueTag Target)
 {
     return(new BranchBlock(this, Target, true));
 }
예제 #13
0
 /// <summary>
 /// Gets the 'continue' basic block for the given tag.
 /// </summary>
 /// <param name="Tag">The tag to find a 'continue' basic block for.</param>
 /// <returns>The 'continue' basic block.</returns>
 public LLVMBasicBlockRef GetContinueBlock(UniqueTag Tag)
 {
     return(continueBlocks[Tag]);
 }
예제 #14
0
 /// <summary>
 /// Gets the 'break' basic block for the given tag.
 /// </summary>
 /// <param name="Tag">The tag to find a 'break' basic block for.</param>
 /// <returns>The 'break' basic block.</returns>
 public LLVMBasicBlockRef GetBreakBlock(UniqueTag Tag)
 {
     return(breakBlocks[Tag]);
 }
예제 #15
0
 public ICodeBlock EmitGotoLabel(UniqueTag Label, ICodeBlock Condition)
 {
     return(new BranchLabelBlock(this, Label));
 }
예제 #16
0
 public ICodeBlock EmitTagged(UniqueTag Tag, ICodeBlock Contents)
 {
     return(new TaggedFlowBlock(this, Tag, (CodeBlock)Contents));
 }
예제 #17
0
 private LNode EncodeUniqueTag(UniqueTag tag, UniqueNameMap <UniqueTag> nameMap)
 {
     return(Factory.Id(nameMap[tag]));
 }
예제 #18
0
 public ICodeBlock EmitContinue(UniqueTag Target)
 {
     return(new BranchBlock(this, Target, false));
 }
예제 #19
0
 public IEmitVariable DeclareLocal(UniqueTag Tag, IVariableMember VariableMember)
 {
     return(DeclareUnmanagedLocal(Tag, VariableMember));
 }
예제 #20
0
 /// <summary>
 /// Creates a code block that branches to a basic block with a label.
 /// </summary>
 /// <param name="CodeGenerator">The code generator.</param>
 /// <param name="Label">The label of the basic block to branch to.</param>
 public BranchLabelBlock(ICodeGenerator CodeGenerator, UniqueTag Label)
 {
     this.codeGen = CodeGenerator;
     this.Label   = Label;
 }
예제 #21
0
 /// <summary>
 /// Tags the given value with the given tag.
 /// </summary>
 /// <param name="Tag">The tag for the value.</param>
 /// <param name="Value">The value to tag.</param>
 public void TagValue(UniqueTag Tag, LLVMValueRef Value)
 {
     taggedValues.Add(Tag, Value);
 }