Port sc6 to C++.

This commit is contained in:
David Anderson 2014-08-22 00:07:40 -07:00
parent 142fbaafdd
commit 3eb1faa470
4 changed files with 177 additions and 177 deletions

View File

@ -87,7 +87,7 @@ binary.sources += [
'sc3.c', 'sc3.c',
'sc4.c', 'sc4.c',
'sc5.c', 'sc5.c',
'sc6.c', 'sc6.cpp',
'sc7.cpp', 'sc7.cpp',
'scexpand.cpp', 'scexpand.cpp',
'sci18n.cpp', 'sci18n.cpp',

View File

@ -1,173 +1,173 @@
/* Abstract Machine for the Pawn compiler, debugger support /* Abstract Machine for the Pawn compiler, debugger support
* *
* This file contains extra definitions that are convenient for debugger * This file contains extra definitions that are convenient for debugger
* support. * support.
* *
* Copyright (c) ITB CompuPhase, 2005 * Copyright (c) ITB CompuPhase, 2005
* *
* This software is provided "as-is", without any express or implied warranty. * This software is provided "as-is", without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from * In no event will the authors be held liable for any damages arising from
* the use of this software. * the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in * claim that you wrote the original software. If you use this software in
* a product, an acknowledgment in the product documentation would be * a product, an acknowledgment in the product documentation would be
* appreciated but is not required. * appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be * 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software. * misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
* *
* Version: $Id$ * Version: $Id$
*/ */
#ifndef AMXDBG_H_INCLUDED #ifndef AMXDBG_H_INCLUDED
#define AMXDBG_H_INCLUDED #define AMXDBG_H_INCLUDED
#ifndef AMX_H_INCLUDED #ifndef AMX_H_INCLUDED
#include "amx.h" #include "amx.h"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Some compilers do not support the #pragma align, which should be fine. Some /* Some compilers do not support the #pragma align, which should be fine. Some
* compilers give a warning on unknown #pragmas, which is not so fine... * compilers give a warning on unknown #pragmas, which is not so fine...
*/ */
#if defined SN_TARGET_PS2 || defined __GNUC__ #if defined SN_TARGET_PS2 || defined __GNUC__
#define AMX_NO_ALIGN #define AMX_NO_ALIGN
#endif #endif
#if defined __GNUC__ #if defined __GNUC__
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
#else #else
#define PACKED #define PACKED
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
#else #else
#pragma pack(push) #pragma pack(push)
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#if defined __TURBOC__ #if defined __TURBOC__
#pragma option -a- /* "pack" pragma for older Borland compilers */ #pragma option -a- /* "pack" pragma for older Borland compilers */
#endif #endif
#endif #endif
#endif #endif
typedef struct tagAMX_DBG_HDR { typedef struct tagAMX_DBG_HDR {
int32_t size PACKED; /* size of the debug information chunk */ int32_t size PACKED; /* size of the debug information chunk */
uint16_t magic PACKED; /* signature, must be 0xf1ef */ uint16_t magic PACKED; /* signature, must be 0xf1ef */
char file_version; /* file format version */ char file_version; /* file format version */
char amx_version; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; /* currently unused */ int16_t flags PACKED; /* currently unused */
int16_t files PACKED; /* number of entries in the "file" table */ int16_t files PACKED; /* number of entries in the "file" table */
int32_t lines PACKED; /* number of entries in the "line" table */ int32_t lines PACKED; /* number of entries in the "line" table */
int32_t symbols PACKED; /* number of entries in the "symbol" table */ int32_t symbols PACKED; /* number of entries in the "symbol" table */
int16_t tags PACKED; /* number of entries in the "tag" table */ int16_t tags PACKED; /* number of entries in the "tag" table */
int16_t automatons PACKED; /* number of entries in the "automaton" table */ int16_t automatons PACKED; /* number of entries in the "automaton" table */
int16_t states PACKED; /* number of entries in the "state" table */ int16_t states PACKED; /* number of entries in the "state" table */
} PACKED AMX_DBG_HDR; } PACKED AMX_DBG_HDR;
#define AMX_DBG_MAGIC 0xf1ef #define AMX_DBG_MAGIC 0xf1ef
typedef struct tagAMX_DBG_FILE { typedef struct tagAMX_DBG_FILE {
ucell address PACKED; /* address in the code segment where generated code (for this file) starts */ ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
const char name[1]; /* ASCII string, zero-terminated */ char name[1]; /* ASCII string, zero-terminated */
} PACKED AMX_DBG_FILE; } PACKED AMX_DBG_FILE;
typedef struct tagAMX_DBG_LINE { typedef struct tagAMX_DBG_LINE {
ucell address PACKED; /* address in the code segment where generated code (for this line) starts */ ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
int32_t line PACKED; /* line number */ int32_t line PACKED; /* line number */
} PACKED AMX_DBG_LINE; } PACKED AMX_DBG_LINE;
typedef struct tagAMX_DBG_SYMBOL { typedef struct tagAMX_DBG_SYMBOL {
ucell address PACKED; /* address in the data segment or relative to the frame */ ucell address PACKED; /* address in the data segment or relative to the frame */
int16_t tag PACKED; /* tag for the symbol */ int16_t tag PACKED; /* tag for the symbol */
ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */ ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */ ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
char ident; /* kind of symbol (function/variable) */ char ident; /* kind of symbol (function/variable) */
char vclass; /* class of symbol (global/local) */ char vclass; /* class of symbol (global/local) */
int16_t dim PACKED; /* number of dimensions */ int16_t dim PACKED; /* number of dimensions */
const char name[1]; /* ASCII string, zero-terminated */ char name[1]; /* ASCII string, zero-terminated */
} PACKED AMX_DBG_SYMBOL; } PACKED AMX_DBG_SYMBOL;
typedef struct tagAMX_DBG_SYMDIM { typedef struct tagAMX_DBG_SYMDIM {
int16_t tag PACKED; /* tag for the array dimension */ int16_t tag PACKED; /* tag for the array dimension */
ucell size PACKED; /* size of the array dimension */ ucell size PACKED; /* size of the array dimension */
} PACKED AMX_DBG_SYMDIM; } PACKED AMX_DBG_SYMDIM;
typedef struct tagAMX_DBG_TAG { typedef struct tagAMX_DBG_TAG {
int16_t tag PACKED; /* tag id */ int16_t tag PACKED; /* tag id */
const char name[1]; /* ASCII string, zero-terminated */ char name[1]; /* ASCII string, zero-terminated */
} PACKED AMX_DBG_TAG; } PACKED AMX_DBG_TAG;
typedef struct tagAMX_DBG_MACHINE { typedef struct tagAMX_DBG_MACHINE {
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
ucell address PACKED; /* address of state variable */ ucell address PACKED; /* address of state variable */
const char name[1]; /* ASCII string, zero-terminated */ char name[1]; /* ASCII string, zero-terminated */
} PACKED AMX_DBG_MACHINE; } PACKED AMX_DBG_MACHINE;
typedef struct tagAMX_DBG_STATE { typedef struct tagAMX_DBG_STATE {
int16_t state PACKED; /* state id */ int16_t state PACKED; /* state id */
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
const char name[1]; /* ASCII string, zero-terminated */ char name[1]; /* ASCII string, zero-terminated */
} PACKED AMX_DBG_STATE; } PACKED AMX_DBG_STATE;
typedef struct tagAMX_DBG { typedef struct tagAMX_DBG {
AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */ AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
AMX_DBG_FILE _FAR **filetbl PACKED; AMX_DBG_FILE _FAR **filetbl PACKED;
AMX_DBG_LINE _FAR *linetbl PACKED; AMX_DBG_LINE _FAR *linetbl PACKED;
AMX_DBG_SYMBOL _FAR **symboltbl PACKED; AMX_DBG_SYMBOL _FAR **symboltbl PACKED;
AMX_DBG_TAG _FAR **tagtbl PACKED; AMX_DBG_TAG _FAR **tagtbl PACKED;
AMX_DBG_MACHINE _FAR **automatontbl PACKED; AMX_DBG_MACHINE _FAR **automatontbl PACKED;
AMX_DBG_STATE _FAR **statetbl PACKED; AMX_DBG_STATE _FAR **statetbl PACKED;
} PACKED AMX_DBG; } PACKED AMX_DBG;
#if !defined iVARIABLE #if !defined iVARIABLE
#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */ #define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */
#define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */ #define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */
#define iARRAY 3 #define iARRAY 3
#define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */ #define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */
#define iFUNCTN 9 #define iFUNCTN 9
#endif #endif
int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg); int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr); int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr);
int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename); int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename);
int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname); int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname);
int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line); int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line);
int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address); int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address);
int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address); int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address);
int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name); int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name);
int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name); int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name);
int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name); int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name);
int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym); int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym);
int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim); int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim);
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__ #if defined LINUX || defined __FreeBSD__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__ #elif defined MACOS && defined __MWERKS__
#pragma options align=reset #pragma options align=reset
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
#endif #endif
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* AMXDBG_H_INCLUDED */ #endif /* AMXDBG_H_INCLUDED */

