## adl-gen-rtlprops.pkg -- derived from ~/src/sml/nj/smlnj-110.60/MLRISC/Tools/ADL/mdl-gen-rtlprops.sml
#
# Generate the <architecture>RTLProps generic.
# This package extracts semantics and dependence
# information about the instruction set needed for SSA optimizations.
# Compiled by:
#
src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-packages.lib### "Civilization advances by extending
### the number of important operations which
### we can perform without thinking of them."
###
### -- Alfred North Whitehead
stipulate
# package ard = architecture_description; # architecture_description is from
src/lib/compiler/back/low/tools/arch/architecture-description.pkg package cst = adl_raw_syntax_constants; # adl_raw_syntax_constants is from
src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-constants.pkg package err = adl_error; # adl_error is from
src/lib/compiler/back/low/tools/line-number-db/adl-error.pkg package smj = sourcecode_making_junk; # sourcecode_making_junk is from
src/lib/compiler/back/low/tools/arch/sourcecode-making-junk.pkg# package mst = adl_symboltable; # adl_symboltable is from
src/lib/compiler/back/low/tools/arch/adl-symboltable.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 rkj = registerkinds_junk; # registerkinds_junk is from
src/lib/compiler/back/low/code/registerkinds-junk.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 package rst = adl_raw_syntax_translation; # adl_raw_syntax_translation is from
src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-translation.pkgherein
# This generic is invoked (only) from:
#
#
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_rtl_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 m = arc::lct; # "lct" == "lowhalf_types".
package rtl = arc::rtl; # "rtl" == "register transfer language".
# package tcf = rtl::tcf;
#
include package rsj;
include package err;
herein
exception UNDEFINED;
exception NOT_FOUND;
# Function to make a new RTL
#
make_new_rtl = raw::ID_IN_EXPRESSION (raw::IDENT (["RTL"], "new"));
############################################################################
#
# Generate a table of compiled RTLs templates
#
fun gen_rtl_table compiled_rtls
=
raw::PACKAGE_DECL
( "Arch",[],
NULL, raw::DECLSEXP
[ raw::LOCAL_DECL (cst::gen_consts const_table, body)]
)
where
architecture_description = arc::architecture_description_of compiled_rtls;
rtls = arc::rtls compiled_rtls;
rtl_string_name = smj::make_package_name architecture_description "RTL";
const_table = cst::new_const_table ();
fun make_entry (arc::RTLDEF { id, args, rtl, ... } )
=
raw::VAL_DECL
[ raw::NAMED_VARIABLE
( raw::IDPAT id,
raw::APPLY_EXPRESSION
( make_new_rtl,
raw::APPLY_EXPRESSION (raw::ID_IN_EXPRESSION (raw::IDENT ([rtl_string_name], id)), arg)
)
)
]
where
lookup = rtl::arg_of rtl;
fun parameter i
=
raw::APPLY_EXPRESSION (raw::ID_IN_EXPRESSION (raw::IDENT (["T"], "PARAM")), integer_constant_in_expression i);
fun make_arg name
=
{ (lookup name) -> (expression, pos);
e = case pos
#
rtl::IN i => parameter i;
rtl::OUT i => parameter i;
rtl::IO (i, _) => parameter i;
esac;
(name, e);
}
except
rtl::NOT_AN_ARGUMENT
=
{ warning ("'" + name + "' is unused in rtl " + id);
#
(name, parameter 0);
};
arg = cst::const const_table (raw::RECORD_IN_EXPRESSION (map make_arg args));
end;
body = map make_entry rtls;
end;
############################################################################
#
# Create the function rtl: Instruction -> Rtl
#
fun mk_rtl_query_fun compiled_rtls
=
{ fun body { instruction, rtl => arc::RTLDEF { id, ... }, const }
=
{ expression => raw::ID_IN_EXPRESSION (raw::IDENT (["Arch"], id)),
case_pats => []
};
arc::make_query compiled_rtls
{
name => "rtl",
named_arguments => TRUE,
args => [ [ "instruction" ] ],
decls => [ arc::complex_error_handler "rtl" ],
case_args => [],
body => body
};
};
############################################################################
#
# Create the function def_use: Instruction -> (List(Register), List(Register))
#
fun make_def_use_query_fun compiled_rtls name
=
{ my { get, decl }
=
m::get_opnd
[ ("int", m::CONV("CELL (int x)")),
("one_word_int", m::CONV("CELL (one_word_int x)")),
("integer", m::CONV("CELL (integer x)")),
("word", m::CONV("CELL (word x)")),
("one_word_unt", m::CONV("CELL (one_word_unt x)")),
("cell", m::CONV("CELL x")),
("label", m::IGNORE),
("registerset", m::MULTI("map CELL (rkj::cls::to_cell_list x)")),
("operand", m::CONV("OPERAND x"))
];
decl0 =
raw::VERBATIM_CODE [ "/* methods for computing value numbers */",
"my ot::VALUE_NUMBERING",
" { int, one_word_int, integer, word, one_word_unt, operand, ... } =",
" valueNumberingMethods",
"/* methods for type conversion */"
];
fun gen x
=
THE (get x);
arc::make_def_use_query
compiled_rtls
{ name,
args => [["valueNumberingMethods"], ["instruction"]],
named_arguments => FALSE,
decls => [arc::complex_error_handler name, decl0, decl],
def => gen,
use => gen
};
};
############################################################################
#
# Main routine
#
fun gen compiled_rtls
=
smj::write_sourcecode_file
{
architecture_description,
created_by_package => "src/lib/compiler/back/low/tools/arch/adl-gen-rtlprops.pkg",
#
subdir => "treecode", # Relative to file containing architecture description.
make_filename => \\ architecture_name = sprintf "RTLProps-%s.pkg" architecture_name, # architecture_name can be "pwrpc32"
| "sparc32" | "intel32".
#
code => [ smj::make_generic
architecture_description
(\\ architecture_name = sprintf "rtl_props_%s_g" architecture_name)
args
smj::STRONG_SEAL
sig_name
(map rst::simplify_declaration str_body)
]
}
where
# The architecture description
#
architecture_description = arc::architecture_description_of compiled_rtls;
# Name of the package/api:
#
str_name = smj::make_package_name architecture_description "RTLProps";
sig_name = "RTL_PROPERTIES";
# Arguments to the instruction generic:
#
args =
["package instruction: " + smj::make_api_name architecture_description "INSTR",
"package region_props: REGION_PROPERTIES",
"package rtl: Treecode_Rtl",
"package operand_table: OPERAND_TABLE where I = Instr",
"package asm_emitter: Machcode_Codebuffer where I = Instr",
" sharing Instr::T = RTL::T"
];
# The generic:
#
str_body =
[ raw::VERBATIM_CODE [ "package i = Instr",
"package c = i::C",
"package rtl = RTL",
"package t = RTL::T",
"package ot = OperandTable",
"",
"enum value = CELL of rkj::cell",
"
| OPERAND of i::operand",
""
],
smj::error_handler architecture_description (\\ architecture_name = "RTLProps"),
arc::complex_error_handler_def (),
raw::PACKAGE_DECL
( smj::make_package_name architecture_description "RTL",
[],
NULL,
raw::APPSEXP
( raw::IDSEXP (raw::IDENT ([], smj::make_package_name architecture_description "RTL")),
raw::DECLSEXP
[
raw::VERBATIM_CODE [ "package rtl = RTL",
"package c = C"
]
]
)
),
gen_rtl_table compiled_rtls,
mk_rtl_query_fun compiled_rtls,
make_def_use_query_fun compiled_rtls "defUse"
];
end;
end; # stipulate
}; # generic package adl_gen_rtl_props
end; # stipulate