当前位置: 首页>>代码示例>>C#>>正文


C# CGenState.MOVL方法代码示例

本文整理汇总了C#中CodeGeneration.CGenState.MOVL方法的典型用法代码示例。如果您正苦于以下问题:C# CGenState.MOVL方法的具体用法?C# CGenState.MOVL怎么用?C# CGenState.MOVL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGeneration.CGenState的用法示例。


在下文中一共展示了CGenState.MOVL方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CGenPrepareIntegralOperands

        // %eax = left, %ebx = right, stack unchanged
        private void CGenPrepareIntegralOperands(CGenState state) {
            // 1. Load Left to EAX.
            // 
            // regs:
            // %eax = Left
            // 
            // stack:
            // +-----+
            // | ... | <- %esp
            // +-----+
            // 
            if (this.Left.CGenValue(state) != Reg.EAX) {
                throw new InvalidOperationException();
            }

            // 2. Push Left to stack.
            // 
            // regs:
            // %eax = Left
            // 
            // stack:
            // +-----+
            // | ... |
            // +-----+
            // | Left | <- %esp has decreased by 4
            // +-----+
            // 
            Int32 stack_size = state.CGenPushLong(Reg.EAX);

            // 3. Load Right to EAX.
            // 
            // regs:
            // %eax = Right
            // 
            // stack:
            // +-----+
            // | ... |
            // +-----+
            // | Left | <- %esp
            // +-----+
            // 
            if (this.Right.CGenValue(state) != Reg.EAX) {
                throw new InvalidOperationException();
            }

            // 4. Move Right into EBX. Pop Left from stack, into EAX.
            // 
            // regs:
            // %eax = Left
            // %ebx = Right
            // 
            // stack:
            // +-----+
            // | ... | <- %esp has moved back.
            // +-----+
            // 
            state.MOVL(Reg.EAX, Reg.EBX);
            state.CGenPopLong(stack_size, Reg.EAX);
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:60,代码来源:BinaryOperators.cs

示例2: CGenValue

 public override Reg CGenValue(CGenState state) {
     state.MOVL((Int32)this.Value, Reg.EAX);
     return Reg.EAX;
 }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:ConstExpressions.cs

示例3: CGenDecln


//.........这里部分代码省略.........
                        last = offset + expr.Type.SizeOf;
                    });

                } else {

                    // Global without initialization.

                    switch (this.scs) {
                        case StorageClass.AUTO:
                            // .comm name,size,align
                            break;

                        case StorageClass.EXTERN:
                            break;

                        case StorageClass.STATIC:
                            // .local name
                            // .comm name,size,align
                            state.LOCAL(this.name);
                            break;

                        case StorageClass.TYPEDEF:
                            // Ignore.
                            return;

                        default:
                            throw new InvalidProgramException();
                    }

                    if (this.type.Kind != ExprTypeKind.FUNCTION) {
                        state.COMM(this.name, this.type.SizeOf, ExprType.ALIGN_LONG);
                    }

                    
                }

                state.NEWLINE();

            } else {
                // stack object

                state.CGenExpandStackTo(env.StackSize, ToString());

                Int32 stack_size = env.StackSize;

                // pos should be equal to stack_size, but whatever...
                Int32 pos = env.Find(this.name).Value.Offset;
                if (this.initr.IsNone) {
                    return;
                }

                Initr initr = this.initr.Value;
                initr.Iterate(this.type, (Int32 offset, Expr expr) => {
                    Reg ret = expr.CGenValue(state);
                    switch (expr.Type.Kind) {
                        case ExprTypeKind.CHAR:
                        case ExprTypeKind.UCHAR:
                            state.MOVB(Reg.EAX, pos + offset, Reg.EBP);
                            break;

                        case ExprTypeKind.SHORT:
                        case ExprTypeKind.USHORT:
                            state.MOVW(Reg.EAX, pos + offset, Reg.EBP);
                            break;

                        case ExprTypeKind.DOUBLE:
                            state.FSTPL(pos + offset, Reg.EBP);
                            break;

                        case ExprTypeKind.FLOAT:
                            state.FSTPS(pos + offset, Reg.EBP);
                            break;

                        case ExprTypeKind.LONG:
                        case ExprTypeKind.ULONG:
                        case ExprTypeKind.POINTER:
                            state.MOVL(Reg.EAX, pos + offset, Reg.EBP);
                            break;

                        case ExprTypeKind.STRUCT_OR_UNION:
                            state.MOVL(Reg.EAX, Reg.ESI);
                            state.LEA(pos + offset, Reg.EBP, Reg.EDI);
                            state.MOVL(expr.Type.SizeOf, Reg.ECX);
                            state.CGenMemCpy();
                            break;

                        case ExprTypeKind.ARRAY:
                        case ExprTypeKind.FUNCTION:
                            throw new InvalidProgramException($"How could a {expr.Type.Kind} be in a init list?");

                        default:
                            throw new InvalidProgramException();
                    }

                    state.CGenForceStackSizeTo(stack_size);

                });

            } // stack object
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:101,代码来源:Declarations.cs

示例4: CGenValue

        public override sealed Reg CGenValue(CGenState state) {

            // 1. Get the address of expr.
            // 
            // regs:
            // %eax = &expr
            // 
            // stack:
            // +-------+
            // | ..... | <- %esp
            // +-------+
            // 
            this.Expr.CGenAddress(state);

            // 2. Push address.
            // 
            // regs:
            // %eax = &expr
            // 
            // stack:
            // +-------+
            // | ..... |
            // +-------+
            // | &expr | <- %esp
            // +-------+
            // 
            Int32 stack_size = state.CGenPushLong(Reg.EAX);

            // 3. Get current Value of expr.
            // 
            // 1) If expr is an integral or pointer:
            // 
            // regs:
            // %eax = expr
            // 
            // stack:
            // +-------+
            // | ..... |
            // +-------+
            // | &expr | <- %esp
            // +-------+
            // 
            // 
            // 2) If expr is a float:
            // 
            // regs:
            // %eax = &expr
            // 
            // stack:
            // +-------+
            // | ..... |
            // +-------+
            // | &expr | <- %esp
            // +-------+
            // 
            // float stack:
            // +-------+
            // | expr  | <- %st(0)
            // +-------+
            // 
            Reg ret = this.Expr.CGenValue(state);

            switch (ret) {
                case Reg.EAX:
                    // expr is an integral or pointer.

                    // 4. Pop address to %ecx.
                    // 
                    // regs:
                    // %eax = expr
                    // %ecx = &expr
                    // 
                    // stack:
                    // +-------+
                    // | ..... | <- %esp
                    // +-------+
                    // 
                    state.CGenPopLong(stack_size, Reg.ECX);

                    // 5. Cache current Value of Expr in %ebx.
                    // 
                    // regs:
                    // %eax = expr
                    // %ebx = expr
                    // %ecx = &expr
                    // 
                    // stack:
                    // +-------+
                    // | ..... | <- %esp
                    // +-------+
                    // 
                    state.MOVL(Reg.EAX, Reg.EBX);

                    // 6. Calculate the new value in %ebx or %eax and save.
                    //    Set %eax to be the return Value.
                    // 
                    // regs:
                    // %eax = expr or (expr +- 1)
                    // %ebx = (expr +- 1) or expr
                    // %ecx = &expr
//.........这里部分代码省略.........
开发者ID:phisiart,项目名称:C-Compiler,代码行数:101,代码来源:UnaryOperators.cs

示例5: CalcAndSavePtr

 public override void CalcAndSavePtr(CGenState state) {
     state.SUBL(this.Expr.Type.SizeOf, Reg.EAX);
     state.MOVL(Reg.EAX, 0, Reg.ECX);
 }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs

示例6: CalcAndSaveLong

 public override void CalcAndSaveLong(CGenState state) {
     state.SUBL(1, Reg.EAX);
     state.MOVL(Reg.EAX, 0, Reg.ECX);
 }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:4,代码来源:UnaryOperators.cs

示例7: CGenValue

        public override Reg CGenValue(CGenState state) {
            Reg ret = this.Expr.CGenValue(state);
            if (ret != Reg.EAX) {
                throw new InvalidProgramException();
            }
            if (this.Expr.Type.Kind != ExprTypeKind.POINTER) {
                throw new InvalidProgramException();
            }

            ExprType type = ((PointerType)this.Expr.Type).RefType;
            switch (type.Kind) {
                case ExprTypeKind.ARRAY:
                case ExprTypeKind.FUNCTION:
                    return Reg.EAX;

                case ExprTypeKind.CHAR:
                    state.MOVSBL(0, Reg.EAX, Reg.EAX);
                    return Reg.EAX;

                case ExprTypeKind.UCHAR:
                    state.MOVZBL(0, Reg.EAX, Reg.EAX);
                    return Reg.EAX;

                case ExprTypeKind.SHORT:
                    state.MOVSWL(0, Reg.EAX, Reg.EAX);
                    return Reg.EAX;

                case ExprTypeKind.USHORT:
                    state.MOVZWL(0, Reg.EAX, Reg.EAX);
                    return Reg.EAX;

                case ExprTypeKind.LONG:
                case ExprTypeKind.ULONG:
                case ExprTypeKind.POINTER:
                    state.MOVL(0, Reg.EAX, Reg.EAX);
                    return Reg.EAX;

                case ExprTypeKind.FLOAT:
                    state.FLDS(0, Reg.EAX);
                    return Reg.ST0;

                case ExprTypeKind.DOUBLE:
                    state.FLDL(0, Reg.EAX);
                    return Reg.ST0;

                case ExprTypeKind.STRUCT_OR_UNION:
                    //// %esi = src address
                    //state.MOVL(Reg.EAX, Reg.ESI);

                    //// %edi = dst address
                    //state.CGenExpandStackBy(Utils.RoundUp(Type.SizeOf, 4));
                    //state.LEA(0, Reg.ESP, Reg.EDI);

                    //// %ecx = nbytes
                    //state.MOVL(Type.SizeOf, Reg.ECX);

                    //state.CGenMemCpy();

                    //return Reg.STACK;
                    return Reg.EAX;

                case ExprTypeKind.VOID:
                default:
                    throw new InvalidProgramException();
            }
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:66,代码来源:Expressions.cs

示例8: CGenValue

        public override Reg CGenValue(CGenState state) {
            Int32 label_set = state.label_idx;
            state.label_idx++;
            Int32 label_finish = state.label_idx;
            state.label_idx++;

            Reg ret = this.Left.CGenValue(state);
            switch (ret) {
                case Reg.EAX:
                    state.TESTL(Reg.EAX, Reg.EAX);
                    state.JNZ(label_set);
                    break;

                case Reg.ST0:
                    state.FLDZ();
                    state.FUCOMIP();
                    state.FSTP(Reg.ST0);
                    state.JNZ(label_set);
                    break;

                default:
                    throw new InvalidProgramException();
            }

            ret = this.Right.CGenValue(state);
            switch (ret) {
                case Reg.EAX:
                    state.TESTL(Reg.EAX, Reg.EAX);
                    state.JNZ(label_set);
                    break;

                case Reg.ST0:
                    state.FLDZ();
                    state.FUCOMIP();
                    state.FSTP(Reg.ST0);
                    state.JNZ(label_set);
                    break;

                default:
                    throw new InvalidProgramException();
            }

            state.MOVL(0, Reg.EAX);

            state.JMP(label_finish);

            state.CGenLabel(label_set);

            state.MOVL(1, Reg.EAX);

            state.CGenLabel(label_finish);

            return Reg.EAX;
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:54,代码来源:BinaryOperators.cs

示例9: OperateULong

 public override void OperateULong(CGenState state) {
     state.CLTD();
     state.DIVL(Reg.EBX);
     state.MOVL(Reg.EDX, Reg.EAX);
 }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:5,代码来源:BinaryOperators.cs

示例10: CGenStmt

        public override void CGenStmt(Env env, CGenState state) {
            ExprType ret_type = env.GetCurrentFunction().ReturnType;

            Int32 stack_size = state.StackSize;

            if (this.ExprOpt.IsSome) {
                // Evaluate the Value.
                this.ExprOpt.Value.CGenValue(state);

                // If the function returns a struct, copy it to the address given by 8(%ebp).
                if (this.ExprOpt.Value.Type is StructOrUnionType) {
                    state.MOVL(Reg.EAX, Reg.ESI);
                    state.MOVL(2 * ExprType.SIZEOF_POINTER, Reg.EBP, Reg.EDI);
                    state.MOVL(this.ExprOpt.Value.Type.SizeOf, Reg.ECX);
                    state.CGenMemCpy();
                    state.MOVL(2 * ExprType.SIZEOF_POINTER, Reg.EBP, Reg.EAX);
                }

                // Restore stack size.
                state.CGenForceStackSizeTo(stack_size);
            }
            // Jump to end of the function.
            state.JMP(state.ReturnLabel);
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:24,代码来源:Statements.cs


注:本文中的CodeGeneration.CGenState.MOVL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。