Skip to content

Commit a706cc3

Browse files
committed
Fix for hspcmp 64bit
1 parent 3ba08be commit a706cc3

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

src/hsp3/hsp3struct.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
#ifndef __hsp3struct_h
66
#define __hsp3struct_h
77

8+
#include <cstdint>
89
#include "hspvar_core.h"
910
#include "hsp3debug.h"
1011

11-
#ifdef _WIN64
12+
#if UINTPTR_MAX == 0xffffffffffffffffu
1213
#define PTR64BIT // ポインタは64bit
13-
#else
14+
#ifndef HSP64
15+
#warning HSP64 is not defined, but pointer is 64bit
16+
#endif
17+
#elif UINTPTR_MAX == 0xffffffff
1418
#define PTR32BIT // ポインタは32bit
19+
20+
#ifdef HSP64
21+
#warning HSP64 is defined, but pointer is 32bit
22+
#endif
23+
#else
24+
#error Unknown pointer size
1525
#endif
1626

1727
// HSPが使用する実数型

src/hspcmp/codegen.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,9 +1847,8 @@ int CToken::GetParameterResTypeCG( char *name )
18471847
return MPTYPE_NONE;
18481848
}
18491849

1850-
1851-
#define GET_FI_SIZE() ((int)(fi_buf->GetSize() / sizeof(STRUCTDAT)))
1852-
#define GET_FI(n) (((STRUCTDAT *)fi_buf->GetBuffer()) + (n))
1850+
#define GET_FI_SIZE() ((int)(fi_buf->GetSize() / sizeof(HED_STRUCTDAT)))
1851+
#define GET_FI(n) (((HED_STRUCTDAT *)fi_buf->GetBuffer()) + (n))
18531852
#define STRUCTDAT_INDEX_DUMMY ((short)0x8000)
18541853

18551854

@@ -1864,7 +1863,7 @@ void CToken::GenerateCodePP_deffunc0( int is_command )
18641863
int prep;
18651864
char funcname[1024];
18661865
STRUCTPRM *prm;
1867-
STRUCTDAT *st;
1866+
HED_STRUCTDAT *st;
18681867