View File

@ -44,7 +44,7 @@ typedef cell (*OPCODE_PROC)(FILE *fbin,char *params,cell opcode);
typedef struct { typedef struct {
cell opcode; cell opcode;
char *name; const char *name;
int segment; /* sIN_CSEG=parse in cseg, sIN_DSEG=parse in dseg */ int segment; /* sIN_CSEG=parse in cseg, sIN_DSEG=parse in dseg */
OPCODE_PROC func; OPCODE_PROC func;
} OPCODEC; } OPCODEC;

View File

@ -45,13 +45,13 @@ typedef struct {
const char *find; const char *find;
const char *replace; const char *replace;
int savesize; /* number of bytes saved (in bytecode) */ int savesize; /* number of bytes saved (in bytecode) */
} PRE_SEQUENCE; } SETUP_SEQUENCE;
typedef struct { typedef struct {
char *find; char *find;
char *replace; char *replace;
int savesize; /* number of bytes saved (in bytecode) */ int savesize; /* number of bytes saved (in bytecode) */
} SEQUENCE; } SEQUENCE;
static PRE_SEQUENCE sequences_cmp[] = { static SETUP_SEQUENCE sequences_cmp[] = {
/* A very common sequence in four varieties /* A very common sequence in four varieties
* load.s.pri n1 load.s.pri n2 * load.s.pri n1 load.s.pri n2
* push.pri load.s.alt n1 * push.pri load.s.alt n1