/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include <stdio.h>
#include <string.h>
static bool LP64 = false;
static bool LONGS_IN_ONE_ENTRY = false;
if( reg == 0 )
if( LONGS_IN_ONE_ENTRY ) {
} else
} else
}
// Print it out
for( int i = 0; i < length; i++) {
if( sig[i] == 0 ) continue; // do not print 'halves'
if( reg ) {
printf(":");
} else {
printf(" ");
}
printf(" ");
}
printf("\n");
}
static int INT_SCALE( int x ) {
return LONGS_IN_ONE_ENTRY ? (x<<1) : x;
}
if( LP64 && !LONGS_IN_ONE_ENTRY ) {
printf("LP64 and 2-reg longs not supported\n");
return;
}
for( int i = 0; i < length; i++ )
sig[i] = s[i]; // Reset sig array
bool is_outgoing = true;
// registers (I0-I5), extras spill to the stack. Then pack the first
// 32 float args into F0-F31, extras spill to the stack. Then pad
// all register sets to align. Then put longs and doubles into the
// same registers as they fit, else spill to the stack.
// and where the longs & doubles will go.
int int_reg_cnt = 0;
int flt_reg_cnt = 0;
int stk_reg_pairs = 0;
for( int i = 0; i < length; i++) {
switch( sig[i] ) {
case Op_RegL: // Longs-in-1-reg compete with int args
if( LONGS_IN_ONE_ENTRY ) {
}
break;
case Op_RegP:
else if( !LP64 ) stk_reg_pairs++;
break;
case Op_RegI:
else stk_reg_pairs++;
break;
case Op_RegF:
else stk_reg_pairs++;
break;
}
}
int stk_reg = 0;
int int_reg = 0;
int flt_reg = 0;
// Now do the signature layout
for( int i = 0; i < length; i++) {
switch( tmp ) {
case Op_RegI:
// case Op_RegP:
break;
case Op_RegL:
if( sig[i] != Op_RegP && sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; }
// case Op_RegP:
if( LONGS_IN_ONE_ENTRY ) {
if( int_reg < int_reg_max ) {
} else {
stk_reg_pairs += 2;
}
} else {
if( int_reg_pairs < int_reg_max ) {
int_reg_pairs += 2;
} else {
stk_reg_pairs += 2;
}
}
break;
case Op_RegF:
break;
case Op_RegD:
if( flt_reg_pairs < flt_reg_max ) {
flt_reg_pairs += 2;
} else {
stk_reg_pairs += 2;
}
break;
case 'h': sig[i] = 0; break;
default:
return;
}
}
printf("java ");
}
static int int_stk_helper( int i ) {
}
if( LP64 && !LONGS_IN_ONE_ENTRY ) {
printf("LP64 and 2-reg longs not supported\n");
return;
}
for( int i = 0; i < length; i++ )
sig[i] = s[i]; // Reset sig array
// The native convention is V8 if !LP64, which means the V8 convention is
// used both with and without LONGS_IN_ONE_ENTRY, an unfortunate split. The
// same actual machine registers are used, but they are named differently in
// the LONGS_IN_ONE_ENTRY mode. The LP64 convention is the V9 convention
// which is slightly more sane.
if( LP64 ) {
// V9 convention: All things "as-if" on double-wide stack slots.
int j = 0; // Count of actual args, not HALVES
for( int i=0; i<length; i++, j++ ) {
int tmp;
switch( sig[i] ) {
case Op_RegI:
sig[i] = int_stk_helper( j );
break;
case Op_RegL:
case Op_RegP:
tmp = int_stk_helper( j );
break;
case Op_RegF: // V9ism: floats go in ODD registers
break;
break;
default:
return;
}
}
} else {
// V8 convention: first 6 things in O-regs, rest on stack.
// Alignment is willy-nilly.
for( int i=0; i<length; i++ ) {
int tmp;
switch( sig[i] ) {
case Op_RegI:
case Op_RegP:
case Op_RegF:
sig[i] = int_stk_helper( i );
break;
case Op_RegL:
case Op_RegD:
tmp = int_stk_helper( i );
break;
case 'h': sig[i] = 0; break;
default:
return;
}
}
}
printf("natv ");
}
if( argc != 2 ) {
printf("Usage: args IPFLhDh... (Java argument string)\n");
printf("Returns argument layout\n");
return -1;
}
const char *s = argv[1];
LP64 = false; LONGS_IN_ONE_ENTRY = false;
LP64 = false; LONGS_IN_ONE_ENTRY = true;
LP64 = true ; LONGS_IN_ONE_ENTRY = true;
LP64 = false; LONGS_IN_ONE_ENTRY = false;
LP64 = false; LONGS_IN_ONE_ENTRY = true;
LP64 = true ; LONGS_IN_ONE_ENTRY = true;
}