示例#1
0
        public static IReadOnlyList <String> GrabLabels(Stmt stmt)
        {
            GotoLabelsGrabber grabber = new GotoLabelsGrabber();

            stmt.Accept(grabber);
            return(grabber.Labels);
        }
示例#2
0
        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();
        }
示例#3
0
 public static IReadOnlyList<String> GrabLabels(Stmt stmt) {
     GotoLabelsGrabber grabber = new GotoLabelsGrabber();
     stmt.Accept(grabber);
     return grabber.Labels;
 }