PreviousUpNext

15.4.341  src/lib/compiler/back/low/pwrpc32/emit/translate-machcode-to-asmcode-pwrpc32-g.codemade.pkg

## translate-machcode-to-asmcode-pwrpc32-g.codemade.pkg
#
# This file generated at   2015-12-06:08:43:06   by
#
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-translate-machcode-to-asmcode-xxx-g-package.pkg
#
# from the architecture description file
#
#     src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description
#
# Edits to this file will be LOST on next system rebuild.

# Compiled by:
#     src/lib/compiler/back/low/pwrpc32/backend-pwrpc32.lib


# We are invoked by:
#
#     src/lib/compiler/back/low/main/pwrpc32/backend-lowhalf-pwrpc32.pkg
#
stipulate
    package lem =  lowhalf_error_message;                                               # lowhalf_error_message         is from   src/lib/compiler/back/low/control/lowhalf-error-message.pkg
    package pp  =  standard_prettyprinter;                                              # standard_prettyprinter                is from   src/lib/prettyprint/big/src/standard-prettyprinter.pkg
    package rkj =  registerkinds_junk;                                          # registerkinds_junk            is from   src/lib/compiler/back/low/code/registerkinds-junk.pkg
herein

    generic package translate_machcode_to_asmcode_pwrpc32_g (
        #
        package cst: Codebuffer;                                                        # Codebuffer                    is from   src/lib/compiler/back/low/code/codebuffer.api
        
        package mcf: Machcode_Pwrpc32                                                   # Machcode_Pwrpc32              is from   src/lib/compiler/back/low/pwrpc32/code/machcode-pwrpc32.codemade.api
                     where
                         tcf == cst::pop::tcf;                          # "tcf" == "treecode_form".
        
        package crm: Compile_Register_Moves_Pwrpc32                                     # Compile_Register_Moves_Pwrpc32        is from   src/lib/compiler/back/low/pwrpc32/code/compile-register-moves-pwrpc32.api
                     where
                         mcf == mcf;
        
        package tce: Treecode_Eval                                                      # Treecode_Eval                 is from   src/lib/compiler/back/low/treecode/treecode-eval.api
                     where
                         tcf == mcf::tcf;                                       # "tcf" == "treecode_form".
        
    )
    : (weak) Machcode_Codebuffer_Pp
    {
                                                                                # Machcode_Codebuffer_Pp                is from   src/lib/compiler/back/low/emit/machcode-codebuffer-pp.api
        
        # Export to client packages:
        #
        package cst =  cst;                                                     # "cst"  == "codestream".
        package mcf =  mcf;                                                     # "mcf" == "machcode_form" (abstract machine code).
        
        stipulate
            package rgk =  mcf::rgk;            # "rgk" == "registerkinds".
            package tcf =  mcf::tcf;            # "tcf" == "treecode_form".
            package pop =  cst::pop;                                            # "pop" == "pseudo_op".
            package lac =  mcf::lac;                                            # "lac" == "late_constant".
        herein
        
        include package   asm_flags;                                                    # asm_flags             is from   src/lib/compiler/back/low/emit/asm-flags.pkg
        
        fun error msg
            =
            lem::error ("translate_machcode_to_asmcode_pwrpc32_g", msg);
        
        fun make_codebuffer (pp: pp::Pp) format_annotations
            =
            {   # stream = *asm_stream::asm_out_stream;                         # asm_stream            is from   src/lib/compiler/back/low/emit/asm-stream.pkg
        
                fun emit' s
                    =
                    pp.lit s;
        
                newline = REF TRUE;
                tabs    = REF 0;
        
                fun tabbing 0 => ();
                    tabbing n => { emit' "\t"; tabbing (n - 1); } ;
                end;
        
                fun emit s
                    =
                    {   tabbing *tabs;
                        tabs := 0;
                        newline := FALSE;
                        emit' s;
                    };
        
                fun nl     ()
                    =
                    {   tabs := 0;
                        if (not *newline)
                            #
                            newline := TRUE;
                            emit' "\n";
                        fi;
                    };
        
                fun comma  () =  emit ", ";
                fun tab    () =  tabs := 1;
                fun indent () =  tabs := 2;
        
                fun ms n
                    =
                    {   s = int::to_string n;
        
                        if (n < 0)   "-" + string::substring (s, 1, size s - 1);
                        else         s;
                        fi;
                    };
        
                fun put_label lab           = emit (pop::cpo::bpo::label_expression_to_string (tcf::LABEL lab));
                fun put_label_expression le = emit (pop::cpo::bpo::label_expression_to_string (tcf::LABEL_EXPRESSION le));
        
                fun put_const lateconst
                    =
                    emit (lac::late_constant_to_string  lateconst);
        
                fun put_int i
                    =
                    emit (ms i);
        
                fun paren f
                    =
                    {   emit "(";
                        f ();
                        emit ")";
                    };
        
                fun put_private_label  label
                    =
                    emit (pop::cpo::bpo::define_private_label label  +  "\n");
        
                fun put_public_label  label
                    =
                    put_private_label  label;
        
                fun put_comment  msg
                    =
                    {   tab ();
                        emit ("/* " + msg + " */");
                        nl ();
                    };
        
                fun put_bblock_note a
                    =
                    put_comment (note::to_string a);
        
                fun get_notes () =  error "get_notes";
                fun do_nothing _ =  ();
                fun fail _       =  raise exception DIE "asmcode-emitter";
        
                fun put_ramregion  ramregion
                    =
                    put_comment (mcf::rgn::ramregion_to_string  ramregion);
        
                put_ramregion
                    =
                    if *show_region    put_ramregion;
                    else               do_nothing;
                    fi;
        
                fun put_pseudo_op  pseudo_op
                    =
                    {   emit (pop::pseudo_op_to_string  pseudo_op);
                        emit "\n";
                    };
        
                fun init  size
                    =
                    {   put_comment ("Code Size = " + ms size);
                        nl ();
                    };
        
                put_register_info = asm_formatting_utilities::reginfo
                                         (emit, format_annotations);
        
                fun put_register r
                    =
                    {   emit (rkj::register_to_string r);
                        put_register_info r;
                    };
        
                fun put_registerset (title, registerset)
                    =
                    {   nl ();
                        put_comment  (title  +  rkj::cls::codetemplists_to_string  registerset);
                    };
        
                put_registerset
                    =
                    if *show_registerset   put_registerset;
                    else                   do_nothing;
                    fi;
        
                fun put_defs  registerset =  put_registerset ("defs: ", registerset);
                fun put_uses  registerset =  put_registerset ("uses: ", registerset);
        
                put_cuts_to
                    =
                    *show_cuts_to   ??   asm_formatting_utilities::put_cuts_to  emit
                                    ::   do_nothing;
        
                fun emitter instruction
                    =
                    {
                        # NB: The following incorrect-indentation problem is nontrivial to fix
                        #     so I'm just living with it for the moment.  -- 2011-05-14 CrT

        fun asm_spr (mcf::XER) => "xer";
            asm_spr (mcf::LR) => "lr";
            asm_spr (mcf::CTR) => "ctr";
        end

        also
        fun put_spr x 
            =
            emit (asm_spr x)

        also
        fun put_operand (mcf::REG_OP int_register) => put_register int_register;
            put_operand (mcf::IMMED_OP int) => put_int int;
            put_operand (mcf::LABEL_OP label_expression) => put_label_expression label_expression;
        end

        also
        fun asm_load (mcf::LBZ) => "lbz";
            asm_load (mcf::LBZE) => "lbze";
            asm_load (mcf::LHZ) => "lhz";
            asm_load (mcf::LHZE) => "lhze";
            asm_load (mcf::LHA) => "lha";
            asm_load (mcf::LHAE) => "lhae";
            asm_load (mcf::LWZ) => "lwz";
            asm_load (mcf::LWZE) => "lwze";
            asm_load (mcf::LDE) => "lde";
            asm_load (mcf::LBZU) => "lbzu";
            asm_load (mcf::LHZU) => "lhzu";
            asm_load (mcf::LHAU) => "lhau";
            asm_load (mcf::LWZU) => "lwzu";
            asm_load (mcf::LDZU) => "ldzu";
        end

        also
        fun put_load x 
            =
            emit (asm_load x)

        also
        fun asm_store (mcf::STB) => "stb";
            asm_store (mcf::STBE) => "stbe";
            asm_store (mcf::STH) => "sth";
            asm_store (mcf::STHE) => "sthe";
            asm_store (mcf::STW) => "stw";
            asm_store (mcf::STWE) => "stwe";
            asm_store (mcf::STDE) => "stde";
            asm_store (mcf::STBU) => "stbu";
            asm_store (mcf::STHU) => "sthu";
            asm_store (mcf::STWU) => "stwu";
            asm_store (mcf::STDU) => "stdu";
        end

        also
        fun put_store x 
            =
            emit (asm_store x)

        also
        fun asm_fload (mcf::LFS) => "lfs";
            asm_fload (mcf::LFSE) => "lfse";
            asm_fload (mcf::LFD) => "lfd";
            asm_fload (mcf::LFDE) => "lfde";
            asm_fload (mcf::LFSU) => "lfsu";
            asm_fload (mcf::LFDU) => "lfdu";
        end

        also
        fun put_fload x 
            =
            emit (asm_fload x)

        also
        fun asm_fstore (mcf::STFS) => "stfs";
            asm_fstore (mcf::STFSE) => "stfse";
            asm_fstore (mcf::STFD) => "stfd";
            asm_fstore (mcf::STFDE) => "stfde";
            asm_fstore (mcf::STFSU) => "stfsu";
            asm_fstore (mcf::STFDU) => "stfdu";
        end

        also
        fun put_fstore x 
            =
            emit (asm_fstore x)

        also
        fun asm_cmp (mcf::CMP) => "cmp";
            asm_cmp (mcf::CMPL) => "cmpl";
        end

        also
        fun put_cmp x 
            =
            emit (asm_cmp x)

        also
        fun asm_fcmp (mcf::FCMPO) => "fcmpo";
            asm_fcmp (mcf::FCMPU) => "fcmpu";
        end

        also
        fun put_fcmp x 
            =
            emit (asm_fcmp x)

        also
        fun asm_unary (mcf::NEG) => "neg";
            asm_unary (mcf::EXTSB) => "extsb";
            asm_unary (mcf::EXTSH) => "extsh";
            asm_unary (mcf::EXTSW) => "extsw";
            asm_unary (mcf::CNTLZW) => "cntlzw";
            asm_unary (mcf::CNTLZD) => "cntlzd";
        end

        also
        fun put_unary x 
            =
            emit (asm_unary x)

        also
        fun asm_funary (mcf::FMR) => "fmr";
            asm_funary (mcf::FNEG) => "fneg";
            asm_funary (mcf::FABS) => "fabs";
            asm_funary (mcf::FNABS) => "fnabs";
            asm_funary (mcf::FSQRT) => "fsqrt";
            asm_funary (mcf::FSQRTS) => "fsqrts";
            asm_funary (mcf::FRSP) => "frsp";
            asm_funary (mcf::FCTIW) => "fctiw";
            asm_funary (mcf::FCTIWZ) => "fctiwz";
            asm_funary (mcf::FCTID) => "fctid";
            asm_funary (mcf::FCTIDZ) => "fctidz";
            asm_funary (mcf::FCFID) => "fcfid";
        end

        also
        fun put_funary x 
            =
            emit (asm_funary x)

        also
        fun asm_farith (mcf::FADD) => "fadd";
            asm_farith (mcf::FSUB) => "fsub";
            asm_farith (mcf::FMUL) => "fmul";
            asm_farith (mcf::FDIV) => "fdiv";
            asm_farith (mcf::FADDS) => "fadds";
            asm_farith (mcf::FSUBS) => "fsubs";
            asm_farith (mcf::FMULS) => "fmuls";
            asm_farith (mcf::FDIVS) => "fdivs";
        end

        also
        fun put_farith x 
            =
            emit (asm_farith x)

        also
        fun asm_farith3 (mcf::FMADD) => "fmadd";
            asm_farith3 (mcf::FMADDS) => "fmadds";
            asm_farith3 (mcf::FMSUB) => "fmsub";
            asm_farith3 (mcf::FMSUBS) => "fmsubs";
            asm_farith3 (mcf::FNMADD) => "fnmadd";
            asm_farith3 (mcf::FNMADDS) => "fnmadds";
            asm_farith3 (mcf::FNMSUB) => "fnmsub";
            asm_farith3 (mcf::FNMSUBS) => "fnmsubs";
            asm_farith3 (mcf::FSEL) => "fsel";
        end

        also
        fun put_farith3 x 
            =
            emit (asm_farith3 x)

        also
        fun asm_arith (mcf::ADD) => "add";
            asm_arith (mcf::SUBF) => "subf";
            asm_arith (mcf::MULLW) => "mullw";
            asm_arith (mcf::MULLD) => "mulld";
            asm_arith (mcf::MULHW) => "mulhw";
            asm_arith (mcf::MULHWU) => "mulhwu";
            asm_arith (mcf::DIVW) => "divw";
            asm_arith (mcf::DIVD) => "divd";
            asm_arith (mcf::DIVWU) => "divwu";
            asm_arith (mcf::DIVDU) => "divdu";
            asm_arith (mcf::AND) => "and";
            asm_arith (mcf::OR) => "or";
            asm_arith (mcf::XOR) => "xor";
            asm_arith (mcf::NAND) => "nand";
            asm_arith (mcf::NOR) => "nor";
            asm_arith (mcf::EQV) => "eqv";
            asm_arith (mcf::ANDC) => "andc";
            asm_arith (mcf::ORC) => "orc";
            asm_arith (mcf::SLW) => "slw";
            asm_arith (mcf::SLD) => "sld";
            asm_arith (mcf::SRW) => "srw";
            asm_arith (mcf::SRD) => "srd";
            asm_arith (mcf::SRAW) => "sraw";
            asm_arith (mcf::SRAD) => "srad";
        end

        also
        fun put_arith x 
            =
            emit (asm_arith x)

        also
        fun asm_arithi (mcf::ADDI) => "addi";
            asm_arithi (mcf::ADDIS) => "addis";
            asm_arithi (mcf::SUBFIC) => "subfic";
            asm_arithi (mcf::MULLI) => "mulli";
            asm_arithi (mcf::ANDI_RC) => "andi.";
            asm_arithi (mcf::ANDIS_RC) => "andis.";
            asm_arithi (mcf::ORI) => "ori";
            asm_arithi (mcf::ORIS) => "oris";
            asm_arithi (mcf::XORI) => "xori";
            asm_arithi (mcf::XORIS) => "xoris";
            asm_arithi (mcf::SRAWI) => "srawi";
            asm_arithi (mcf::SRADI) => "sradi";
        end

        also
        fun put_arithi x 
            =
            emit (asm_arithi x)

        also
        fun asm_rotate (mcf::RLWNM) => "rlwnm";
            asm_rotate (mcf::RLDCL) => "rldcl";
            asm_rotate (mcf::RLDCR) => "rldcr";
        end

        also
        fun put_rotate x 
            =
            emit (asm_rotate x)

        also
        fun asm_rotatei (mcf::RLWINM) => "rlwinm";
            asm_rotatei (mcf::RLWIMI) => "rlwimi";
            asm_rotatei (mcf::RLDICL) => "rldicl";
            asm_rotatei (mcf::RLDICR) => "rldicr";
            asm_rotatei (mcf::RLDIC) => "rldic";
            asm_rotatei (mcf::RLDIMI) => "rldimi";
        end

        also
        fun put_rotatei x 
            =
            emit (asm_rotatei x)

        also
        fun asm_ccarith (mcf::CRAND) => "crand";
            asm_ccarith (mcf::CROR) => "cror";
            asm_ccarith (mcf::CRXOR) => "crxor";
            asm_ccarith (mcf::CRNAND) => "crnand";
            asm_ccarith (mcf::CRNOR) => "crnor";
            asm_ccarith (mcf::CREQV) => "creqv";
            asm_ccarith (mcf::CRANDC) => "crandc";
            asm_ccarith (mcf::CRORC) => "crorc";
        end

        also
        fun put_ccarith x 
            =
            emit (asm_ccarith x)

        also
        fun asm_bit (mcf::LT) => "lt";
            asm_bit (mcf::GT) => "gt";
            asm_bit (mcf::EQ) => "eq";
            asm_bit (mcf::SO) => "so";
            asm_bit (mcf::FL) => "lt";
            asm_bit (mcf::FG) => "gt";
            asm_bit (mcf::FE) => "eq";
            asm_bit (mcf::FU) => "un";
            asm_bit (mcf::FX) => "lt";
            asm_bit (mcf::FEX) => "gt";
            asm_bit (mcf::VX) => "eq";
            asm_bit (mcf::OX) => "so";
        end

        also
        fun put_bit x 
            =
            emit (asm_bit x);

###line 634.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun emitx (s, mcf::REG_OP _) => if ((string::get_byte_as_char (s, (size s) - 1)) == 'e')
                                            #
                                            emit (string::substring (s, 0, 
                                                     (size s) - 1)); 
                                            emit "xe"; 
                                        else
                                            emit s; 
                                            emit "x"; 
                                        fi;
            emitx (s, _) => emit s;
        end;

###line 640.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_oerc { oe => FALSE, 
                     rc => FALSE
                   }
                => ();
            e_oerc { oe => FALSE, 
                     rc => TRUE
                   }
                => emit ".";
            e_oerc { oe => TRUE, 
                     rc => FALSE
                   }
                => emit "o";
            e_oerc { oe => TRUE, 
                     rc => TRUE
                   }
                => emit "o.";
        end;

###line 645.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_rc FALSE => "";
            e_rc TRUE => ".";
        end;

###line 648.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun cr_bit (cr, bit) 
            =
            (4 * (rkj::hardware_register_id_of cr)) + case bit
                                                          #
                                                          mcf::LT => 0;
                                                          mcf::GT => 1;
                                                          mcf::EQ => 2;
                                                          mcf::SO => 3;
                                                          mcf::FL => 0;
                                                          mcf::FG => 1;
                                                          mcf::FE => 2;
                                                          mcf::FU => 3;
                                                          mcf::FX => 0;
                                                          mcf::FEX => 1;
                                                          mcf::VX => 2;
                                                          mcf::OX => 3;
                                                      esac;

###line 655.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_crbit x 
            =
            emit (int::to_string (cr_bit x));

###line 657.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_lk TRUE => emit "l";
            e_lk FALSE => ();
        end;

###line 660.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_i (mcf::REG_OP _) => ();
            e_i _ => emit "i";
        end;

###line 663.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_bi (bo, bf, bit) 
            =
            case (bo, rkj::hardware_register_id_of bf)
                #
                (mcf::ALWAYS, _) => ();
                (mcf::COUNTER { cond => NULL, 
                                ...
                              }
, _                 ) => ();
                (_, 0) => emit (asm_bit bit);
                (_, n) => emit ((("4*cr" + (int::to_string n)) + "+") + (asm_bit bit));
            esac;

###line 669.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun put_bo bo 
            =
            emit case bo
                     #
                     mcf::TRUE => "t";
                     mcf::FALSE => "f";
                     mcf::ALWAYS => "";
                     mcf::COUNTER { eq_zero, 
                                    cond => NULL
                                  }
                         => if  eq_zero   "dz";
                            else   "dnz";
                            fi;
                     mcf::COUNTER { eq_zero, 
                                    cond => THE cc
                                  }
                         => if  eq_zero   "dz";
                            else   "dnz";
                            fi + if  cc   "t";
                                 else   "f";
                                 fi;
                 esac;

###line 680.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun e_me (THE me) => {   emit ", "; 
                                 put_int me; 
                             };
            e_me NULL => ();
        end;

###line 683.7 "src/lib/compiler/back/low/pwrpc32/pwrpc32.architecture-description"

        fun address (ra, mcf::REG_OP rb) => {   put_register ra; 
                                                emit ", "; 
                                                put_register rb; 
                                            };
            address (ra, d) => {   put_operand d; 
                                   emit "("; 
                                   put_register ra; 
                                   emit ")"; 
                               };
        end;

        fun put_op' instruction 
            =
            case instruction
                #
                mcf::LL { ld, 
                          rt, 
                          ra, 
                          d, 
                          ramregion
                        }
                    => {   emitx (asm_load ld, d); 
                           emit "\t"; 
                           put_register rt; 
                           emit ", "; 
                           address (ra, d); 
                           put_ramregion ramregion; 
                       };
                mcf::LF { ld, 
                          ft, 
                          ra, 
                          d, 
                          ramregion
                        }
                    => {   emitx (asm_fload ld, d); 
                           emit "\t"; 
                           put_register ft; 
                           emit ", "; 
                           address (ra, d); 
                           put_ramregion ramregion; 
                       };
                mcf::ST { st, 
                          rs, 
                          ra, 
                          d, 
                          ramregion
                        }
                    => {   emitx (asm_store st, d); 
                           emit "\t"; 
                           put_register rs; 
                           emit ", "; 
                           address (ra, d); 
                           put_ramregion ramregion; 
                       };
                mcf::STF { st, 
                           fs, 
                           ra, 
                           d, 
                           ramregion
                         }
                    => {   emitx (asm_fstore st, d); 
                           emit "\t"; 
                           put_register fs; 
                           emit ", "; 
                           address (ra, d); 
                           put_ramregion ramregion; 
                       };
                mcf::UNARY { oper, 
                             rt, 
                             ra, 
                             rc, 
                             oe
                           }
                    => {   put_unary oper; 
                           e_oerc { rc, 
                                    oe
                                  }

                           emit "\t"; 
                           put_register rt; 
                           emit ", "; 
                           put_register ra; 
                       };
                mcf::ARITH { oper, 
                             rt, 
                             ra, 
                             rb, 
                             rc, 
                             oe
                           }
                    => {   put_arith oper; 
                           e_oerc { rc, 
                                    oe
                                  }

                           emit "\t"; 
                           put_register rt; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_register rb; 
                       };
                mcf::ARITHI { oper, 
                              rt, 
                              ra, 
                              im
                            }
                    => {   put_arithi oper; 
                           emit "\t"; 
                           put_register rt; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_operand im; 
                       };
                mcf::ROTATE { oper, 
                              ra, 
                              rs, 
                              sh, 
                              mb, 
                              me
                            }
                    => {   put_rotate oper; 
                           emit "\t"; 
                           put_register ra; 
                           emit ", "; 
                           put_register rs; 
                           emit ", "; 
                           put_register sh; 
                           emit ", "; 
                           put_int mb; 
                           e_me me; 
                       };
                mcf::ROTATEI { oper, 
                               ra, 
                               rs, 
                               sh, 
                               mb, 
                               me
                             }
                    => {   put_rotatei oper; 
                           emit "\t"; 
                           put_register ra; 
                           emit ", "; 
                           put_register rs; 
                           emit ", "; 
                           put_operand sh; 
                           emit ", "; 
                           put_int mb; 
                           e_me me; 
                       };
                mcf::COMPARE { cmp, 
                               l, 
                               bf, 
                               ra, 
                               rb
                             }
                    => {   put_cmp cmp; 
                           e_i rb; 
                           emit "\t"; 
                           put_register bf; 
                           emit ", "; 
                           emit if  l   "1";
                                else   "0";
                                fi; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_operand rb; 
                       };
                mcf::FCOMPARE { cmp, 
                                bf, 
                                fa, 
                                fb
                              }
                    => {   put_fcmp cmp; 
                           emit "\t"; 
                           put_register bf; 
                           emit ", "; 
                           put_register fa; 
                           emit ", "; 
                           put_register fb; 
                       };
                mcf::FUNARY { oper, 
                              ft, 
                              fb, 
                              rc
                            }
                    => {   put_funary oper; 
                           e_rc rc; 
                           emit "\t"; 
                           put_register ft; 
                           emit ", "; 
                           put_register fb; 
                       };
                mcf::FARITH { oper, 
                              ft, 
                              fa, 
                              fb, 
                              rc
                            }
                    => {   put_farith oper; 
                           e_rc rc; 
                           emit "\t"; 
                           put_register ft; 
                           emit ", "; 
                           put_register fa; 
                           emit ", "; 
                           put_register fb; 
                       };
                mcf::FARITH3 { oper, 
                               ft, 
                               fa, 
                               fb, 
                               fc, 
                               rc
                             }
                    => {   put_farith3 oper; 
                           e_rc rc; 
                           emit "\t"; 
                           put_register ft; 
                           emit ", "; 
                           put_register fa; 
                           emit ", "; 
                           put_register fb; 
                           emit ", "; 
                           put_register fc; 
                       };
                mcf::CCARITH { oper, 
                               bt, 
                               ba, 
                               bb
                             }
                    => {   put_ccarith oper; 
                           emit "\t"; 
                           e_crbit bt; 
                           emit ", "; 
                           e_crbit ba; 
                           emit ", "; 
                           e_crbit bb; 
                       };
                mcf::MCRF { bf, 
                            bfa
                          }
                    => {   emit "mcrf\t"; 
                           put_register bf; 
                           emit ", "; 
                           put_register bfa; 
                       };
                mcf::MTSPR { rs, 
                             spr
                           }
                    => {   emit "mt"; 
                           put_register spr; 
                           emit "\t"; 
                           put_register rs; 
                       };
                mcf::MFSPR { rt, 
                             spr
                           }
                    => {   emit "mf"; 
                           put_register spr; 
                           emit "\t"; 
                           put_register rt; 
                       };
                mcf::LWARX { rt, 
                             ra, 
                             rb
                           }
                    => {   emit "lwarx\t"; 
                           put_register rt; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_register rb; 
                       };
                mcf::STWCX { rs, 
                             ra, 
                             rb
                           }
                    => {   emit "stwcx.\t"; 
                           put_register rs; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_register rb; 
                       };
                mcf::TW { to, 
                          ra, 
                          si
                        }
                    => {   emit "tw"; 
                           e_i si; 
                           emit "\t"; 
                           put_int to; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_operand si; 
                       };
                mcf::TD { to, 
                          ra, 
                          si
                        }
                    => {   emit "td"; 
                           e_i si; 
                           emit "\t"; 
                           put_int to; 
                           emit ", "; 
                           put_register ra; 
                           emit ", "; 
                           put_operand si; 
                       };
                mcf::BC { bo, 
                          bf, 
                          bit, 
                          address, 
                          lk, 
                          fall
                        }
                    => {   emit "b"; 
                           put_bo bo; 
                           e_lk lk; 
                           emit "\t"; 
                           e_bi (bo, bf, bit); 
                           emit ", "; 
                           put_operand address; 
                       };
                mcf::BCLR { bo, 
                            bf, 
                            bit, 
                            lk, 
                            labels
                          }
                    => {   emit "b"; 
                           put_bo bo; 
                           emit "lr"; 
                           e_lk lk; 
                           emit "\t"; 
                           e_bi (bo, bf, bit); 
                       };
                mcf::BB { address, 
                          lk
                        }
                    => {   emit "b"; 
                           e_lk lk; 
                           emit "\t"; 
                           put_operand address; 
                       };
                mcf::CALL { def, 
                            uses, 
                            cuts_to, 
                            ramregion
                          }
                    => {   emit "blrl"; 
                           put_ramregion ramregion; 
                           put_defs def; 
                           put_uses uses; 
                           put_cuts_to cuts_to; 
                       };
                mcf::SOURCE { } => emit "source";
                mcf::SINK { } => emit "sink";
                mcf::PHI { } => emit "phi";
            esac;
                        tab ();
                        put_op' instruction;
                        nl ();
                    }                                           # fun emitter
        
                also
                fun put_indented_instruction  instruction
                    =
                    {   indent ();
                        put_op instruction;
                        nl ();
                    }
        
                also
                fun put_instructions instructions
                    =
                    apply if *indent_copies   put_indented_instruction;
                          else put_op;
                          fi
                          instructions
        
                also
                fun put_op (mcf::NOTE { op, note } )
                        =>
                        {   put_comment (note::to_string note);
                            nl ();
                            put_op op;
                        };
        
                    put_op (mcf::LIVE { regs, spilled } )
                        =>
                        put_comment("live= " + rkj::cls::codetemplists_to_string regs +
                            "spilled= " + rkj::cls::codetemplists_to_string spilled);
        
                    put_op (mcf::DEAD { regs, spilled } )
                        =>
                        put_comment("dead= " + rkj::cls::codetemplists_to_string regs +                 # 'dead' here was 'killed' -- is there a critical difference?
                            "spilled= " + rkj::cls::codetemplists_to_string spilled);
        
                    put_op (mcf::BASE_OP i)
                        =>
                        emitter i;
        
                    put_op (mcf::COPY { kind=>rkj::INT_REGISTER, size_in_bits, src, dst, tmp } )
                        =>
                        put_instructions (crm::compile_int_register_moves { tmp, src, dst } );
        
                    put_op (mcf::COPY { kind=>rkj::FLOAT_REGISTER, size_in_bits, src, dst, tmp } )
                        =>
                        put_instructions (crm::compile_float_register_moves { tmp, src, dst } );
        
                    put_op _
                        =>
                        error "put_op";
                end;
        
                
                {
                  start_new_cccomponent => init,
                  put_pseudo_op,
                  put_op,
                  get_completed_cccomponent => fail,
                  put_private_label,
                  put_public_label,
                  put_comment,
                  put_fn_liveout_info => do_nothing,
                  put_bblock_note,
                  get_notes
                };
            };                                                                          # fun make_codebuffer
        end;                                                                            # stipulate
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext