Ejemplo n.º 1
0
        public static IReadOnlyList <String> GrabLabels(Stmt stmt)
        {
            GotoLabelsGrabber grabber = new GotoLabelsGrabber();

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