18691868
prep = 0;
18701869
GetTokenCG( GETTOKEN_DEFAULT );
@@ -1927,7 +1926,7 @@ void CToken::GenerateCodePP_deffunc0( int is_command )
19271926
regflag = 0;
19281927
}
19291928
if ( t == MPTYPE_TMODULEVAR ) {
1930-
st = (STRUCTDAT *)fi_buf->GetBuffer();
1929+
st = (HED_STRUCTDAT *)fi_buf->GetBuffer();
19311930
if ( st[ subid ].otindex != 0 ) throw CGERROR_PP_MODTERM_USED;
19321931
st[ subid ].otindex = GET_FI_SIZE();
19331932
regflag = 0;
@@ -1961,7 +1960,7 @@ void CToken::GenerateCodePP_deffunc0( int is_command )
19611960
ot = PutOT( GetCS() );
19621961
if ( index == -1 ) {
19631962
index = GET_FI_SIZE();
1964-
fi_buf->PreparePtr( sizeof(STRUCTDAT) );
1963+
fi_buf->PreparePtr( sizeof(HED_STRUCTDAT) );
19651964
if ( regflag ) {
19661965
lb->Regist( funcname, TYPE_MODCMD, index, cg_orgfilefull, cg_orgline);
19671966
}
@@ -2563,10 +2562,10 @@ void CToken::PutCSSymbol( int label_id, int exflag )
25632562
int id = *(int *)lb->GetData2(label_id);
25642563
tmp_lb->AddReference( id );
25652564

2566-
STRUCTDAT st = { STRUCTDAT_INDEX_DUMMY };
2565+
HED_STRUCTDAT st = { STRUCTDAT_INDEX_DUMMY };
25672566
st.otindex = label_id;
25682567
value = GET_FI_SIZE();
2569-
fi_buf->PutData( &st, sizeof(STRUCTDAT) );
2568+
fi_buf->PutData( &st, sizeof(HED_STRUCTDAT) );
25702569
lb->SetOpt( label_id, value );
25712570
}
25722571
if ( exflag & EXFLG_1 && type != TYPE_VAR && type != TYPE_STRUCT ) {
@@ -2835,10 +2834,10 @@ char *CToken::GetDS( int ptr )
28352834
int CToken::PutLIB( int flag, char *name )
28362835
{
28372836
int a,i = -1,p;
2838-
LIBDAT lib;
2839-
LIBDAT *l;
2840-
p = li_buf->GetSize() / sizeof(LIBDAT);
2841-
l = (LIBDAT *)li_buf->GetBuffer();
2837+
HED_LIBDAT lib;
2838+
HED_LIBDAT *l;
2839+
p = li_buf->GetSize() / sizeof(HED_LIBDAT);
2840+
l = (HED_LIBDAT *)li_buf->GetBuffer();
28422841

28432842
if ( flag == LIBDAT_FLAG_DLL ) {
28442843
if ( *name != 0 ) {
@@ -2863,7 +2862,11 @@ int CToken::PutLIB( int flag, char *name )
28632862

28642863
lib.flag = flag;
28652864
lib.nameidx = i;
2865+
#ifdef PTR64BIT
2866+
lib.p_hlib = 0;
2867+
#else
28662868
lib.hlib = NULL;
2869+
#endif
28672870
lib.clsid = -1;
28682871
li_buf->PutData( &lib, sizeof(LIBDAT) );
28692872
//Mesf( "LIB#%d:%s",flag,name );
@@ -2930,7 +2933,9 @@ int CToken::PutStructParam( short mptype, int extype )
29302933
case MPTYPE_PTR_EXINFO:
29312934
case MPTYPE_PTR_DPMINFO:
29322935
case MPTYPE_NULLPTR:
2933-
size = sizeof(char *);
2936+
// XXX 32bit版換算でax出力する
2937+
//size = sizeof(char *);
2938+
size = 4;
29342939
break;
29352940
case MPTYPE_SINGLEVAR:
29362941
case MPTYPE_ARRAYVAR:
@@ -2980,7 +2985,7 @@ int CToken::PutStructEnd( int i, char *name, int libindex, int otindex, int func
29802985
{
29812986
// STRUCTDATを登録する(モジュール用)
29822987
//
2983-
STRUCTDAT st;
2988+
HED_STRUCTDAT st;
29842989
st.index = libindex;
29852990
st.nameidx = PutDSBuf( name );
29862991
st.subid = i;
@@ -3003,7 +3008,7 @@ int CToken::PutStructEnd( int i, char *name, int libindex, int otindex, int func
30033008
int CToken::PutStructEnd( char *name, int libindex, int otindex, int funcflag )
30043009
{
30053010
int i = GET_FI_SIZE();
3006-
fi_buf->PreparePtr( sizeof(STRUCTDAT) );
3011+
fi_buf->PreparePtr( sizeof(HED_STRUCTDAT) );
30073012
return PutStructEnd( i, name, libindex, otindex, funcflag );
30083013
}
30093014

@@ -3012,7 +3017,7 @@ int CToken::PutStructEndDll( char *name, int libindex, int subid, int otindex )
30123017
// STRUCTDATを登録する(DLL用)
30133018
//
30143019
int i;
3015-
STRUCTDAT st;
3020+
HED_STRUCTDAT st;
30163021
i = GET_FI_SIZE();
30173022
st.index = libindex;
30183023
if ( name[0] == '*' ) {
@@ -3023,10 +3028,11 @@ int CToken::PutStructEndDll( char *name, int libindex, int subid, int otindex )
30233028
st.subid = subid;
30243029
st.prmindex = cg_stptr;
30253030
st.prmmax = cg_stnum;
3026-
st.proc = NULL;
3031+
//st.proc = NULL;
3032+
st.funcflag = 0;
30273033
st.size = cg_stsize;
30283034
st.otindex = otindex;
3029-
fi_buf->PutData( &st, sizeof(STRUCTDAT) );
3035+
fi_buf->PutData( &st, sizeof(HED_STRUCTDAT) );
30303036
//Mesf( "#%d : %s(LIB%d) prm%d size%d ot%d", i, name, libindex, cg_stnum, cg_stsize, otindex );
30313037
return i;
30323038
}
@@ -3039,7 +3045,7 @@ void CToken::PutHPI( short flag, short option, char *libname, char *funcname )
30393045
hpi.option = option;
30403046
hpi.libname = PutDSBuf( libname );
30413047
hpi.funcname = PutDSBuf( funcname );
3042-
#ifndef HSP64
3048+
#ifndef PTR64BIT
30433049
hpi.libptr = NULL;
30443050
#else
30453051
hpi.p_libptr = 0;
@@ -3299,7 +3305,7 @@ int CToken::GenerateCode( CMemBuf *srcbuf, char *oname, int mode )
32993305
} else {
33003306
int n_mod, n_hpi;
33013307
n_hpi = hpi_buf->GetSize() / sizeof(HPIDAT);
3302-
n_mod = fi_buf->GetSize() / sizeof(STRUCTDAT);
3308+
n_mod = fi_buf->GetSize() / sizeof(HED_STRUCTDAT);
33033309
Mesf( "#Code size (%d) String data size (%d) param size (%d)",cs_size,ds_size,mi_buf->GetSize() );
33043310
Mesf( "#Vars (%d) Labels (%d) Modules (%d) Libs (%d) Plugins (%d)",cg_valcnt,ot_size>>2,n_mod,li_size,n_hpi );
33053311
if (sz_exopt) {

0 commit comments

Comments
 (0)