2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2012-03-24 14:06:46 -04:00
|
|
|
* Copyright 2001, 2011 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "opcode.h"
|
|
|
|
#include "mdq.h"
|
|
|
|
#include "cgp.h"
|
2012-06-15 13:29:37 -04:00
|
|
|
#include <emit_code.h>
|
2012-02-05 11:35:58 -05:00
|
|
|
#include "rtnhdr.h"
|
|
|
|
#include "obj_file.h"
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
GBLREF int4 curr_addr, code_size;
|
2012-02-05 11:35:58 -05:00
|
|
|
GBLREF char cg_phase; /* code generation phase */
|
|
|
|
GBLREF triple t_orig; /* head of triples */
|
|
|
|
LITREF octabstruct oc_tab[]; /* op-code table */
|
|
|
|
|
|
|
|
void shrink_jmps(void)
|
|
|
|
{
|
|
|
|
int new_size, old_size, shrink;
|
|
|
|
triple *ct; /* current triple */
|
2012-03-24 14:06:46 -04:00
|
|
|
DCL_THREADGBL_ACCESS;
|
2012-02-05 11:35:58 -05:00
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
SETUP_THREADGBL_ACCESS;
|
|
|
|
assert(CGP_ADDR_OPT == cg_phase);
|
2012-02-05 11:35:58 -05:00
|
|
|
do
|
|
|
|
{
|
|
|
|
shrink = 0;
|
|
|
|
dqloop(&t_orig, exorder, ct)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
if ((oc_tab[ct->opcode].octype & OCT_JUMP) || (OC_LDADDR == ct->opcode) || (OC_FORLOOP == ct->opcode))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
old_size = ct->exorder.fl->rtaddr - ct->rtaddr;
|
|
|
|
curr_addr = 0;
|
2012-03-24 14:06:46 -04:00
|
|
|
if (0 > ct->operand[0].oprval.tref->rtaddr - ct->rtaddr)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
ct->rtaddr -= shrink;
|
|
|
|
trip_gen(ct);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
trip_gen(ct);
|
|
|
|
ct->rtaddr -= shrink;
|
|
|
|
}
|
|
|
|
new_size = curr_addr; /* size of operand 0 */
|
|
|
|
assert(old_size >= new_size);
|
|
|
|
shrink += old_size - new_size;
|
|
|
|
} else
|
|
|
|
ct->rtaddr -= shrink;
|
|
|
|
}/* dqloop */
|
|
|
|
code_size -= shrink;
|
|
|
|
} while (shrink != 0);
|
|
|
|
|
|
|
|
/* Now that the code has been strunk, we may have to adjust the pad length of the code segment. Compute
|
|
|
|
this by now subtracting out the size of the pad length from the code size and recomputing the pad length
|
|
|
|
and readjusting the code size. (see similar computation in code_gen().
|
|
|
|
*/
|
2012-03-24 14:06:46 -04:00
|
|
|
code_size -= TREF(codegen_padlen);
|
|
|
|
TREF(codegen_padlen) = PADLEN(code_size, SECTION_ALIGN_BOUNDARY); /* Length to pad to align next section */
|
|
|
|
code_size += TREF(codegen_padlen);
|
2012-02-05 11:35:58 -05:00
|
|
|
}
|