## client-pseudo-ops-mythryl-g.pkg -- pseudo ops
# Compiled by:
#
src/lib/compiler/core.sublibstipulate
package lbl = codelabel; # codelabel is from
src/lib/compiler/back/low/code/codelabel.pkg package pbt = pseudo_op_basis_type; # pseudo_op_basis_type is from
src/lib/compiler/back/low/mcg/pseudo-op-basis-type.pkgherein
# We are invoked from:
#
#
src/lib/compiler/back/low/main/pwrpc32/backend-lowhalf-pwrpc32.pkg #
src/lib/compiler/back/low/main/sparc32/backend-lowhalf-sparc32.pkg #
src/lib/compiler/back/low/main/intel32/backend-lowhalf-intel32-g.pkg #
generic package client_pseudo_ops_mythryl_g (
# ===========================
#
package bpo: Base_Pseudo_Ops; # Base_Pseudo_Ops is from
src/lib/compiler/back/low/mcg/base-pseudo-ops.api )
: (weak) Client_Pseudo_Ops_Mythryl # Client_Pseudo_Ops_Mythryl is from
src/lib/compiler/back/low/main/nextcode/client-pseudo-ops-mythryl.api {
# Export to client packages:
#
package bpo = bpo; # "bpo" == "base_pseudo_ops".
stipulate
package tcf = bpo::tcf; # "tcf" == "treecode_form".
herein
Lib7_Pseudo_Op
#
= FILENAME String
#
| JUMPTABLE { base: lbl::Codelabel,
targets: List( lbl::Codelabel )
}
;
Pseudo_Op = Lib7_Pseudo_Op;
fun to_basis (JUMPTABLE { base, targets } ) # 64-bit issue. "ALIGN_SIZE n" == "align to 2**n byte boundary", so 32-bit needs ALIGN 2, 64-bit needs ALIGN 3.
=>
pbt::ALIGN_SIZE 2 ! # Encode jumptable as .align 2
pbt::DATA_LABEL base ! # base: label1 - base
list::fold_backward # label2 - base
(\\ (target, result) = pseudo_op_offset target ! result) # label3 - base
[] # ...
targets
where
fun target_offset label
=
tcf::SUB (32, tcf::LABEL label, tcf::LABEL base); # 64-bit issue.
fun pseudo_op_offset label
=
pbt::INT { size=>32, i => [tcf::LABEL_EXPRESSION (target_offset label)] }; # 64-bit issue
end;
to_basis (FILENAME file)
=>
{ fun int_8 n
=
pbt::INT { size=>8, i=> [tcf::LITERAL (tcf::mi::from_int (8, n))] };
# Adjust for zero termination and
# last byte containing the length:
#
len = unt::from_int (string::length_in_bytes file) + 0u2;
k4 = unt::bitwise_and (len + 0u3, unt::bitwise_not 0u3);
fun pad 0u0 => [int_8 (unt::to_int (unt::(>>) (k4, 0u2)))];
pad n => int_8 (0) ! pad (n - 0u1);
end;
pbt::ALIGN_SIZE 2 ! pbt::ASCIIZ(file) ! pad (k4-len);
};
end;
fun pseudo_op_to_string pseudo_op
=
string::cat(
list::fold_backward
(\\ (p, result) = bpo::pseudo_op_to_string p + "\n" ! result)
[]
(to_basis pseudo_op)
);
fun put_pseudo_op { pseudo_op, loc, put_byte }
=
{ pb = to_basis pseudo_op;
#
list::fold_forward put_pseudo_op' loc (to_basis pseudo_op)
where
fun put_pseudo_op' (pseudo_op, loc)
=
{ bpo::put_pseudo_op { pseudo_op, loc, put_byte };
#
loc + bpo::current_pseudo_op_size_in_bytes (pseudo_op, loc);
};
end;
();
};
fun current_pseudo_op_size_in_bytes (pseudo_op, loc)
=
list::fold_forward
(\\ (pseudo_op, result_so_far) = result_so_far + bpo::current_pseudo_op_size_in_bytes (pseudo_op, loc))
0
(to_basis pseudo_op);
fun adjust_labels (JUMPTABLE { base, ... }, loc)
=>
{ base_addr
=
loc + bpo::current_pseudo_op_size_in_bytes (pbt::ALIGN_SIZE 2, loc);
if (lbl::get_codelabel_address base == base_addr)
#
FALSE;
else
lbl::set_codelabel_address (base, base_addr);
TRUE;
fi;
};
adjust_labels (FILENAME _, _)
=>
FALSE;
end;
end;
};
end;
## COPYRIGHT (c) 2001 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.