PreviousUpNext

15.4.396  src/lib/compiler/back/low/tools/arch/adl-gen-instruction-props.pkg

## adl-gen-istruction-props.pkg -- derived from   ~/src/sml/nj/smlnj-110.60/MLRISC/Tools/ADL/mdl-gen-insnprops.sml
#
# Generate the <architecture>Props generic.
# This package extracts information about the instruction set.

# Compiled by:
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-packages.lib


stipulate
    package ard =  architecture_description;                            # architecture_description                              is from   src/lib/compiler/back/low/tools/arch/architecture-description.pkg
    package smj =  sourcecode_making_junk;                              # sourcecode_making_junk                                        is from   src/lib/compiler/back/low/tools/arch/sourcecode-making-junk.pkg
    package raw =  adl_raw_syntax_form;                                 # adl_raw_syntax_form                                   is from   src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.pkg
    package rsj =  adl_raw_syntax_junk;                                 # adl_raw_syntax_junk                                   is from   src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-junk.pkg
herein

    # This generic is invoked (only) in:
    #
    #     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-pwrpc32.pkg
    #     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-intel32.pkg
    #     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-sparc32.pkg
    #     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-packages.pkg
    #
    generic package   adl_gen_instruction_props   (
        #             =========================
        #
        arc:  Adl_Rtl_Comp                                              # Adl_Rtl_Comp                                          is from   src/lib/compiler/back/low/tools/arch/adl-rtl-comp.api
    )
    : (weak)   Adl_Gen_Module2                                          # Adl_Gen_Module2                                       is from   src/lib/compiler/back/low/tools/arch/adl-gen-module2.api
    {
        # Export to client packages:
        #
        package arc = arc;                                              # "arc" == "adl_rtl_compiler".

        stipulate
            package lct =  arc::lct;
            #
            include rsj;
        herein

            type_defs
                = 
                raw::VERBATIM_CODE [ "/* classify instructions */",
                      "enum kind = IK_JUMP   /* branches, including returns */",
                      "  | IK_NOP    /* no ops */",
                      "  | IK_INSTRUCTION  /* normal instructions */",
                      "  | IK_COPY   /* parallel copy */",
                      "  | IK_CALL   /* call instructions */",
                      "  | IK_PHI    /* A phi node (SSA) */",
                      "  | IK_SINK   /* A sink node (SSA) */",
                      "  | IK_SOURCE /* A source node (SSA) */",
                      "",
                      "enum target = LABELLED of label::label",
                      "                | FALLTHROUGH" ,
                      "                | ESCAPES",
                      "",
                      "exception NegateCondtional",
                      ""
                    ];

            fun_defs
                = 
                raw::VERBATIM_CODE [ "fun get_notes (i::NOTE { instruction, note } ) =",
                      "    let my (instruction, notes) = get_notes instruction in (instruction, note . notes) end",
                      "  | get_notes instruction = (instruction,[])",
                      "fun annotate (instruction, note) = i::NOTE { instruction, note }"
                    ];

            fun gen compiled_rtls
                =
                smj::write_sourcecode_file
                  {
                    architecture_description,
                    created_by_package =>  "src/lib/compiler/back/low/tools/arch/adl-gen-instruction-props.pkg",
                    #
                    subdir        =>  "code",                                                                           # Relative to file containing architecture description.
                    make_filename =>  fn architecture_name = sprintf "Props2-%s.pkg" architecture_name,                 # architecture_name can be "pwrpc32" | "sparc32" | "intel32".
                    code          =>  [ smj::make_generic
                                            architecture_description
                                            (fn architecture_name = sprintf "props2_%s_g" architecture_name)
                                            args
                                            smj::STRONG_SEAL
                                            sig_name str_body
                                      ]
                  }
                where
                    architecture_description      = arc::architecture_description_of  compiled_rtls;

                    # Name of the package/api:
                    #
                    str_name =  smj::make_package_name  architecture_description  "Props";
                    sig_name =  "Machcode_Universals";

                    instructions =  ard::base_ops_of  architecture_description;                                 #  The instructions.

                    args =  ["I:  " + smj::make_api_name architecture_description "INSTR" ];                            # Arguments to the instruction generic.

                    instr_kind  = dummy_fun "instr_kind";                                                       # Function that determines the type of an instruction.

                    # Functions for dealing with parallel copies:
                    #
                    move_instr   =  dummy_fun "moveInstr";
                    move_tmp_r   =  dummy_fun "moveTmpR";
                    move_dst_src =  dummy_fun "moveDstSrc";

                    nop        = dummy_fun "nop";
                    jump       = dummy_fun "jump";

                    load_immed = dummy_fun "loadImmed";

                    branch_targets = dummy_fun "branchTargets";
                    set_targets    = dummy_fun "setTargets";

                    negate_conditional =  dummy_fun "negateConditional";
                    immed_range        =  dummy_fun "immedRange";
                    load_operand       =  dummy_fun "loadOperand";

                    eq_opn         = dummy_fun "eqOpn";
                    hash_opn       = dummy_fun "hashOpn";

                    fun mk_def_use (registerkind as raw::REGISTER_SET { name, ... } )
                        = 
                        arc::make_def_use_query  compiled_rtls 
                          {
                            name  => "defUse" + name,
                            decls => [decl],
                            args  => [ ["instruction"] ],
                            def   => def_use,
                            use   => def_use,
                            #
                            named_arguments => FALSE
                          }
                        where
                            my { get, decl }
                                =
                                lct::get_opnd
                                  [ ("int",         lct::IGNORE),
                                    ("one_word_int",        lct::IGNORE),
                                    ("integer",     lct::IGNORE),
                                    ("word",        lct::IGNORE),
                                    ("one_word_unt",        lct::IGNORE),
                                    ("label",       lct::IGNORE),
                                    ("registers",   lct::MULTI "x"),
                                    ("register",    lct::CONV "x"),
                                    ("registerset", lct::MULTI("c::registerset::get C." + name + " x")),
                                    ("operand",     lct::IGNORE) #  XXX 
                                  ];

                            fun def_use (x, expression, lll)
                                    = 
                                    if (lct::of_registerkind (expression, registerkind))    THE (get (x, expression, lll));
                                    else                                                      NULL;
                                    fi;
                        end;

                    def_use_funs =  raw::SEQ_DECL (smj::forall_user_registersets  architecture_description  mk_def_use);

                    def_use      =  smj::make_query_by_registerkind  architecture_description  "defUse";

                    # The generic:
                    #
                    str_body
                        = 
                        [ raw::VERBATIM_CODE [ "package i  = I",
                                "package c  = i::C",
                                "package le = label_expression",
                                "",
                                "exception NEGATE_CONDITIONAL",
                                ""
                              ],
                          smj::error_handler architecture_description (fn architecture_name = "Props"),
                          type_defs,
                          instr_kind,
                          move_instr,
                          move_tmp_r,
                          move_dst_src,
                          nop,
                          jump,
                          load_immed,
                          branch_targets,
                          set_targets,
                          negate_conditional,
                          immed_range,
                          load_operand,
                          eq_opn,
                          hash_opn,
                          def_use_funs,
                          def_use,
                          fun_defs
                        ];

            end;
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext