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


C# CGenState.CGenLabel方法代码示例

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


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

示例1: CGenDecln

        public void CGenDecln(Env env, CGenState state) {
            //     .text
            //     [.globl <func>]
            // <func>:
            //     pushl %ebp
            //     movl %esp, %ebp
            // 
            state.TEXT();
            Env.Entry entry = env.Find(this.name).Value;
            state.COMMENT(ToString());
            switch (entry.Kind) {
            case Env.EntryKind.GLOBAL:
                switch (this.scs) {
                case StorageClass.AUTO:
                case StorageClass.EXTERN:
                    state.GLOBL(this.name);
                    break;
                case StorageClass.STATIC:
                    // static definition
                    break;
                default:
                    throw new InvalidOperationException();
                }
                break;
            default:
                throw new InvalidOperationException();
            }
            state.CGenFuncStart(this.name);

            state.InFunction(GotoLabelsGrabber.GrabLabels(this.stmt));

            this.stmt.CGenStmt(env, state);

            state.CGenLabel(state.ReturnLabel);
            state.OutFunction();

            //     leave
            //     ret
            state.LEAVE();
            state.RET();
            state.NEWLINE();
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:42,代码来源:ExternalDefinitions.cs

示例2: CGenDecln

        // * function;
        // * extern function;
        // * static function;
        // * obj;
        // * obj = Init;
        // * static obj;
        // * static obj = Init;
        // * extern obj;
        // * extern obj = Init;
        public void CGenDecln(Env env, CGenState state) {

            if (env.IsGlobal()) {

                if (this.initr.IsSome) {
                    Initr initr = this.initr.Value;
                    switch (this.scs) {
                        case StorageClass.AUTO:
                            state.GLOBL(this.name);
                            break;

                        case StorageClass.EXTERN:
                            throw new InvalidProgramException();

                        case StorageClass.STATIC:
                            break;

                        case StorageClass.TYPEDEF:
                            // Ignore.
                            return;

                        default:
                            throw new InvalidProgramException();
                    }

                    state.DATA();

                    state.ALIGN(ExprType.ALIGN_LONG);

                    state.CGenLabel(this.name);

                    Int32 last = 0;
                    initr.Iterate(this.type, (Int32 offset, Expr expr) => {
                        if (offset > last) {
                            state.ZERO(offset - last);
                        }

                        if (!expr.IsConstExpr) {
                            throw new InvalidOperationException("Cannot initialize with non-const expression.");
                        }

                        switch (expr.Type.Kind) {
                            // TODO: without const char/short, how do I initialize?
                            case ExprTypeKind.CHAR:
                            case ExprTypeKind.UCHAR:
                            case ExprTypeKind.SHORT:
                            case ExprTypeKind.USHORT:
                                throw new NotImplementedException();
                            case ExprTypeKind.LONG:
                                state.LONG(((ConstLong)expr).Value);
                                break;

                            case ExprTypeKind.ULONG:
                                state.LONG((Int32)((ConstULong)expr).Value);
                                break;

                            case ExprTypeKind.POINTER:
                                state.LONG((Int32)((ConstPtr)expr).Value);
                                break;

                            case ExprTypeKind.FLOAT:
                                byte[] float_bytes = BitConverter.GetBytes(((ConstFloat)expr).Value);
                                Int32 intval = BitConverter.ToInt32(float_bytes, 0);
                                state.LONG(intval);
                                break;

                            case ExprTypeKind.DOUBLE:
                                byte[] double_bytes = BitConverter.GetBytes(((ConstDouble)expr).Value);
                                Int32 first_int = BitConverter.ToInt32(double_bytes, 0);
                                Int32 second_int = BitConverter.ToInt32(double_bytes, 4);
                                state.LONG(first_int);
                                state.LONG(second_int);
                                break;

                            default:
                                throw new InvalidProgramException();
                        }

                        last = offset + expr.Type.SizeOf;
                    });

                } else {

                    // Global without initialization.

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

                        case StorageClass.EXTERN:
//.........这里部分代码省略.........
开发者ID:phisiart,项目名称:C-Compiler,代码行数:101,代码来源:Declarations.cs

示例3: 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

示例4: CGenValue

        // 
        //          test Cond
        //          jz false ---+
        //          true_expr   |
        // +------- jmp finish  |
        // |    false: <--------+
        // |        false_expr
        // +--> finish:
        // 
        public override Reg CGenValue(CGenState state) {
            Int32 stack_size = state.StackSize;
            Reg ret = this.Cond.CGenValue(state);
            state.CGenForceStackSizeTo(stack_size);

            // test Cond
            switch (ret) {
                case Reg.EAX:
                    state.TESTL(Reg.EAX, Reg.EAX);
                    break;

                case Reg.ST0:
                    /// Compare Expr with 0.0
                    /// < see cref = "BinaryComparisonOp.OperateFloat(CGenState)" />
                    state.FLDZ();
                    state.FUCOMIP();
                    state.FSTP(Reg.ST0);
                    break;

                default:
                    throw new InvalidProgramException();
            }

            Int32 false_label = state.RequestLabel();
            Int32 finish_label = state.RequestLabel();

            state.JZ(false_label);

            this.TrueExpr.CGenValue(state);

            state.JMP(finish_label);

            state.CGenLabel(false_label);

            ret = this.FalseExpr.CGenValue(state);

            state.CGenLabel(finish_label);

            return ret;
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:49,代码来源:Expressions.cs

示例5: CGenStmt

        public override void CGenStmt(Env env, CGenState state) {
            Reg ret = CGenExprStmt(env, this.Cond, state);

            CGenTest(ret, state);

            Int32 false_label = state.RequestLabel();
            Int32 finish_label = state.RequestLabel();

            state.JZ(false_label);

            this.TrueStmt.CGenStmt(env, state);

            state.JMP(finish_label);

            state.CGenLabel(false_label);

            this.FalseStmt.CGenStmt(env, state);

            state.CGenLabel(finish_label);
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:20,代码来源:Statements.cs


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