This commit is contained in:
Ash Wolf 2022-11-07 03:06:21 +00:00
parent d0b9848c54
commit 9a46dd0e2e
62 changed files with 30796 additions and 1532 deletions

View File

@ -84,4 +84,9 @@ add_executable(mwcc
compiler_and_linker/unsorted/CPrec.c
compiler_and_linker/unsorted/CError.c
compiler_and_linker/unsorted/CInt64.c
compiler_and_linker/unsorted/CMachine.c compiler_and_linker/FrontEnd/C/CPrepTokenizer.c compiler_and_linker/FrontEnd/C/CPrep.c)
compiler_and_linker/unsorted/CMachine.c
compiler_and_linker/FrontEnd/C/CPrepTokenizer.c
compiler_and_linker/FrontEnd/C/CPrep.c
compiler_and_linker/unsorted/PCode.c
compiler_and_linker/unsorted/PCodeInfo.c
compiler_and_linker/unsorted/RegisterInfo.c compiler_and_linker/unsorted/Registers.c compiler_and_linker/unsorted/CMangler.c compiler_and_linker/unsorted/CodeGen.c includes/compiler/Operands.h compiler_and_linker/unsorted/Operands.c includes/compiler/PCodeUtilities.h compiler_and_linker/unsorted/PCodeUtilities.c compiler_and_linker/unsorted/TOC.c compiler_and_linker/unsorted/StackFrame.c includes/compiler/StackFrame.h includes/compiler/TOC.h includes/compiler/CInit.h compiler_and_linker/unsorted/CInit.c compiler_and_linker/unsorted/CExpr.c includes/compiler/CExpr.h compiler_and_linker/unsorted/CExpr2.c includes/compiler/CParser.h compiler_and_linker/unsorted/CParser.c compiler_and_linker/unsorted/CDecl.c includes/compiler/CDecl.h compiler_and_linker/unsorted/CABI.c includes/compiler/CABI.h includes/compiler/CMachine.h includes/compiler/CMangler.h includes/compiler/CScope.h includes/compiler/CPrep.h includes/compiler/CPrepTokenizer.h includes/compiler/CodeGen.h includes/compiler/CClass.h compiler_and_linker/unsorted/CClass.c compiler_and_linker/unsorted/CFunc.c includes/compiler/CFunc.h includes/compiler/CInline.h compiler_and_linker/unsorted/CInline.c)

110
PCode.h
View File

@ -1,110 +0,0 @@
#pragma once
typedef struct _PCodeArg {
unsigned int _0;
unsigned int _4;
unsigned int _8;
} PCodeArg;
typedef struct _PCode {
struct _PCode *nextPCode;
struct _PCode *prevPCode;
struct _PCBlock *block;
unsigned int xx_C;
unsigned int _10;
int flags;
unsigned int _18;
unsigned int _1C;
short op;
short argCount;
PCodeArg args[0];
} PCode;
typedef struct _PCLabel {
struct _PCLabel *nextLabel;
struct _PCBlock *block;
short resolved;
short index;
} PCLabel;
typedef struct _PCLink {
struct _PCLink *nextLink;
struct _PCBlock *block;
} PCLink;
typedef struct _PCBlock {
struct _PCBlock *nextBlock;
struct _PCBlock *prevBlock;
PCLabel *labels;
PCLink *predecessors;
PCLink *successors;
PCode *firstPCode;
PCode *lastPCode;
int blockIndex;
int codeOffset; // in bytes
int loopWeight;
short pcodeCount;
unsigned short flags;
} PCBlock;
/* PCode Flags */
enum {
fPCodeFlag1 = 1,
fPCodeFlag2 = 2,
fPCodeFlag4 = 4,
fPCodeFlag8 = 8,
fPCodeFlag10 = 0x10,
fIsPtrOp = 0x20,
fIsConst = 0x40,
fIsVolatile = 0x80,
fSideEffects = 0x100,
fPCodeFlag200 = 0x200,
fPCodeFlag400 = 0x400,
fPCodeFlag800 = 0x800,
fPCodeFlag1000 = 0x1000,
fCommutative = 0x2000,
fIsCSE = 0x4000,
fOverflow = 0x800000,
fLink = 0x1000000,
fBranchNotTaken = 0x4000000,
fBranchTaken = 0x8000000,
fAbsolute = 0x10000000,
fSetsCarry = 0x10000000,
};
enum {
fPCBlockFlag1 = 1,
fPCBlockFlag2 = 2,
fPCBlockFlag4 = 4,
fPCBlockFlag8 = 8,
fPCBlockFlag10 = 0x10,
fPCBlockFlag20 = 0x20
};
extern PCBlock *pcbasicblocks;
extern PCBlock *pclastblock;
extern void *prologue;
extern void *epilogue;
extern PCBlock **depthfirstordering;
extern int pcblockcount;
extern int pcloopweight;
extern void initpcode();
extern PCode *makepcode(short op, ...);
extern void emitpcode(short op, ...);
extern PCode *copypcode(PCode *pcode);
extern PCLabel *makepclabel();
extern PCBlock *makepcblock();
extern void pclabel(PCBlock *block, PCLabel *label);
extern void pcbranch(PCBlock *block, PCLabel *label);
extern void pccomputepredecessors();
extern void deleteblock(PCBlock *block);
extern void deleteunreachableblocks();
extern void appendpcode(PCBlock *block, PCode *pcode);
extern void deletepcode(PCode *pcode);
extern void insertpcodebefore(PCode *anchor, PCode *newpcode);
extern void insertpcodeafter(PCode *anchor, PCode *newpcode);
extern void setpcodeflags(int flags);
extern void clearpcodeflags(int flags);
extern int pccomputeoffsets();
extern void computedepthfirstordering();

View File

@ -1,55 +0,0 @@
#include "PCodeInfo.h"
void pcode_get_hi_lo(int a1, char a2, int *pA, int *pB) {
}
int pcode_check_imm_bits(int a1, int a2, int a3) {
}
int pcode_const_from_format(char *buf, int *pResult) {
}
PCode *vformatpcode(short opcode, va_list argList) {
}
int expectandformatoperand(PCodeArg *operand, unsigned char expectedKind, char a3, int bitCount, char *buf) {
}
int formatoperand(PCodeArg *operand, char *buf) {
}
void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) {
}
PCode *makecopyinstruction(PCodeArg *a, PCodeArg *b) {
}
int is_location_independent(PCode *pcode) {
}
int can_reuse_stored_value(PCode *a, PCode *b) {
}
int nbytes_loaded_or_stored_by(PCode *pcode) {
}
void change_num_operands(PCode *pcode, int newNum) {
}
void change_opcode(PCode *pcode, short opcode) {
pcode->flags = (pcode->flags & ~(opcodeinfo[pcode->op].flags & ~fIsPtrOp)) | opcodeinfo[opcode].flags;
if ((pcode->flags & fPCodeFlag10) && (pcode->flags & (fPCodeFlag1 | fPCodeFlag8)))
pcode->flags &= ~fPCodeFlag10;
pcode->op = opcode;
}

View File

@ -1,462 +0,0 @@
#pragma once
#include "PCode.h"
typedef struct _OpcodeInfo {
const char *name;
const char *format;
unsigned char x8;
unsigned char x9;
int xA;
unsigned int insn;
} OpcodeInfo;
enum {
PC_B = 0x0,
PC_BL = 0x1,
PC_BC = 0x2,
PC_BCLR = 0x3,
PC_BCCTR = 0x4,
PC_BT = 0x5,
PC_BTLR = 0x6,
PC_BTCTR = 0x7,
PC_BF = 0x8,
PC_BFLR = 0x9,
PC_BFCTR = 0xA,
PC_BDNZ = 0xB,
PC_BDNZT = 0xC,
PC_BDNZF = 0xD,
PC_BDZ = 0xE,
PC_BDZT = 0xF,
PC_BDZF = 0x10,
PC_BLR = 0x11,
PC_BCTR = 0x12,
PC_BCTRL = 0x13,
PC_BLRL = 0x14,
PC_LBZ = 0x15,
PC_LBZU = 0x16,
PC_LBZX = 0x17,
PC_LBZUX = 0x18,
PC_LHZ = 0x19,
PC_LHZU = 0x1A,
PC_LHZX = 0x1B,
PC_LHZUX = 0x1C,
PC_LHA = 0x1D,
PC_LHAU = 0x1E,
PC_LHAX = 0x1F,
PC_LHAUX = 0x20,
PC_LHBRX = 0x21,
PC_LWZ = 0x22,
PC_LWZU = 0x23,
PC_LWZX = 0x24,
PC_LWZUX = 0x25,
PC_LWBRX = 0x26,
PC_LMW = 0x27,
PC_STB = 0x28,
PC_STBU = 0x29,
PC_STBX = 0x2A,
PC_STBUX = 0x2B,
PC_STH = 0x2C,
PC_STHU = 0x2D,
PC_STHX = 0x2E,
PC_STHUX = 0x2F,
PC_STHBRX = 0x30,
PC_STW = 0x31,
PC_STWU = 0x32,
PC_STWX = 0x33,
PC_STWUX = 0x34,
PC_STWBRX = 0x35,
PC_STMW = 0x36,
PC_DCBF = 0x37,
PC_DCBST = 0x38,
PC_DCBT = 0x39,
PC_DCBTST = 0x3A,
PC_DCBZ = 0x3B,
PC_ADD = 0x3C,
PC_ADDC = 0x3D,
PC_ADDE = 0x3E,
PC_ADDI = 0x3F,
PC_ADDIC = 0x40,
PC_ADDICR = 0x41,
PC_ADDIS = 0x42,
PC_ADDME = 0x43,
PC_ADDZE = 0x44,
PC_DIVW = 0x45,
PC_DIVWU = 0x46,
PC_MULHW = 0x47,
PC_MULHWU = 0x48,
PC_MULLI = 0x49,
PC_MULLW = 0x4A,
PC_NEG = 0x4B,
PC_SUBF = 0x4C,
PC_SUBFC = 0x4D,
PC_SUBFE = 0x4E,
PC_SUBFIC = 0x4F,
PC_SUBFME = 0x50,
PC_SUBFZE = 0x51,
PC_CMPI = 0x52,
PC_CMP = 0x53,
PC_CMPLI = 0x54,
PC_CMPL = 0x55,
PC_ANDI = 0x56,
PC_ANDIS = 0x57,
PC_ORI = 0x58,
PC_ORIS = 0x59,
PC_XORI = 0x5A,
PC_XORIS = 0x5B,
PC_AND = 0x5C,
PC_OR = 0x5D,
PC_XOR = 0x5E,
PC_NAND = 0x5F,
PC_NOR = 0x60,
PC_EQV = 0x61,
PC_ANDC = 0x62,
PC_ORC = 0x63,
PC_EXTSB = 0x64,
PC_EXTSH = 0x65,
PC_CNTLZW = 0x66,
PC_RLWINM = 0x67,
PC_RLWNM = 0x68,
PC_RLWIMI = 0x69,
PC_SLW = 0x6A,
PC_SRW = 0x6B,
PC_SRAWI = 0x6C,
PC_SRAW = 0x6D,
PC_CRAND = 0x6E,
PC_CRANDC = 0x6F,
PC_CREQV = 0x70,
PC_CRNAND = 0x71,
PC_CRNOR = 0x72,
PC_CROR = 0x73,
PC_CRORC = 0x74,
PC_CRXOR = 0x75,
PC_MCRF = 0x76,
PC_MTXER = 0x77,
PC_MTCTR = 0x78,
PC_MTLR = 0x79,
PC_MTCRF = 0x7A,
PC_MTMSR = 0x7B,
PC_MTSPR = 0x7C,
PC_MFMSR = 0x7D,
PC_MFSPR = 0x7E,
PC_MFXER = 0x7F,
PC_MFCTR = 0x80,
PC_MFLR = 0x81,
PC_MFCR = 0x82,
PC_MFFS = 0x83,
PC_MTFSF = 0x84,
PC_EIEIO = 0x85,
PC_ISYNC = 0x86,
PC_SYNC = 0x87,
PC_RFI = 0x88,
PC_LI = 0x89,
PC_LIS = 0x8A,
PC_MR = 0x8B,
PC_NOP = 0x8C,
PC_NOT = 0x8D,
PC_LFS = 0x8E,
PC_LFSU = 0x8F,
PC_LFSX = 0x90,
PC_LFSUX = 0x91,
PC_LFD = 0x92,
PC_LFDU = 0x93,
PC_LFDX = 0x94,
PC_LFDUX = 0x95,
PC_STFS = 0x96,
PC_STFSU = 0x97,
PC_STFSX = 0x98,
PC_STFSUX = 0x99,
PC_STFD = 0x9A,
PC_STFDU = 0x9B,
PC_STFDX = 0x9C,
PC_STFDUX = 0x9D,
PC_FMR = 0x9E,
PC_FABS = 0x9F,
PC_FNEG = 0xA0,
PC_FNABS = 0xA1,
PC_FADD = 0xA2,
PC_FADDS = 0xA3,
PC_FSUB = 0xA4,
PC_FSUBS = 0xA5,
PC_FMUL = 0xA6,
PC_FMULS = 0xA7,
PC_FDIV = 0xA8,
PC_FDIVS = 0xA9,
PC_FMADD = 0xAA,
PC_FMADDS = 0xAB,
PC_FMSUB = 0xAC,
PC_FMSUBS = 0xAD,
PC_FNMADD = 0xAE,
PC_FNMADDS = 0xAF,
PC_FNMSUB = 0xB0,
PC_FNMSUBS = 0xB1,
PC_FRES = 0xB2,
PC_FRSQRTE = 0xB3,
PC_FSEL = 0xB4,
PC_FRSP = 0xB5,
PC_FCTIW = 0xB6,
PC_FCTIWZ = 0xB7,
PC_FCMPU = 0xB8,
PC_FCMPO = 0xB9,
PC_LWARX = 0xBA,
PC_LSWI = 0xBB,
PC_LSWX = 0xBC,
PC_STFIWX = 0xBD,
PC_STSWI = 0xBE,
PC_STSWX = 0xBF,
PC_STWCX = 0xC0,
PC_ECIWX = 0xC1,
PC_ECOWX = 0xC2,
PC_DCBI = 0xC3,
PC_ICBI = 0xC4,
PC_MCRFS = 0xC5,
PC_MCRXR = 0xC6,
PC_MFTB = 0xC7,
PC_MFSR = 0xC8,
PC_MTSR = 0xC9,
PC_MFSRIN = 0xCA,
PC_MTSRIN = 0xCB,
PC_MTFSB0 = 0xCC,
PC_MTFSB1 = 0xCD,
PC_MTFSFI = 0xCE,
PC_SC = 0xCF,
PC_FSQRT = 0xD0,
PC_FSQRTS = 0xD1,
PC_TLBIA = 0xD2,
PC_TLBIE = 0xD3,
PC_TLBLD = 0xD4,
PC_TLBLI = 0xD5,
PC_TLBSYNC = 0xD6,
PC_TW = 0xD7,
PC_TRAP = 0xD8,
PC_TWI = 0xD9,
PC_OPWORD = 0xDA,
PC_MFROM = 0xDB,
PC_DSA = 0xDC,
PC_ESA = 0xDD,
PC_DCCCI = 0xDE,
PC_DCREAD = 0xDF,
PC_ICBT = 0xE0,
PC_ICCCI = 0xE1,
PC_ICREAD = 0xE2,
PC_RFCI = 0xE3,
PC_TLBRE = 0xE4,
PC_TLBSX = 0xE5,
PC_TLBWE = 0xE6,
PC_WRTEE = 0xE7,
PC_WRTEEI = 0xE8,
PC_MFDCR = 0xE9,
PC_MTDCR = 0xEA,
PC_DCBA = 0xEB,
PC_DSS = 0xEC,
PC_DSSALL = 0xED,
PC_DST = 0xEE,
PC_DSTT = 0xEF,
PC_DSTST = 0xF0,
PC_DSTSTT = 0xF1,
PC_LVEBX = 0xF2,
PC_LVEHX = 0xF3,
PC_LVEWX = 0xF4,
PC_LVSL = 0xF5,
PC_LVSR = 0xF6,
PC_LVX = 0xF7,
PC_LVXL = 0xF8,
PC_STVEBX = 0xF9,
PC_STVEHX = 0xFA,
PC_STVEWX = 0xFB,
PC_STVX = 0xFC,
PC_STVXL = 0xFD,
PC_MFVSCR = 0xFE,
PC_MTVSCR = 0xFF,
PC_VADDCUW = 0x100,
PC_VADDFP = 0x101,
PC_VADDSBS = 0x102,
PC_VADDSHS = 0x103,
PC_VADDSWS = 0x104,
PC_VADDUBM = 0x105,
PC_VADDUBS = 0x106,
PC_VADDUHM = 0x107,
PC_VADDUHS = 0x108,
PC_VADDUWM = 0x109,
PC_VADDUWS = 0x10A,
PC_VAND = 0x10B,
PC_VANDC = 0x10C,
PC_VAVGSB = 0x10D,
PC_VAVGSH = 0x10E,
PC_VAVGSW = 0x10F,
PC_VAVGUB = 0x110,
PC_VAVGUH = 0x111,
PC_VAVGUW = 0x112,
PC_VCFSX = 0x113,
PC_VCFUX = 0x114,
PC_VCMPBFP = 0x115,
PC_VCMPEQFP = 0x116,
PC_VCMPEQUB = 0x117,
PC_VCMPEQUH = 0x118,
PC_VCMPEQUW = 0x119,
PC_VCMPGEFP = 0x11A,
PC_VCMPGTFP = 0x11B,
PC_VCMPGTSB = 0x11C,
PC_VCMPGTSH = 0x11D,
PC_VCMPGTSW = 0x11E,
PC_VCMPGTUB = 0x11F,
PC_VCMPGTUH = 0x120,
PC_VCMPGTUW = 0x121,
PC_VCTSXS = 0x122,
PC_VCTUXS = 0x123,
PC_VEXPTEFP = 0x124,
PC_VLOGEFP = 0x125,
PC_VMAXFP = 0x126,
PC_VMAXSB = 0x127,
PC_VMAXSH = 0x128,
PC_VMAXSW = 0x129,
PC_VMAXUB = 0x12A,
PC_VMAXUH = 0x12B,
PC_VMAXUW = 0x12C,
PC_VMINFP = 0x12D,
PC_VMINSB = 0x12E,
PC_VMINSH = 0x12F,
PC_VMINSW = 0x130,
PC_VMINUB = 0x131,
PC_VMINUH = 0x132,
PC_VMINUW = 0x133,
PC_VMRGHB = 0x134,
PC_VMRGHH = 0x135,
PC_VMRGHW = 0x136,
PC_VMRGLB = 0x137,
PC_VMRGLH = 0x138,
PC_VMRGLW = 0x139,
PC_VMULESB = 0x13A,
PC_VMULESH = 0x13B,
PC_VMULEUB = 0x13C,
PC_VMULEUH = 0x13D,
PC_VMULOSB = 0x13E,
PC_VMULOSH = 0x13F,
PC_VMULOUB = 0x140,
PC_VMULOUH = 0x141,
PC_VNOR = 0x142,
PC_VOR = 0x143,
PC_VPKPX = 0x144,
PC_VPKSHSS = 0x145,
PC_VPKSHUS = 0x146,
PC_VPKSWSS = 0x147,
PC_VPKSWUS = 0x148,
PC_VPKUHUM = 0x149,
PC_VPKUHUS = 0x14A,
PC_VPKUWUM = 0x14B,
PC_VPKUWUS = 0x14C,
PC_VREFP = 0x14D,
PC_VRFIM = 0x14E,
PC_VRFIN = 0x14F,
PC_VRFIP = 0x150,
PC_VRFIZ = 0x151,
PC_VRLB = 0x152,
PC_VRLH = 0x153,
PC_VRLW = 0x154,
PC_VRSQRTEFP = 0x155,
PC_VSL = 0x156,
PC_VSLB = 0x157,
PC_VSLH = 0x158,
PC_VSLO = 0x159,
PC_VSLW = 0x15A,
PC_VSPLTB = 0x15B,
PC_VSPLTH = 0x15C,
PC_VSPLTW = 0x15D,
PC_VSPLTISB = 0x15E,
PC_VSPLTISH = 0x15F,
PC_VSPLTISW = 0x160,
PC_VSR = 0x161,
PC_VSRAB = 0x162,
PC_VSRAH = 0x163,
PC_VSRAW = 0x164,
PC_VSRB = 0x165,
PC_VSRH = 0x166,
PC_VSRO = 0x167,
PC_VSRW = 0x168,
PC_VSUBCUW = 0x169,
PC_VSUBFP = 0x16A,
PC_VSUBSBS = 0x16B,
PC_VSUBSHS = 0x16C,
PC_VSUBSWS = 0x16D,
PC_VSUBUBM = 0x16E,
PC_VSUBUBS = 0x16F,
PC_VSUBUHM = 0x170,
PC_VSUBUHS = 0x171,
PC_VSUBUWM = 0x172,
PC_VSUBUWS = 0x173,
PC_VSUMSWS = 0x174,
PC_VSUM2SWS = 0x175,
PC_VSUM4SBS = 0x176,
PC_VSUM4SHS = 0x177,
PC_VSUM4UBS = 0x178,
PC_VUPKHPX = 0x179,
PC_VUPKHSB = 0x17A,
PC_VUPKHSH = 0x17B,
PC_VUPKLPX = 0x17C,
PC_VUPKLSB = 0x17D,
PC_VUPKLSH = 0x17E,
PC_VXOR = 0x17F,
PC_VMADDFP = 0x180,
PC_VMHADDSHS = 0x181,
PC_VMHRADDSHS = 0x182,
PC_VMLADDUHM = 0x183,
PC_VMSUMMBM = 0x184,
PC_VMSUMSHM = 0x185,
PC_VMSUMSHS = 0x186,
PC_VMSUMUBM = 0x187,
PC_VMSUMUHM = 0x188,
PC_VMSUMUHS = 0x189,
PC_VNMSUBFP = 0x18A,
PC_VPERM = 0x18B,
PC_VSEL = 0x18C,
PC_VSLDOI = 0x18D,
PC_VMR = 0x18E,
PC_VMRP = 0x18F,
PC_SLE = 0x190,
PC_SLEQ = 0x191,
PC_SLIQ = 0x192,
PC_SLLIQ = 0x193,
PC_SLLQ = 0x194,
PC_SLQ = 0x195,
PC_SRAIQ = 0x196,
PC_SRAQ = 0x197,
PC_SRE = 0x198,
PC_SREA = 0x199,
PC_SREQ = 0x19A,
PC_SRIQ = 0x19B,
PC_SRLIQ = 0x19C,
PC_SRLQ = 0x19D,
PC_SRQ = 0x19E,
PC_MASKG = 0x19F,
PC_MASKIR = 0x1A0,
PC_LSCBX = 0x1A1,
PC_DIV = 0x1A2,
PC_DIVS = 0x1A3,
PC_DOZ = 0x1A4,
PC_MUL = 0x1A5,
PC_NABS = 0x1A6,
PC_ABS = 0x1A7,
PC_CLCS = 0x1A8,
PC_DOZI = 0x1A9,
PC_RLMI = 0x1AA,
PC_RRIB = 0x1AB,
PC_PENTRY = 0x1AC,
PC_PEXIT = 0x1AD,
OPCODE_MAX = 0x1AE
};
extern OpcodeInfo opcodeInfo[OPCODE_MAX];
extern void pcode_get_hi_lo(int a1, char a2, int *pA, int *pB);
extern int pcode_check_imm_bits(int a1, int a2, int a3);
extern int pcode_const_from_format(char *buf, int *pResult);
extern PCode *vformatpcode(short opcode, va_list argList);
extern int expectandformatoperand(PCodeArg *operand, unsigned char expectedKind, char a3, int bitCount, char *buf);
extern int formatoperand(PCodeArg *operand, char *buf);
extern void formatoperands(PCode *pcode, char *buf, int showBasicBlocks);
extern PCode *makecopyinstruction(PCodeArg *a, PCodeArg *b);
extern int is_location_independent(PCode *pcode);
extern int can_reuse_stored_value(PCode *a, PCode *b);
extern int nbytes_loaded_or_stored_by(PCode *pcode);
extern void change_num_operands(PCode *pcode, int newNum);
extern void change_opcode(PCode *pcode, short opcode);

View File

@ -956,6 +956,6 @@ int OS_LoadMacResourceFork(const OSSpec *spec, void **file_data, SInt32 *file_le
return ENOENT;
}
Boolean OS_IsMultiByte(const char *str, int offset) {
Boolean OS_IsMultiByte(const char *str1, const char *str2) {
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,9 @@
#include "compiler.h"
#include "compiler/CError.h"
#include "compiler/CMangler.h"
#include "compiler/CParser.h"
#include "compiler/CPrep.h"
#include "compiler/CScope.h"
#include "compiler/enode.h"
#include "compiler/objects.h"
#include "compiler/scopes.h"
@ -1016,7 +1020,7 @@ static NameSpaceObjectList *CScope_FindLookupName(NameSpaceLookupList *list, Has
if (r6->object->otype == r30->object->otype) {
switch (r6->object->otype) {
case OT_TYPE:
if ((OBJ_TYPE(r6->object)->type == OBJ_TYPE(r30->object)->type) && (OBJ_TYPE(r6->object)->unk6 == OBJ_TYPE(r30->object)->unk6))
if ((OBJ_TYPE(r6->object)->type == OBJ_TYPE(r30->object)->type) && (OBJ_TYPE(r6->object)->qual == OBJ_TYPE(r30->object)->qual))
goto break1;
break;
case OT_TYPETAG:
@ -1196,7 +1200,7 @@ static Boolean CScope_SetupParseNameResult(CScopeParseResult *result, NameSpaceO
return 0;
case OT_TYPE:
result->x8 = OBJ_TYPE(list->object)->type;
result->xC = OBJ_TYPE(list->object)->unk6;
result->xC = OBJ_TYPE(list->object)->qual;
result->obj_10 = list->object;
result->name_4 = name;
result->x20 = 1;
@ -1388,7 +1392,7 @@ inline Boolean CScope_NSIteratorNext(CScopeNSIterator *iterator) {
}
}
Type *CScope_GetType(NameSpace *nspace, HashNameNode *name, void **unk6) {
Type *CScope_GetType(NameSpace *nspace, HashNameNode *name, UInt32 *qual) {
CScopeParseResult result;
CScopeNSIterator iterator;
NameSpaceObjectList *list;
@ -1400,13 +1404,13 @@ Type *CScope_GetType(NameSpace *nspace, HashNameNode *name, void **unk6) {
do {
for (list = CScope_NSIteratorFind(&iterator, name); list; list = list->next) {
if (list->object->otype == OT_TYPETAG) {
if (unk6)
*unk6 = NULL;
if (qual)
*qual = 0;
return OBJ_TYPE_TAG(list->object)->type;
}
if (list->object->otype == OT_TYPE) {
if (unk6)
*unk6 = OBJ_TYPE(list->object)->unk6;
if (qual)
*qual = OBJ_TYPE(list->object)->qual;
return OBJ_TYPE(list->object)->type;
}
}
@ -2429,7 +2433,7 @@ static void CScope_AddUsingObject(BClassList *bcl, NameSpace *nspace, ObjBase *o
if (!nspace->theclass) {
if ((list = CScope_FindQualName(nspace, name)) && (list->object->otype == OT_TYPE) &&
(OBJ_TYPE(obj)->type == OBJ_TYPE(list->object)->type) &&
(OBJ_TYPE(obj)->unk6 == OBJ_TYPE(list->object)->unk6))
(OBJ_TYPE(obj)->qual == OBJ_TYPE(list->object)->qual))
return;
}
copy = galloc(sizeof(ObjType));
@ -2530,7 +2534,7 @@ void CScope_AddClassUsingDeclaration(TypeClass *tclass, TypeClass *tclass2, Hash
}
}
void CScope_ParseUsingDeclaration(NameSpace *nspace, AccessType access) {
void CScope_ParseUsingDeclaration(NameSpace *nspace, short access, Boolean flag) {
// almost matches, slight bit of register weirdness
CScopeParseResult result;

View File

@ -0,0 +1,93 @@
#include "compiler/CABI.h"
#include "compiler/CMachine.h"
#include "compiler/types.h"
#include "compiler/CompilerTools.h"
static void *trans_vtboffsets; // TODO type
static void *cabi_pathroot; // TODO type - 8 byte struct??
static void *cabi_pathcur; // TODO type
static TypeClass *cabi_loop_class;
static Boolean cabi_loop_construct;
short CABI_GetStructResultArgumentIndex(void) {
return 0;
}
Type *CABI_GetSizeTType(void) {
return (Type *) &stunsignedlong;
}
Type *CABI_GetPtrDiffTType(void) {
return (Type *) &stsignedlong;
}
SInt16 CABI_StructSizeAlignValue(Type *type, SInt32 size) {}
void CABI_ReverseBitField(TypeBitfield *tbitfield) {}
// not sure about the sig for this, it's unused lmao
static void CABI_AllocateZeroVTablePointer() {}
static SInt32 CABI_GetBaseSize(TypeClass *tclass) {}
static void CABI_AllocateBases() {}
static void CABI_AllocateVirtualBasePointers() {}
static void CABI_GetMemberOffset() {}
static void CABI_AllocateMembers() {}
static void CABI_AllocateVirtualBases() {}
static void CABI_FindZeroDeltaVPtr() {}
static void CABI_FindZeroVirtualBaseMember() {}
void CABI_AddVTable(TypeClass *tclass) {
tclass->vtable = galloc(sizeof(VTable));
memclrw(tclass->vtable, sizeof(VTable));
}
SInt32 CABI_GetVTableOffset(TypeClass *tclass) {
return 0;
}
static void CABI_GetBaseVTableSize() {}
static void CABI_ApplyClassFlags() {}
static void CABI_AllocateVTable() {}
void CABI_LayoutClass(DeclE *decle, TypeClass *tclass) {}
void CABI_MakeDefaultArgConstructor(Object *obj, TypeClass *tclass) {}
static void CABI_ThisArg() {}
ENode *CABI_MakeThisExpr(TypeClass *tclass, SInt32 offset) {}
static void CABI_VArg() {}
static void CABI_MakeVArgExpr() {}
static void CABI_MakeCopyConArgExpr() {}
static void CABI_InitVBasePtr1() {}
static void CABI_InitVBasePtrs() {}
static void CABI_GetVBasePath() {}
static void CABI_GetVBasePtr() {}
static SInt32 CABI_FindNVBase(TypeClass *tclass, TypeClass *base, SInt32 offset) {}
SInt32 CABI_GetCtorOffsetOffset(TypeClass *tclass, TypeClass *base) {}
static void CABI_InitVBaseCtorOffsets() {}
static void CABI_InitVTablePtrs() {}
static Boolean CABI_IsOperatorNew(Object *obj) {}
Object *CABI_ConstructorCallsNew(TypeClass *tclass) {}
void CABI_TransConstructor(Object *obj, Statement *stmt, TypeClass *tclass, TransConstructorCallback callback, Boolean flag) {}
void CABI_MakeDefaultConstructor(TypeClass *tclass, Object *obj) {}
static void CABI_AssignObject() {}
static void CABI_FindIntegralSizeType() {}
static void CABI_AppendCopyRegion() {}
static void CABI_ClassInitLoopCallBack() {}
static void CABI_CopyConAssignCB() {}
void CABI_MakeDefaultCopyConstructor(TypeClass *tclass, Object *obj) {}
void CABI_MakeDefaultAssignmentOperator(TypeClass *tclass, Object *obj) {}
static void CABI_DestroyMembers() {}
static void CABI_DestroyBases() {}
static void CABI_DestroyVBases() {}
void CABI_TransDestructor(Object *obj1, Object *obj2, Statement *stmt, TypeClass *tclass) {}
void CABI_MakeDefaultDestructor(TypeClass *tclass, Object *obj) {}
static void CABI_CreateLayeredDestructor() {}
void CABI_MakeLayeredDestructor(TypeClass *tclass, Object *obj) {}
Object *CABI_GetDestructorObject(Object *obj, int what) {
return obj;
}
static void CABI_AddLayeredDestructor() {}
void CABI_AddLayeredDestructors(TypeClass *tclass) {}
ENode *CABI_DestroyObject(Object *dtor, ENode *objexpr, UInt8 mode, Boolean flag1, Boolean flag2) {}

View File

@ -0,0 +1,122 @@
#include "compiler/CClass.h"
typedef struct OVClassBase {
struct OVClassBase *next;
struct OVClass *ovclass;
Boolean is_virtual;
} OVClassBase;
typedef struct OVFunc {
struct OVFunc *next;
Object *obj;
struct OVClass *ovc8;
struct OVFunc *ovfC;
struct OVFunc *ovf10;
} OVFunc;
typedef struct OVClass {
TypeClass *tclass;
OVFunc *vfuncs;
OVClassBase *bases;
SInt32 offset;
SInt32 voffset;
Boolean alloced_vtable;
} OVClass;
static TypeClass *main_class;
static void *cclass_thunklist; // TODO type
static TypeClass *cclass_isbase_mostderived;
static void *cclass_isbase_foundoffset; // TODO type
static Boolean cclass_isambigbase;
static short cclass_founddepth;
static void *vtable_object_data; // TODO type
static void *vtable_data_size; // TODO type
static VTableObjectLink *vtable_object_links;
static TypeClass *cclass_vbase;
static OVClass *cclass_ovbase;
static OVClass *cclass_root;
static Object *found_pure;
static Boolean check_pures;
static Object *cclass_dominator_vobject;
static SInt32 cclass_dominator_voffset;
static Object *cclass_dominator_oobject;
static TypeClass *cclass_dominator_oclass;
static SInt32 cclass_dominator_ooffset;
static Object *cclass_dominator_eobject;
void CClass_Init(void) {}
void CClass_GenThunks(void) {}
static Object *CClass_ThunkObject(Object *obj, SInt32 a, SInt32 b, SInt32 c) {}
static Boolean CClass_IsZeroOffsetClass(TypeClass *a, TypeClass *b) {}
static UInt8 CClass_IsCovariantResult(Type *a, UInt32 qualA, Type *b, UInt32 qualB) {}
UInt8 CClass_GetOverrideKind(TypeFunc *a, TypeFunc *b, Boolean errorflag) {}
Boolean CClass_IsEmpty(TypeClass *tclass) {}
Boolean CClass_IsNonStaticMemberFunc(TypeMethod *tmethod) {}
Object *CClass_DefaultConstructor(TypeClass *tclass) {}
Object *CClass_DummyDefaultConstructor(TypeClass *tclass) {}
ENode *CClass_DefaultConstructorCall(TypeClass *a, TypeClass *b, ENode *expr, SInt32 unkshortparam, Boolean flag1, Boolean flag2, Boolean *errorflag) {}
Object *CClass_AssignmentOperator(TypeClass *tclass) {}
Object *CClass_CopyConstructor(TypeClass *tclass) {}
NameSpaceObjectList *CClass_MemberObject(TypeClass *tclass, HashNameNode *name) {}
Object *CClass_Constructor(TypeClass *tclass) {}
Object *CClass_Destructor(TypeClass *tclass) {}
Boolean CClass_IsConstructor(Object *obj) {}
Boolean CClass_IsDestructor(Object *obj) {}
Boolean CClass_IsPODClass(TypeClass *tclass) {}
Boolean CClass_IsTrivialCopyClass(TypeClass *tclass) {}
Boolean CClass_IsTrivialCopyAssignClass(TypeClass *tclass) {}
Boolean CClass_ReferenceArgument(TypeClass *tclass) {}
BClassList *CClass_GetPathCopy(BClassList *path, Boolean is_global) {}
BClassList *CClass_AppendPath(BClassList *a, BClassList *b) {}
static AccessType CClass_GetPathAccess(BClassList *path) {}
Boolean CClass_IsMoreAccessiblePath(BClassList *path1, BClassList *path2) {}
static BClassList *CClass_GetBasePathRec(TypeClass *a, TypeClass *b, SInt32 offset, short depth) {}
BClassList *CClass_GetBasePath(TypeClass *a, TypeClass *b, short *founddepth, Boolean *isambigbase) {}
Boolean CClass_IsBaseClass(TypeClass *a, TypeClass *b, short *founddepth, Boolean pathcheckflag, Boolean ambigerrorflag) {}
TypeClass *CClass_GetQualifiedClass(void) {}
ENode *CClass_AccessPathCast(BClassList *path, ENode *expr, Boolean flag) {}
ENode *CClass_ClassPointerCast(ENode *expr, TypeClass *a, TypeClass *b, Boolean typconflag, Boolean ambigerrorflag, Boolean pathcheckflag) {}
ENode *CClass_DirectBasePointerCast(ENode *expr, TypeClass *a, TypeClass *b) {}
SInt32 CClass_GetPathOffset(BClassList *path) {}
Boolean CClass_ClassDominates(TypeClass *a, TypeClass *b) {}
SInt32 CClass_VirtualBaseOffset(TypeClass *a, TypeClass *b) {}
SInt32 CClass_VirtualBaseVTableOffset(TypeClass *a, TypeClass *b) {}
SInt32 CClass_GetMemberOffset(TypeClass *tclass, HashNameNode *name, ObjMemberVar **obj) {}
Boolean CClass_OverridesBaseMember(TypeClass *tclass, HashNameNode *name, Object *obj) {}
static OVClass *CClass_FindOVClass(OVClass *ovclass, TypeClass *tclass, SInt32 offset) {}
static OVClass *CClass_BuildOVClassTree(OVClass *root, TypeClass *tclass, SInt32 offset, SInt32 voffset) {}
static Boolean CClass_IsBaseOf(OVClass *a, OVClass *b) {}
static void CClass_FindOVFunc(OVClass *a, OVClass *b, OVFunc *func) {}
static TypeList *CClass_GetCoVariantClassList(TypeList *list, TypeClass *tclass, Object *func, Boolean flag) {}
static TypeMethod *CClass_GetCovariantType(TypeMethod *tmethod, Type *type) {}
static Object *CClass_FindCovariantFunction(Object *func, Type *type) {}
static ObjectList *CClass_DeclareCovariantFuncs(ObjectList *list, Object *func, TypeClass *tclass) {}
void CClass_DefineCovariantFuncs(Object *method, CI_FuncData *ifuncdata) {}
static void CClass_OverrideOVClassTree(OVClass *ovclass) {}
static void CClass_AllocVTableRec(OVClass *ovclass) {}
static Object *CClass_CheckClass(OVClass *ovclass, Boolean errorflag) {}
static void CClass_AllocVTable(TypeClass *tclass) {}
static Object *CClass_CheckVirtuals(TypeClass *tclass) {}
static void CClass_CheckVirtualBaseOverrides(OVClass *a, OVClass *b, Boolean flag) {}
static void CClass_CheckHideVirtual(OVClass *a, OVClass *b) {}
void CClass_CheckOverrides(TypeClass *tclass) {}
static void CClass_FindDominator(TypeClass *tclass1, SInt32 offset1, Object *object1, TypeClass *tclass2, SInt32 offset2, TypeClass *base) {}
static void CClass_ConstructVTable(TypeClass *tclass, SInt32 voffset, SInt32 offset, TypeClass *base) {}
void CClass_ClassDefaultFuncAction(TypeClass *tclass) {}
void CClass_ClassAction(TypeClass *tclass) {}
void CClass_MakeStaticActionClass(TypeClass *tclass) {}
Object *CClass_CheckPures(TypeClass *tclass) {}
void CClass_MemberDef(Object *obj, TypeClass *tclass) {}
Object *CClass_ThisSelfObject(void) {}
ENode *CClass_CreateThisSelfExpr(void) {}
static Boolean CClass_BaseMemberAccess(BClassList *path, AccessType access) {}
static Boolean CClass_CanAccess(BClassList *path, AccessType access) {}
void CClass_CheckPathAccess(BClassList *path, Object *obj, AccessType access) {}
static BClassList *CClass_PathCleanup(BClassList *path, TypeClass *tclass) {}
void CClass_CheckStaticAccess(BClassList *path, TypeClass *tclass, AccessType access) {}
void CClass_CheckObjectAccess(BClassList *path, Object *obj) {}
void CClass_CheckEnumAccess(BClassList *path, ObjEnumConst *objec) {}
static Type *CClass_PointerTypeCopy(Type *type) {}
Type *CClass_CombineClassAccessQualifiers(Type *type, UInt32 qual1, UInt32 qual2, UInt32 *outflags) {}
static void CClass_OptimizeBitFieldAccess(Type **type, SInt32 *offset) {}
ENode *CClass_AccessMember(ENode *classexpr, Type *type, UInt32 qual, SInt32 offset) {}

View File

@ -3,6 +3,7 @@
#include "compiler/types.h"
#include "pref_structs.h"
#include "compiler/CompilerTools.h"
#include "compiler/CPrep.h"
Boolean systemHandles;
@ -11,14 +12,6 @@ Boolean crippled;
SInt32 license_cookie;
CParams cparams;
// TODO move me to CParser.c, or maybe CMachine.c?
Type sttemplexpr = {TYPETEMPLDEPEXPR, 0};
Type stillegal = {TYPEILLEGAL, 1};
Type stvoid = {TYPEVOID, 0};
TypePointer void_ptr = {TYPEPOINTER, 0, &stvoid, 0};
TypeFunc rt_func = {TYPEFUNC, 0, NULL, NULL, &stvoid, 0, 0};
// TODO move me to CParser.c
static void get_extension(ConstStringPtr src, char *dst) {
int ep;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,123 @@
#include "compiler/CExpr.h"
#include "compiler/CError.h"
Boolean (*name_obj_check)(void *, Object *); // TODO figure out the right type
Boolean disallowgreaterthan;
void CExpr_RewriteConst() {}
void optimizecomm() {}
static void checkadditive() {}
static void CExpr_CompareConvert() {}
static void CExpr_ConstResult() {}
static void makemultnode() {}
static void makedivnode() {}
static void canadd2() {}
void canadd() {}
static void addconst() {}
static void integralpointerpromote() {}
static void padd() {}
static void psub() {}
static void makeaddnode() {}
static void makesubnode() {}
void checkreference() {}
static ENode *pointer_generation2(ENode *expr) {}
ENode *pointer_generation(ENode *expr) {}
void CExpr_PointerGeneration() {}
static void CExpr_ConstPointerCheck() {}
void oldassignmentpromotion() {}
void argumentpromotion() {}
void classargument() {}
ENodeList *CExpr_ScanExpressionList(Boolean flag) {}
static void skipcommaexpr() {}
void CExpr_DoExplicitConversion() {}
static void CExpr_TemplArgDepCast() {}
static void CExpr_ParseExplicitConversion() {}
static void CExpr_MemberVarAccess() {}
static void CExpr_IsTemplateFunc() {}
static void CExpr_ExplicitTemplateArgCheck() {}
void CExpr_MakeNameLookupResultExpr() {}
static void CExpr_NewPTMType() {}
static void CExpr_ParseNameResultExpr() {}
static void CExpr_ParseRotate() {}
static void CExpr_ParseNextArg() {}
static void CExpr_ParseVecStep() {}
static void CExpr_BuiltInComputeAlign() {}
static void CExpr_AtomTypeID() {}
static void CExpr_BuiltInComputeType() {}
static void CExpr_BuiltInClassifyType() {}
static void CExpr_BuiltInComputeVArgType() {}
static void CExpr_ParseTypeExpression() {}
static void CExpr_ParseBuiltin() {}
static void CExpr_ParseBuiltin_isintconst() {}
static void primary_expression() {}
static void CExpr_SimpleExplicitConversion() {}
static void CExpr_NewPTMFCall() {}
static void call_ptmf() {}
static void CExpr_DummyDestr() {}
static void postfix_expression() {}
static void CExpr_ParseSizeof() {}
void scansizeof() {}
static void CExpr_ParseAlignof() {}
void scanalignof() {}
static void logicalexpression() {}
void getnodeaddress() {}
static void CExpr_MakeStaticMemberList() {}
static void CExpr_MakePTDM() {}
void getpointertomemberfunc() {}
static void getpointertomember() {}
void CExpr_New_ELOGNOT_Node() {}
void CExpr_New_EMONMIN_Node() {}
void CExpr_New_EBINNOT_Node() {}
void unary_expression() {}
void do_castnullcheck() {}
void CExpr_SafeClassPointerCast() {}
void PointerToMemberCast() {}
void CExpr_MemberPointerConversion() {}
static void CExpr_MemberPointerCast() {}
void do_typecast() {}
static void isvectorconst() {}
void cast_expression() {}
static void pm_expression() {}
void CExpr_New_EMUL_Node() {}
void CExpr_New_EDIV_Node() {}
void CExpr_New_EMODULO_Node() {}
void CExpr_New_EADD_Node() {}
void CExpr_New_ESUB_Node() {}
void CExpr_New_ESHL_Node() {}
void CExpr_New_ESHR_Node() {}
static void pointercompare() {}
static void unsigncheck() {}
void CExpr_New_ELESS_Node() {}
void CExpr_New_ELESSEQU_Node() {}
void CExpr_New_EGREATER_Node() {}
void CExpr_New_EGREATEREQU_Node() {}
void memberpointercompare() {}
void CExpr_New_EEQU_Node() {}
void CExpr_New_ENOTEQU_Node() {}
void CExpr_New_EAND_Node() {}
void CExpr_New_EXOR_Node() {}
void CExpr_New_EOR_Node() {}
void CExpr_New_ELAND_Node() {}
void CExpr_New_ELOR_Node() {}
void CExpr_NewDyadicNode() {}
static void CExpr_GetDyadicInfo() {}
static void CExpr_ParseDyadicExpression() {}
static void CExpr_IsBlockMoveType() {}
void CExpr_New_ECOND_Node() {}
static void conditional_expression() {}
static void CExpr_MakeOpAssNode() {}
static void makeassignmentnode() {}
static void makepassignmentnode() {}
static void makemulassignmentnode() {}
static void CExpr_TransformOpAssign() {}
ENode *assignment_expression(void) {}
ENode *conv_assignment_expression(void) {}
static void CExpr_HasSideEffect() {}
void CExpr_CheckUnusedExpression() {}
void s_expression() {}
ENode *expression(void) {}
void CExpr_IntegralConstExprType() {}
ENode *CExpr_IntegralConstOrDepExpr(void) {}
void CExpr_IntegralConstExpr() {}
void CExpr_CheckUnwantedAssignment() {}
void CExpr_ParseAsmExpr() {}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,105 @@
#include "compiler/CFunc.h"
#include "compiler/types.h"
FuncArg elipsis;
FuncArg oldstyle;
ObjectList *arguments;
ObjectList *locals;
short localcount;
SInt32 curstmtvalue;
SInt32 sourceoffset;
HashNameNode *sourcefilepath;
SInt32 functionbodyoffset;
HashNameNode *functionbodypath;
InitExpr *init_expressions;
CLabel *Labels;
CtorChain *ctor_chain;
Statement *curstmt;
static short temp_destructor_object_regmem;
static short temp_destructor_objects;
static short temp_expression_has_conditionals;
static DeclBlock *firstblock;
static DeclBlock *currentblock;
static short blockcount;
static Object *sinit_first_object;
static CLabel *sinit_label;
static Boolean ainit_only_one;
static ENode *ainit_expr;
static FuncArg *check_arglist;
static Boolean cfunc_is_extern_c;
static short cfunc_staticvarcount;
static void *destroyobjects;
static Boolean cfunc_hasdtortemp;
static void CFunc_LoopIncrement(void) {}
static void CFunc_LoopDecrement(void) {}
DeclBlock *CFunc_NewDeclBlock(void) {}
void CFunc_RestoreBlock(DeclBlock *block) {}
void CFunc_SetupLocalVarInfo(Object *obj) {}
static void adjustargumenttype(DeclInfo *declinfo) {}
static FuncArg *CFunc_IsInArgList(FuncArg *list, HashNameNode *name) {}
static Object *CFunc_IsInObjList(ObjectList *list, HashNameNode *name) {}
static void CFunc_AppendArg(FuncArg **list, FuncArg *arg) {}
static void identifier_list(DeclInfo *declinfo) {}
static Boolean defarg_name_obj_check(HashNameNode *name, Object *obj) {}
void CFunc_DefaultArg(Type *type, short qual, FuncArg *args) {}
static FuncArg *parameter_list(DeclInfo *declinfo) {}
Boolean CFunc_ParseFakeArgList(Boolean flag) {}
FuncArg *parameter_type_list(DeclInfo *declinfo) {}
CLabel *findlabel(void) {}
CLabel *newlabel(void) {}
Statement *CFunc_AppendStatement(StatementType sttype) {}
Statement *CFunc_InsertStatement(StatementType sttype, Statement *after) {}
Statement *CFunc_InsertBeforeStatement(StatementType sttype, Statement *before) {}
void CheckCLabels(void) {}
Object *create_temp_object(Type *type) {}
ENode *create_temp_node(Type *type) {}
ENode *create_temp_node2(Type *type) {}
static void CFunc_DestroyReverse() {} // not sure about type
static void CFunc_TempTransDestroy() {} // not sure about type
void CFunc_WarnUnused(void) {}
void CFunc_CodeCleanup(Statement *stmt) {}
static Boolean DestructorNeeded(ExceptionAction *a, ExceptionAction *b) {}
static Statement *DestructLocals(Statement *stmt, ExceptionAction *exc1, ExceptionAction *exc2) {}
static Boolean NeedsDestruction(Statement *stmt1, Statement *stmt2) {}
static ExceptionAction *FindLastNonCommonStackObj(Statement *stmt1, Statement *stmt2) {}
static void DestructorReturnTransform(Statement *stmt1, Statement *stmt2) {}
static Statement *DestructorIfTransform(Statement *stmt) {}
static Boolean IsSubStack(ExceptionAction *exc1, ExceptionAction *exc2) {}
static void CFunc_CheckInitSkip(Statement *stmt, ExceptionAction *exc) {}
void CFunc_DestructorCleanup(Statement *stmt) {}
static void scancase(DeclThing *thing) {}
static void CFunc_NameLocalStaticDataObject(Object *obj, char *str) {}
static void sinit_insert_expr(ENode *expr) {}
static void ainit_insert_expr(ENode *expr) {}
static ENode *ainit_register_object(TypeClass *tclass, Object *local, SInt32 offset, void *unk) {}
static void CFunc_LocalDataDeclarator(DeclInfo *declinfo, TStreamElement *element, Boolean flag1, Boolean flag2) {}
static ENode *CFunc_ParseLocalDeclarationList(Boolean flag1, Boolean flag2, Boolean flag3, Boolean flag4) {}
static void makeifstatement(ENode *expr, CLabel *label1, CLabel *label2, Boolean flag1, Boolean flag2) {}
static void CFunc_HasDtorTempCallBack(ENode *expr) {}
static void ifstatement(Boolean flag1, ENode *expr, CLabel *label, Boolean flag2) {}
Statement *CFunc_GenerateLoop(Statement *stmt, Type *type, ENode *expr1, ENode *expr2, ENode *expr3, ENode *expr4, ENode (*callback)(ENode *, ENode *)) {}
static Boolean checklabel(void) {}
static ENode *returnstatementadjust(ENode *expr, Type *type, UInt32 qual) {}
static void CFunc_AutoResultCheck(ENode *expr) {}
static void statement(DeclThing *thing) {}
void CFunc_CompoundStatement(DeclThing *thing) {}
static void CFunc_InsertArgumentCopyConversion(Object *obj, Type *type1, Type *type2, Boolean flag) {}
static void CFunc_AdjustOldStyleArgs(void) {}
void CFunc_SetupNewFuncArgs(Object *obj, FuncArg *args) {}
static ObjectList *CFunc_CopyObjectList(ObjectList *list) {}
static void SetupFunctionArguments(Object *obj, DeclInfo *declinfo) {}
NameSpace *CFunc_FuncGenSetup(Statement *stmt) {}
void CFunc_GetGlobalCompilerState(CFuncSave *state) {}
void CFunc_SetGlobalCompilerState(CFuncSave *state) {}
void CFunc_Gen(Statement *stmt, Object *obj, UInt8 unk) {}
static void CFunc_CheckCtorInitializer(TypeClass *tclass, CtorChain *chain) {}
void CFunc_CheckClassCtors(TypeClass *tclass) {}
static void CFunc_ParseCtorInitializer(void) {}
static void CFunc_FunctionRedefinedCheck(Object *obj) {}
static Object *CFunc_DeclareFuncName(char *str, HashNameNode *name) {}
void CFunc_ParseFuncDef(Object *obj, DeclInfo *declinfo, TypeClass *tclass, Boolean is_method, Boolean is_static, NameSpace *nspace) {}
void InitExpr_Register(ENode *expr, Object *object) {}
void CFunc_GenerateDummyFunction(Object *a) {}
void CFunc_GenerateSingleExprFunc(Object *a, ENode *expr) {}
void CFunc_GenerateDummyCtorFunc(Object *a, Object *b) {}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,116 @@
#include "compiler/CInline.h"
#include "compiler/CFunc.h"
static CInlineCopyMode enode_copymode;
static Boolean enode_globalcopy;
static void *enode_idtrans; // type?
static void *local_dobjects; // type?
static void *local_aobjects; // type?
static CI_Var *loc_args;
static CI_Var *loc_vars;
static Boolean inline_expanded;
static Boolean any_inline_expanded;
static short cinline_level;
static void *cinline_label_trans; // type?
static Statement *cinline_first_stmt;
static void *cinline_stmtlevelexpr[16]; // type?
static short cinline_stmtlevelexprs;
static Boolean cinline_unconditionalpart;
static Boolean cinline_serialize_stmt;
static void *cinline_exportlist; // type?
static CI_Action *cinline_actionlist;
CI_Action *cinline_tactionlist;
static ObjectList *cinline_freflist;
static Boolean cinline_gendeps;
static Statement *cinline_serial_stmt;
static Statement *cinline_cur_serial_stmt;
static void *cinline_uid_temps; // type?
static Boolean cinline_has_sideeffect;
static SInt32 inline_max_size;
static Boolean recursive_inline;
static Object *expanding_function;
static Boolean cinline_funccallfound;
void CInline_Init(void) {}
static ENode *CInline_MakeNotNot(ENode *expr) {}
static ENode *CInline_FoldConst(ENode *expr) {}
SInt32 CInline_GetLocalID(Object *obj) {}
static Boolean CInline_IsTrivialExpression(ENode *expr) {}
Boolean CInline_ExpressionHasSideEffect(ENode *expr) {}
static ENode *CInline_CopyExpressionSave(ENode *expr) {}
static SInt32 CInline_TranslateID(SInt32 id) {}
static SInt32 CInline_GetLabelStatementNumber(HashNameNode *name) {}
static ENodeList *CInline_CopyNodeList(ENodeList *list) {}
static EMemberInfo *CInline_CopyEMemberInfo(EMemberInfo *mi) {}
static ENode *CInline_CopyNodes(ENode *node) {}
static void CInline_CheckUsage(ENode *expr, Boolean flag) {}
ENode *CInline_CopyExpression(ENode *expr, CInlineCopyMode mode) {}
static UInt8 CInline_GetObjectSFlags(Object *obj) {}
static void CInline_SetObjectSFlags(Object *obj, UInt8 sflags) {}
static Object *CInline_NewLocalObject(Type *type, short qual, UInt8 sflags) {}
static ENode *CInline_FuncArgConvert(ENode *expr) {}
static ENode *CInline_RefArgTransform(ENode *expr, Boolean flag) {}
static ENode *CInline_SetupArgsExpression(Object *obj, CI_FuncData *data, ENodeList *list) {}
static void CInline_ReturnCheckCB(/* there should be args here */) {}
static ENode *CInline_ReturnCheck(ENode *expr) {}
static ENode *CInline_ReturnMemResult(void) {}
static ENode *CInline_InlineFunctionExpression(ENode *expr) {}
static Boolean CInline_CanExpand(ENode *expr) {}
static SInt32 CInline_EstimateSizeOfExpr(ENode *expr, SInt32 a, SInt32 b) {}
static SInt32 CInline_EstimateSizeOfFunc(CI_FuncData *funcdata, SInt32 a, SInt32 b) {}
static SInt32 EstimateExpandedSizeOfExpr(ENode *expr, SInt32 b) {}
static SInt32 EstimateExpandedSizeOfFunction(Statement *stmt) {}
static Boolean CInline_InlineFunctionCheck(ENode *expr) {}
static ENode *CInline_ExpandExpression(ENode *expr) {}
static Statement *CInline_NewStatement(StatementType sttype) {}
static ENode *CInline_LoadToTemp(ENode *expr, Object **obj) {}
static ENode *CInline_SerializeEFORCELOAD(ENode *expr) {}
static ENode *CInline_SerializeECOMMA(ENode *expr) {}
static ENode *CInline_SerializeELOR(ENode *expr) {}
static ENode *CInline_SerializeELAND(ENode *expr) {}
static ENode *CInline_SerializeEPRECOMP(ENode *expr) {}
static ENode *CInline_SerializeENULLCHECK(ENode *expr) {}
static ENode *CInline_SerializeECOND(ENode *expr) {}
static ENode *CInline_SerializeExpr(ENode *expr) {}
void CInline_SerializeStatement(Statement *stmt) {}
static void CInline_UnpackSwitch(Statement *stmt, CI_Statement *packed, CLabel **labels) {}
Object *CInline_GetLocalObj(SInt32 id, Boolean flag) {}
static ExceptionAction *CInline_UnpackActions(CI_Statement *packed, Boolean flag) {}
static Statement *CInline_ExpandStatements(Object *obj, Statement *stmt, CI_FuncData *data, ENode *expr, CLabel *label, Object *obj2, Boolean flag) {}
static Statement *CInline_InlineFunctionStatement(Statement *stmt, Boolean *success) {}
static Statement *CInline_ExtractInlineFunction(Statement *stmt) {}
static Statement *CInline_ExpandStatement(Statement *stmt) {}
static void CInline_ForceReverseSearch(ENode *) {}
static ENode *CInline_ForceReverseEvaluation(ENode *expr) {}
static void CInline_ExportCheck(ENode *expr) {}
static void CInline_Expand(Statement *stmt) {}
SInt32 CInline_GetStatementNumber(Statement *first, Statement *stmt) {}
static CI_Switch *CInline_PackSwitch(Statement *s1, Statement *s2) {}
static Boolean CInline_CanInline(Object *obj, Statement *stmt) {}
static ExceptionAction *CInline_PackActions(Statement *s1, Statement *s2) {}
void CInline_PackIFunctionData(CI_FuncData *packed, Statement *stmt, Object *obj) {}
void CInline_UnpackIFunctionData(Object *obj, CI_FuncData *packed, Statement *stmt) {}
static void CInline_GenIFunctionCode(Object *obj, CI_FuncData *func, UInt8 unk) {}
void CInline_AddDefaultFunctionAction(Object *obj) {}
void CInline_AddInlineFunctionAction(Object *obj, TypeClass *tclass, FileOffsetInfo *fileoffset, TStream *stream, Boolean flag) {}
void CInline_AddMemberFunctionAction(Object *obj, Type *a, Type *b, TemplateMember *tmemb) {}
void CInline_AddTemplateFunctionAction(Object *obj, TemplateFunction *func, TemplFuncInstance *inst) {}
static void CInline_AddFRefList_Object(Object *obj) {}
static void CInline_AddFRefList_ExAction(ExceptionAction *exc) {}
static void CInline_AddFRefList_ExprCB(ENode *expr) {}
static void CInline_AddFRefList_Expr(ENode *expr) {}
static void CInline_AddFRefList_Statement(Statement *stmt) {}
static void CInline_AddFRefList_InlineFunc(CI_FuncData *data) {}
static void CInline_GenerateTemplateInline(Object *obj) {}
void CInline_ObjectAddrRef(Object *obj) {}
static Boolean CInline_CheckDependencies(ObjectList *list) {}
static Boolean CInline_IsSmallFunction(Object *obj, Statement *stmt) {}
static Boolean CInline_NoFPLocals(void) {}
void CInline_GenFunc(Statement *stmt, Object *obj, UInt8 unk) {}
static void CInline_GenerateDefaultFunc(Object *obj) {}
static TemplClassInst *CInline_FindNestedTemplInst(TemplClassInst *inst) {}
static void CInline_GenerateInlineFunc(CI_Action *action) {}
Boolean CInline_CanFreeLHeap(void) {}
Boolean CInline_GenerateDeferredFuncs(void) {}
static InitExpr *CInline_InitTemplateData(InitExpr *init) {}
void CInline_Finish(void) {}

View File

@ -186,6 +186,7 @@ SInt32 CMach_ArgumentAlignment(Type *type) {
return align;
}
// TODO: investigate if this returns SInt16 actually
SInt32 CMach_AllocationAlignment(Type *type, UInt32 qual) {
SInt32 align;
SInt32 qualalign;
@ -573,7 +574,7 @@ void CMach_InitIntMem(Type *type, CInt64 val, void *mem) {
}
}
void CMach_InitVectorMem(Type *type, MWVector128 val, void *mem) {
void CMach_InitVectorMem(Type *type, MWVector128 val, void *mem, Boolean flag) {
unsigned char uc[16];
unsigned short us[8];
unsigned int ul[4];
@ -856,7 +857,7 @@ static SInt16 CMach_GetQualifiedStructAlign(TypeStruct *tstruct, Boolean flag) {
switch (copts.align_mode) {
case AlignMode3_1Byte:
case AlignMode8:
case AlignMode8_Packed:
return 1;
case AlignMode0_Mac68k:
return 2;
@ -941,7 +942,7 @@ static SInt16 CMach_GetQualifiedClassAlign(TypeClass *tclass, Boolean flag) {
switch (copts.align_mode) {
case AlignMode3_1Byte:
case AlignMode8:
case AlignMode8_Packed:
return 1;
case AlignMode0_Mac68k:
return 2;
@ -1047,7 +1048,7 @@ static SInt16 CMach_GetQualifiedTypeAlign(Type *type, Boolean flag) {
switch (copts.align_mode) {
case AlignMode3_1Byte:
case AlignMode8:
case AlignMode8_Packed:
return 1;
case AlignMode4_2Byte:
case AlignMode5_4Byte:
@ -1166,7 +1167,7 @@ static SInt16 CMach_GetMemberAlignment(Type *type, SInt32 var, Boolean flag) {
align = 16;
switch (copts.align_mode) {
case AlignMode8:
case AlignMode8_Packed:
align = 1;
break;
case AlignMode0_Mac68k:
@ -1266,7 +1267,7 @@ SInt32 CMach_StructLayoutBitfield(TypeBitfield *tbitfield, UInt32 qual) {
switch (copts.align_mode) {
case AlignMode3_1Byte:
case AlignMode8:
case AlignMode8_Packed:
required_alignment = 0;
break;
}

View File

@ -0,0 +1,719 @@
#include "compiler.h"
#include "compiler/CError.h"
#include "compiler/CInt64.h"
#include "compiler/enode.h"
#include "compiler/objects.h"
#include "compiler/scopes.h"
#include "compiler/templates.h"
#include "compiler/types.h"
#include "cos.h"
HashNameNode *constructor_name_node;
HashNameNode *destructor_name_node;
HashNameNode *asop_name_node;
// forward decls
static void CMangler_MangleClassName(TypeClass *tclass);
static void CMangler_MangleTypeAppend(Type *type, UInt32 qual);
static void CMangler_MangleArgs(FuncArg *args);
void CMangler_Setup(void) {
constructor_name_node = GetHashNameNodeExport("__ct");
destructor_name_node = GetHashNameNodeExport("__dt");
asop_name_node = GetHashNameNodeExport("__as");
}
HashNameNode *CMangler_BasicDtorName(void) {
return GetHashNameNodeExport("__dtb");
}
HashNameNode *CMangler_VBaseDtorName(void) {
return GetHashNameNodeExport("__dtv");
}
HashNameNode *CMangler_ArrayDtorName(void) {
return GetHashNameNodeExport("__dta");
}
HashNameNode *CMangler_SDeleteDtorName(void) {
return GetHashNameNodeExport("__dts");
}
HashNameNode *CMangler_DeleteDtorName(void) {
return GetHashNameNodeExport("__dt");
}
char *CMangler_GetOperator(HashNameNode *opname) {
char *name;
if (opname == asop_name_node)
return "operator=";
name = opname->name;
if (!strcmp(name, "__nw")) return "operator new";
if (!strcmp(name, "__dl")) return "operator delete";
if (!strcmp(name, "__nwa")) return "operator new[]";
if (!strcmp(name, "__dla")) return "operator delete[]";
if (!strcmp(name, "__pl")) return "operator+";
if (!strcmp(name, "__mi")) return "operator-";
if (!strcmp(name, "__ml")) return "operator*";
if (!strcmp(name, "__dv")) return "operator/";
if (!strcmp(name, "__md")) return "operator%";
if (!strcmp(name, "__er")) return "operator^";
if (!strcmp(name, "__ad")) return "operator&";
if (!strcmp(name, "__or")) return "operator|";
if (!strcmp(name, "__co")) return "operator~";
if (!strcmp(name, "__nt")) return "operator!";
if (!strcmp(name, "__lt")) return "operator<";
if (!strcmp(name, "__gt")) return "operator>";
if (!strcmp(name, "__apl")) return "operator+=";
if (!strcmp(name, "__ami")) return "operator-=";
if (!strcmp(name, "__amu")) return "operator*=";
if (!strcmp(name, "__adv")) return "operator/=";
if (!strcmp(name, "__amd")) return "operator%=";
if (!strcmp(name, "__aer")) return "operator^=";
if (!strcmp(name, "__aad")) return "operator&=";
if (!strcmp(name, "__aor")) return "operator|=";
if (!strcmp(name, "__ls")) return "operator<<";
if (!strcmp(name, "__rs")) return "operator>>";
if (!strcmp(name, "__als")) return "operator<<=";
if (!strcmp(name, "__ars")) return "operator>>=";
if (!strcmp(name, "__eq")) return "operator==";
if (!strcmp(name, "__ne")) return "operator!=";
if (!strcmp(name, "__le")) return "operator<=";
if (!strcmp(name, "__ge")) return "operator>=";
if (!strcmp(name, "__aa")) return "operator&&";
if (!strcmp(name, "__oo")) return "operator||";
if (!strcmp(name, "__pp")) return "operator++";
if (!strcmp(name, "__mm")) return "operator--";
if (!strcmp(name, "__cm")) return "operator,";
if (!strcmp(name, "__rm")) return "operator->*";
if (!strcmp(name, "__rf")) return "operator*";
if (!strcmp(name, "__cl")) return "operator()";
if (!strcmp(name, "__vc")) return "operator[]";
return NULL;
}
HashNameNode *CMangler_OperatorName(short token) {
switch (token) {
case TK_NEW: return GetHashNameNodeExport("__nw");
case TK_DELETE: return GetHashNameNodeExport("__dl");
case TK_NEW_ARRAY: return GetHashNameNodeExport("__nwa");
case TK_DELETE_ARRAY: return GetHashNameNodeExport("__dla");
case '+': return GetHashNameNodeExport("__pl");
case '-': return GetHashNameNodeExport("__mi");
case '*': return GetHashNameNodeExport("__ml");
case '/': return GetHashNameNodeExport("__dv");
case '%': return GetHashNameNodeExport("__md");
case '^': return GetHashNameNodeExport("__er");
case '&': return GetHashNameNodeExport("__ad");
case '|': return GetHashNameNodeExport("__or");
case '~': return GetHashNameNodeExport("__co");
case '!': return GetHashNameNodeExport("__nt");
case '=': return asop_name_node;
case '<': return GetHashNameNodeExport("__lt");
case '>': return GetHashNameNodeExport("__gt");
case TK_ADD_ASSIGN: return GetHashNameNodeExport("__apl");
case TK_SUB_ASSIGN: return GetHashNameNodeExport("__ami");
case TK_MULT_ASSIGN: return GetHashNameNodeExport("__amu");
case TK_DIV_ASSIGN: return GetHashNameNodeExport("__adv");
case TK_MOD_ASSIGN: return GetHashNameNodeExport("__amd");
case TK_XOR_ASSIGN: return GetHashNameNodeExport("__aer");
case TK_AND_ASSIGN: return GetHashNameNodeExport("__aad");
case TK_OR_ASSIGN: return GetHashNameNodeExport("__aor");
case TK_SHL: return GetHashNameNodeExport("__ls");
case TK_SHR: return GetHashNameNodeExport("__rs");
case TK_SHL_ASSIGN: return GetHashNameNodeExport("__als");
case TK_SHR_ASSIGN: return GetHashNameNodeExport("__ars");
case TK_LOGICAL_EQ: return GetHashNameNodeExport("__eq");
case TK_LOGICAL_NE: return GetHashNameNodeExport("__ne");
case TK_LESS_EQUAL: return GetHashNameNodeExport("__le");
case TK_GREATER_EQUAL: return GetHashNameNodeExport("__ge");
case TK_LOGICAL_AND: return GetHashNameNodeExport("__aa");
case TK_LOGICAL_OR: return GetHashNameNodeExport("__oo");
case TK_INCREMENT: return GetHashNameNodeExport("__pp");
case TK_DECREMENT: return GetHashNameNodeExport("__mm");
case ',': return GetHashNameNodeExport("__cm");
case TK_ARROW_STAR: return GetHashNameNodeExport("__rm");
case TK_ARROW: return GetHashNameNodeExport("__rf");
case '(': return GetHashNameNodeExport("__cl");
case '[': return GetHashNameNodeExport("__vc");
default: return NULL;
}
}
HashNameNode *CMangler_VTableName(TypeClass *tclass) {
HashNameNode *name;
name_mangle_list.size = 0;
AppendGListName(&name_mangle_list, "__vt__");
CMangler_MangleClassName(tclass);
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
HashNameNode *CMangler_RTTIObjectName(Type *type, UInt32 qual) {
HashNameNode *name;
name_mangle_list.size = 0;
AppendGListName(&name_mangle_list, "__RTTI__");
CMangler_MangleTypeAppend(type, qual);
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
HashNameNode *CMangler_ThunkName(Object *obj, int a, int b, int c) {
HashNameNode *linkname;
HashNameNode *name;
char buf[64];
linkname = CMangler_GetLinkName(obj);
name_mangle_list.size = 0;
if (b == 0) {
if (c < 0)
sprintf(buf, "_@%ld@", -a);
else
sprintf(buf, "_@%ld@%ld@", -a, c);
} else {
sprintf(buf, "_@%ld@%ld@%ld@", -a, c, b);
}
AppendGListName(&name_mangle_list, buf);
AppendGListID(&name_mangle_list, linkname->name + 1);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
static void CMangler_CheckTemplateArguments(TemplArg *arg) {
ENode *expr;
while (arg) {
if (arg->pid.type == TPT_NONTYPE) {
expr = arg->data.paramdecl.expr;
#line 360
CError_ASSERT(expr);
if (expr->rtype->type != TYPETEMPLDEPEXPR) {
switch (expr->type) {
case EINTCONST:
break;
case EOBJREF:
CMangler_GetLinkName(expr->data.objref);
break;
default:
#line 383
CError_FATAL();
}
}
}
arg = arg->next;
}
}
static void CMangler_AppendTemplateArgumentList(TemplArg *arg) {
ENode *expr;
char buf[32];
AppendGListByte(&name_mangle_list, '<');
while (arg) {
if (arg->pid.type == TPT_NONTYPE) {
expr = arg->data.paramdecl.expr;
#line 409
CError_ASSERT(expr);
if (expr->rtype->type != TYPETEMPLDEPEXPR) {
switch (expr->type) {
case EINTCONST:
CInt64_PrintDec(buf, expr->data.intval);
AppendGListName(&name_mangle_list, buf);
break;
case EOBJREF:
AppendGListByte(&name_mangle_list, '&');
AppendGListName(&name_mangle_list, CMangler_GetLinkName(expr->data.objref)->name);
break;
default:
#line 452
CError_FATAL();
}
} else {
AppendGListByte(&name_mangle_list, 'T');
}
} else if (arg->pid.type == TPT_TYPE) {
CMangler_MangleTypeAppend(arg->data.typeparam.type, arg->data.typeparam.qual);
} else {
#line 467
CError_ASSERT(arg->pid.type == TPT_TEMPLATE);
CMangler_MangleTypeAppend(arg->data.ttargtype, 0);
}
if (arg->next)
AppendGListByte(&name_mangle_list, ',');
arg = arg->next;
}
AppendGListByte(&name_mangle_list, '>');
}
HashNameNode *CMangler_TemplateInstanceName(HashNameNode *basename, TemplArg *args) {
HashNameNode *name;
CMangler_CheckTemplateArguments(args);
name_mangle_list.size = 0;
AppendGListName(&name_mangle_list, basename->name);
CMangler_AppendTemplateArgumentList(args);
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
static void CMangler_MangleTypeName(char *str) {
char buf[16];
sprintf(buf, "%d", strlen(str));
AppendGListName(&name_mangle_list, buf);
AppendGListName(&name_mangle_list, str);
}
static void CMangler_MangleNameSpaceName(NameSpace *nspace, char *str) {
char *stack[10];
int stackp;
stack[0] = str;
stackp = 1;
while (nspace) {
if (nspace->name) {
stack[stackp++] = nspace->name->name;
if (stackp >= 9)
break;
}
nspace = nspace->parent;
}
if (stackp > 1) {
AppendGListByte(&name_mangle_list, 'Q');
AppendGListByte(&name_mangle_list, '0' + stackp);
}
while (--stackp >= 0)
CMangler_MangleTypeName(stack[stackp]);
}
static void CMangler_MangleClassName(TypeClass *tclass) {
if (!tclass->classname)
CMangler_MangleNameSpaceName(tclass->nspace->parent, "class");
else
CMangler_MangleNameSpaceName(tclass->nspace->parent, tclass->nspace->name->name);
}
static void CMangler_MangleQualifier(UInt32 qual) {
if (qual & Q_CONST)
AppendGListByte(&name_mangle_list, 'C');
if (qual & Q_VOLATILE)
AppendGListByte(&name_mangle_list, 'V');
}
static void CMangler_MangleTypeAppend(Type *type, UInt32 qual) {
char buf[16];
switch (type->type) {
case TYPEVOID:
CMangler_MangleQualifier(qual);
AppendGListByte(&name_mangle_list, 'v');
break;
case TYPEINT:
case TYPEFLOAT:
CMangler_MangleQualifier(qual);
switch (TYPE_INTEGRAL(type)->integral) {
case IT_BOOL:
AppendGListByte(&name_mangle_list, 'b');
return;
case IT_CHAR:
AppendGListByte(&name_mangle_list, 'c');
return;
case IT_WCHAR_T:
AppendGListByte(&name_mangle_list, 'w');
return;
case IT_UCHAR:
AppendGListName(&name_mangle_list, "Uc");
return;
case IT_SCHAR:
AppendGListName(&name_mangle_list, "Sc");
return;
case IT_SHORT:
AppendGListByte(&name_mangle_list, 's');
return;
case IT_USHORT:
AppendGListName(&name_mangle_list, "Us");
return;
case IT_INT:
AppendGListByte(&name_mangle_list, 'i');
return;
case IT_UINT:
AppendGListName(&name_mangle_list, "Ui");
return;
case IT_LONG:
AppendGListByte(&name_mangle_list, 'l');
return;
case IT_ULONG:
AppendGListName(&name_mangle_list, "Ul");
return;
case IT_LONGLONG:
AppendGListByte(&name_mangle_list, 'x');
return;
case IT_ULONGLONG:
AppendGListName(&name_mangle_list, "Ux");
return;
case IT_FLOAT:
AppendGListByte(&name_mangle_list, 'f');
return;
case IT_SHORTDOUBLE:
AppendGListByte(&name_mangle_list, 'D');
return;
case IT_DOUBLE:
AppendGListByte(&name_mangle_list, 'd');
return;
case IT_LONGDOUBLE:
AppendGListByte(&name_mangle_list, 'r');
return;
default:
#line 619
CError_FATAL();
}
case TYPEENUM:
CMangler_MangleQualifier(qual);
if (!TYPE_ENUM(type)->enumname)
CMangler_MangleNameSpaceName(TYPE_ENUM(type)->nspace, "enum");
else
CMangler_MangleNameSpaceName(TYPE_ENUM(type)->nspace, TYPE_ENUM(type)->enumname->name);
break;
case TYPEPOINTER:
CMangler_MangleQualifier(TYPE_POINTER(type)->qual);
if (TYPE_POINTER(type)->qual & Q_REFERENCE)
AppendGListByte(&name_mangle_list, 'R');
else
AppendGListByte(&name_mangle_list, 'P');
CMangler_MangleTypeAppend(TYPE_POINTER(type)->target, qual);
break;
case TYPEMEMBERPOINTER:
if (TYPE_MEMBER_POINTER(type)->ty2->type != TYPECLASS) {
AppendGListName(&name_mangle_list, "3<T>");
} else {
CMangler_MangleQualifier(TYPE_MEMBER_POINTER(type)->qual);
AppendGListByte(&name_mangle_list, 'M');
CMangler_MangleClassName(TYPE_CLASS(TYPE_MEMBER_POINTER(type)->ty2));
CMangler_MangleTypeAppend(TYPE_MEMBER_POINTER(type)->ty1, qual);
}
break;
case TYPEARRAY:
AppendGListByte(&name_mangle_list, 'A');
if (TYPE_POINTER(type)->target->size) {
sprintf(buf, "%ld", type->size / TYPE_POINTER(type)->target->size);
AppendGListName(&name_mangle_list, buf);
} else {
AppendGListByte(&name_mangle_list, '0');
}
AppendGListByte(&name_mangle_list, '_');
CMangler_MangleTypeAppend(TYPE_POINTER(type)->target, qual);
break;
case TYPEFUNC:
CMangler_MangleQualifier(qual);
AppendGListByte(&name_mangle_list, 'F');
CMangler_MangleArgs(TYPE_FUNC(type)->args);
AppendGListByte(&name_mangle_list, '_');
CMangler_MangleTypeAppend(TYPE_FUNC(type)->functype, TYPE_FUNC(type)->qual);
break;
case TYPESTRUCT:
CMangler_MangleQualifier(qual);
switch (TYPE_STRUCT(type)->stype) {
case STRUCT_TYPE_4:
AppendGListName(&name_mangle_list, "XUc");
return;
case STRUCT_TYPE_5:
AppendGListName(&name_mangle_list, "Xc");
return;
case STRUCT_TYPE_6:
AppendGListName(&name_mangle_list, "XC");
return;
case STRUCT_TYPE_7:
AppendGListName(&name_mangle_list, "XUs");
return;
case STRUCT_TYPE_8:
AppendGListName(&name_mangle_list, "Xs");
return;
case STRUCT_TYPE_9:
AppendGListName(&name_mangle_list, "XS");
return;
case STRUCT_TYPE_A:
AppendGListName(&name_mangle_list, "XUi");
return;
case STRUCT_TYPE_B:
AppendGListName(&name_mangle_list, "Xi");
return;
case STRUCT_TYPE_C:
AppendGListName(&name_mangle_list, "XI");
return;
case STRUCT_TYPE_D:
AppendGListName(&name_mangle_list, "Xf");
return;
case STRUCT_TYPE_E:
AppendGListName(&name_mangle_list, "Xp");
return;
}
if (TYPE_STRUCT(type)->name && !IsTempName(TYPE_STRUCT(type)->name)) {
CMangler_MangleTypeName(TYPE_STRUCT(type)->name->name);
return;
}
switch (TYPE_STRUCT(type)->stype) {
case STRUCT_TYPE_STRUCT:
AppendGListName(&name_mangle_list, "struct");
break;
case STRUCT_TYPE_UNION:
AppendGListName(&name_mangle_list, "union");
break;
case STRUCT_TYPE_CLASS:
AppendGListName(&name_mangle_list, "class");
break;
default:
#line 701
CError_FATAL();
}
break;
case TYPECLASS:
CMangler_MangleQualifier(qual);
CMangler_MangleClassName(TYPE_CLASS(type));
break;
case TYPETEMPLATE:
AppendGListName(&name_mangle_list, "1T");
break;
default:
#line 716
CError_FATAL();
}
}
void CMangler_MangleType(Type *type, UInt32 qual) {
name_mangle_list.size = 0;
CMangler_MangleTypeAppend(type, qual);
}
static void CMangler_MangleArgs(FuncArg *args) {
TypePointer ptr;
if (args) {
if (args->type) {
while (args) {
if (args != &elipsis && args != &oldstyle) {
if (args->type->type == TYPEPOINTER) {
ptr = *TYPE_POINTER(args->type);
ptr.qual &= ~(Q_CONST | Q_VOLATILE);
CMangler_MangleTypeAppend((Type *) &ptr, args->qual);
} else {
CMangler_MangleTypeAppend(args->type, 0);
}
} else {
AppendGListByte(&name_mangle_list, 'e');
}
args = args->next;
}
} else {
AppendGListByte(&name_mangle_list, 'e');
}
} else {
AppendGListByte(&name_mangle_list, 'v');
}
}
static void CMangler_MangleFunction(Object *obj, NameSpace *nspace) {
TypeFunc *tfunc = TYPE_FUNC(obj->type);
FuncArg *arg = tfunc->args;
AppendGListName(&name_mangle_list, obj->name->name);
if (obj->u.func.inst) {
if (tfunc->flags & FUNC_FLAGS_40)
CMangler_MangleTypeAppend(tfunc->functype, tfunc->qual);
CMangler_AppendTemplateArgumentList(obj->u.func.inst->args);
}
AppendGListName(&name_mangle_list, "__");
while (nspace && nspace->name == NULL)
nspace = nspace->parent;
if (nspace) {
CMangler_MangleNameSpaceName(nspace->parent, nspace->name->name);
if (nspace->theclass) {
if (obj->name == destructor_name_node) {
AppendGListName(&name_mangle_list, "Fv");
return;
}
if (arg) {
if (obj->name == constructor_name_node) {
arg = arg->next;
if (arg && (nspace->theclass->flags & CLASS_FLAGS_20))
arg = arg->next;
} else {
if ((tfunc->flags & FUNC_FLAGS_METHOD) && !TYPE_METHOD(tfunc)->x26) {
CMangler_MangleQualifier(arg->qual);
arg = arg->next;
}
}
}
}
}
AppendGListByte(&name_mangle_list, 'F');
CMangler_MangleArgs(arg);
if (obj->u.func.inst && copts.new_mangler) {
AppendGListByte(&name_mangle_list, '_');
CMangler_MangleTypeAppend(tfunc->functype, tfunc->qual);
}
}
HashNameNode *CMangler_ConversionFuncName(Type *type, UInt32 qual) {
HashNameNode *name;
if (CTemplTool_IsTemplateArgumentDependentType(type))
return GetHashNameNodeExport("__op");
name_mangle_list.size = 0;
AppendGListName(&name_mangle_list, "__op");
CMangler_MangleTypeAppend(type, qual);
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
static HashNameNode *CMangler_MangleNameToUpper(char *str) {
HashNameNode *name;
name_mangle_list.size = 0;
while (*str) {
AppendGListByte(&name_mangle_list, toupper(*(str++)));
}
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
static HashNameNode *CMangler_FunctionLinkName(Object *obj) {
HashNameNode *name;
NameSpace *nspace;
if (obj->u.func.inst)
CMangler_CheckTemplateArguments(obj->u.func.inst->args);
for (nspace = obj->nspace; nspace; nspace = nspace->parent) {
if (nspace->name)
break;
}
name_mangle_list.size = 0;
if (is_pascal_object(obj) && (!nspace || !nspace->theclass)) {
AppendGListData(&name_mangle_list, "_", 1);
AppendGListID(&name_mangle_list, obj->name->name);
} else if ((obj->qual & Q_80000) && (strcmp("main", obj->name->name) || (obj->nspace != cscope_root))) {
AppendGListData(&name_mangle_list, "_", 1);
CMangler_MangleFunction(obj, nspace);
AppendGListByte(&name_mangle_list, 0);
} else {
AppendGListData(&name_mangle_list, "_", 1);
AppendGListID(&name_mangle_list, obj->name->name);
}
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
HashNameNode *CMangler_GetCovariantFunctionName(Object *obj, Type *type) {
HashNameNode *linkname;
HashNameNode *name;
linkname = CMangler_GetLinkName(obj);
name_mangle_list.size = 0;
AppendGListName(&name_mangle_list, linkname->name);
AppendGListName(&name_mangle_list, "@@");
CMangler_MangleTypeAppend(type, 0);
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
static HashNameNode *CMangler_DataLinkName(Object *obj) {
NameSpace *nspace;
HashNameNode *name;
nspace = obj->nspace;
while (nspace && nspace->name == NULL)
nspace = nspace->parent;
name_mangle_list.size = 0;
AppendGListData(&name_mangle_list, "_", 1);
AppendGListName(&name_mangle_list, obj->name->name);
while (nspace && nspace->name == NULL)
nspace = nspace->parent;
if (nspace && (obj->qual & Q_80000)) {
AppendGListName(&name_mangle_list, "__");
CMangler_MangleNameSpaceName(nspace->parent, nspace->name->name);
}
AppendGListByte(&name_mangle_list, 0);
COS_LockHandle(name_mangle_list.data);
name = GetHashNameNodeExport(*name_mangle_list.data);
COS_UnlockHandle(name_mangle_list.data);
return name;
}
HashNameNode *CMangler_GetLinkName(Object *obj) {
while (obj->datatype == DALIAS)
obj = obj->u.alias.object;
switch (obj->datatype) {
case DFUNC:
case DVFUNC:
if (!obj->u.func.linkname)
obj->u.func.linkname = CMangler_FunctionLinkName(obj);
return obj->u.func.linkname;
case DDATA:
if (!obj->u.data.linkname)
obj->u.data.linkname = CMangler_DataLinkName(obj);
return obj->u.data.linkname;
case DINLINEFUNC:
return CMangler_FunctionLinkName(obj);
case DLOCAL:
case DABSOLUTE:
case DLABEL:
return obj->name;
case DNONLAZYPTR:
if (!obj->u.toc.linkname)
obj->u.toc.linkname = CMangler_DataLinkName(obj);
return obj->u.toc.linkname;
default:
#line 1110
CError_FATAL();
return NULL;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,697 @@
#include "compiler.h"
#include "compiler/CError.h"
#include "compiler/PCode.h"
#include "compiler/PCodeInfo.h"
#include "compiler/PCodeUtilities.h"
#include "compiler/enode.h"
#include "compiler/objects.h"
#include "compiler/tokens.h"
#include "compiler/types.h"
static Macro powcM;
static Macro __powcM;
static Macro ppc_cpu;
static Macro profM;
static Macro hostM;
static Macro bendM;
static Macro _ppc_M;
static Macro longI;
static Macro IEEED;
Macro vecM;
Macro altivecM;
static Macro macM2;
static Macro appleM;
static Macro optM;
static Macro alignM;
static Macro _machM;
static Macro archM;
static Macro dynM;
static Macro ppcM;
Object *gFunction;
static ObjectList *temps;
PCodeLabel *returnlabel;
PCodeLabel *cleanreturnlabel;
Boolean needs_cleanup;
Statement *current_statement;
int has_catch_blocks;
int disable_optimizer;
SInt32 current_linenumber;
Boolean has_altivec_arrays;
short high_reg;
short low_reg;
short high_offset;
short low_offset;
short low_reg2;
short high_reg2;
PCodeLabel *pic_base_pcodelabel;
Object *dyld_stub_binding_helper;
Object *rt_cvt_fp2unsigned;
Object *rt_profile_entry;
Object *rt_profile_exit;
Object *rt_div2i;
Object *rt_div2u;
Object *rt_mod2i;
Object *rt_mod2u;
Object *rt_shr2i;
Object *rt_shr2u;
Object *rt_shl2i;
Object *rt_cvt_ull_dbl;
Object *rt_cvt_sll_dbl;
Object *rt_cvt_ull_flt;
Object *rt_cvt_sll_flt;
Object *rt_cvt_dbl_usll;
static void *saveheaperror;
enum {
GPRLimit = 10,
FPRLimit = 13,
VRLimit = 13
};
VarInfo *CodeGen_GetNewVarInfo(void) {
VarInfo *vi;
vi = lalloc(sizeof(VarInfo));
memclrw(vi, sizeof(VarInfo));
vi->deftoken = *CPrep_CurStreamElement();
vi->varnumber = localcount++;
return vi;
}
Object *maketemporary(Type *type) {
ObjectList *list;
Object *obj;
for (list = temps; list; list = list->next) {
obj = list->object;
if (obj->u.var.uid == 0 && obj->type == type) {
obj->u.var.uid = 1;
return obj;
}
}
obj = lalloc(sizeof(Object));
memclrw(obj, sizeof(Object));
obj->otype = OT_OBJECT;
obj->access = ACCESSPUBLIC;
obj->datatype = DLOCAL;
obj->type = type;
obj->name = CParser_GetUniqueName();
obj->u.var.info = CodeGen_GetNewVarInfo();
obj->u.var.uid = 1;
list = lalloc(sizeof(ObjectList));
memclrw(list, sizeof(ObjectList));
list->next = temps;
list->object = obj;
temps = list;
return obj;
}
static void free_temporaries(void) {
ObjectList *list;
for (list = temps; list; list = list->next)
list->object->u.var.uid = 0;
}
static void allocate_temporaries(void) {
ObjectList *list;
for (list = temps; list; list = list->next)
assign_local_memory(list->object);
}
void process_arguments(ArgumentProcessor func, Boolean flag) {
short gpr = 3;
short fpr = 1;
short vr = 2;
Type *type;
ObjectList *list;
for (list = arguments; list; list = list->next) {
type = list->object->type;
if (IS_TYPE_FLOAT(type)) {
func(list->object, (fpr <= FPRLimit) ? fpr : 0);
fpr++;
if (type->size == 4)
gpr++;
else
gpr += 2;
} else if (IS_TYPE_VECTOR(type)) {
func(list->object, (vr <= VRLimit) ? vr : 0);
vr++;
if (flag) {
if ((vr - 1) == 2)
gpr = 9;
else if ((vr - 1) > 2)
gpr = 11;
}
} else {
func(list->object, (gpr <= GPRLimit) ? gpr : 0);
if (TYPE_FITS_IN_REGISTER(type)) {
if (type->size <= 4)
gpr += 1;
else
gpr += 2;
} else {
gpr += (type->size >> 2);
if (type->size & 3)
gpr++;
}
}
}
last_argument_register[RegClass_GPR] = gpr - 1;
last_argument_register[RegClass_FPR] = fpr - 1;
last_argument_register[RegClass_VR] = vr - 1;
if (flag)
move_varargs_to_memory();
}
static void retain_argument_register(Object *obj, short reg) {
VarInfo *vi = Registers_GetVarInfo(obj);
Type *type = obj->type;
if (reg && !vi->noregister && vi->used) {
if (TYPE_FITS_IN_REGISTER(type)) {
if (type->size <= 4) {
retain_register(obj, RegClass_GPR, reg);
} else if (reg < GPRLimit) {
if (copts.little_endian)
retain_GPR_pair(obj, reg, reg + 1);
else
retain_GPR_pair(obj, reg + 1, reg);
}
} else if (IS_TYPE_FLOAT(type)) {
retain_register(obj, RegClass_FPR, reg);
} else if (IS_TYPE_VECTOR(type)) {
retain_register(obj, RegClass_VR, reg);
}
}
}
static void allocate_local_vregs(void) {
VarInfo *vi;
ObjectList *list;
Object *obj;
if (copts.codegen_pic && uses_globals && assignable_registers[RegClass_GPR]) {
if (assignable_registers[RegClass_GPR]) {
vi = pic_base.u.var.info;
vi->reg = 0;
assign_register_by_type(&pic_base);
pic_base_reg = vi->reg;
#line 497
CError_ASSERT(pic_base_reg);
} else {
#line 500
CError_FATAL();
}
} else {
pic_base_reg = 0;
}
for (list = exceptionlist; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && !vi->reg)
assign_register_by_type(obj);
}
}
set_last_exception_registers();
for (list = arguments; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && !vi->reg)
assign_register_by_type(obj);
}
}
for (list = locals; list; list = list->next) {
obj = list->object;
if (!IsTempName(obj->name)) {
vi = Registers_GetVarInfo(obj);
if (vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && !vi->reg)
assign_register_by_type(obj);
}
}
}
open_fe_temp_registers();
for (list = locals; list; list = list->next) {
obj = list->object;
if (IsTempName(obj->name)) {
vi = Registers_GetVarInfo(obj);
if (vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && !vi->reg)
assign_register_by_type(obj);
}
}
}
for (list = toclist; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (!vi->reg && vi->used && vi->usage > 1)
assign_register_by_type(obj);
}
}
static void allocate_local_GPRs(void) {
ObjectList *list;
Object *obj;
Object *winning_obj;
SInt32 winning_usage;
VarInfo *vi;
Type *type;
if (copts.codegen_pic && uses_globals && assignable_registers[RegClass_GPR]) {
vi = pic_base.u.var.info;
vi->reg = 0;
assign_register_by_type(&pic_base);
pic_base_reg = vi->reg;
#line 605
CError_ASSERT(pic_base_reg);
} else {
pic_base_reg = 0;
}
while (assignable_registers[RegClass_GPR]) {
winning_obj = NULL;
winning_usage = -1;
if (!(disable_optimizer & 2)) {
for (list = arguments; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
type = obj->type;
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (TYPE_FITS_IN_REGISTER(type) && (!TYPE_IS_8BYTES(type) || assignable_registers[RegClass_GPR] >= 2)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
if (!(disable_optimizer & 2)) {
for (list = locals; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
type = obj->type;
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (TYPE_FITS_IN_REGISTER(type) && (!TYPE_IS_8BYTES(type) || assignable_registers[RegClass_GPR] >= 2)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
for (list = toclist; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used) {
if (vi->usage >= winning_usage && vi->usage >= 3) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
if (!winning_obj)
break;
assign_register_by_type(winning_obj);
#line 698
CError_ASSERT(Registers_GetVarInfo(winning_obj)->flags & VarInfoFlag2);
}
}
static void allocate_local_FPRs(void) {
ObjectList *list;
Object *obj;
Object *winning_obj;
SInt32 winning_usage;
VarInfo *vi;
Type *type;
while (assignable_registers[RegClass_FPR]) {
winning_obj = NULL;
winning_usage = -1;
if (!(disable_optimizer & 2)) {
for (list = arguments; list; list = list->next) {
obj = list->object;
type = obj->type;
vi = Registers_GetVarInfo(obj);
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (IS_TYPE_FLOAT(type)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
if (!(disable_optimizer & 2)) {
for (list = locals; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (IS_TYPE_FLOAT(obj->type)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
if (!winning_obj)
break;
assign_register_by_type(winning_obj);
#line 782
CError_ASSERT(Registers_GetVarInfo(winning_obj)->flags & VarInfoFlag2);
}
}
static void allocate_local_VRs(void) {
ObjectList *list;
Object *obj;
Object *winning_obj;
SInt32 winning_usage;
VarInfo *vi;
while (assignable_registers[RegClass_VR]) {
winning_obj = NULL;
winning_usage = -1;
if (!(disable_optimizer & 2)) {
for (list = arguments; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (IS_TYPE_VECTOR(obj->type)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
if (!(disable_optimizer & 2)) {
for (list = locals; list; list = list->next) {
obj = list->object;
vi = Registers_GetVarInfo(obj);
if (vi->flags & VarInfoFlag40)
vi->usage = 100000;
if (!vi->reg && vi->used && !vi->noregister) {
if (!OBJ_GET_TARGET_VOLATILE(obj) && vi->usage >= winning_usage && vi->usage >= 2) {
if (IS_TYPE_VECTOR(obj->type)) {
winning_obj = obj;
winning_usage = vi->usage;
}
}
}
}
}
if (!winning_obj)
break;
assign_register_by_type(winning_obj);
#line 846
CError_ASSERT(Registers_GetVarInfo(winning_obj)->flags & VarInfoFlag2);
}
}
static void allocate_locals(void) {
has_altivec_arrays = 0;
if (!requires_frame && !optimizing)
process_arguments(retain_argument_register, 0);
if (optimizing) {
allocate_local_vregs();
} else {
allocate_local_GPRs();
allocate_local_FPRs();
allocate_local_VRs();
}
assign_locals_to_memory(locals);
}
void move_assigned_argument(Object *obj, short reg) {
VarInfo *vi;
Type *type;
SInt32 bytesLeft;
SInt32 offset;
vi = Registers_GetVarInfo(obj);
type = obj->type;
#line 901
CError_ASSERT(obj->datatype == DLOCAL);
if (!vi->used)
return;
if (reg) {
if (vi->reg) {
if (TYPE_IS_8BYTES(type)) {
if (copts.little_endian) {
if (vi->reg != reg)
emitpcode(PC_MR, vi->reg, reg);
if (reg < GPRLimit) {
#line 916
CError_FAIL((vi->regHi == reg) || (vi->reg == (reg + 1)));
if (vi->regHi != (reg + 1))
emitpcode(PC_MR, vi->regHi, reg + 1);
} else {
load_store_register(PC_LWZ, vi->regHi, local_base_register(obj), obj, high_offset);
}
} else {
if (vi->regHi != reg)
emitpcode(PC_MR, vi->regHi, reg);
if (reg < GPRLimit) {
#line 931
CError_FAIL((vi->reg == reg) || (vi->regHi == (reg + 1)));
if (vi->reg != (reg + 1))
emitpcode(PC_MR, vi->reg, reg + 1);
} else {
load_store_register(PC_LWZ, vi->reg, local_base_register(obj), obj, low_offset);
}
}
} else if (vi->reg != reg) {
if (IS_TYPE_FLOAT(type)) {
emitpcode(PC_FMR, vi->reg, reg);
} else if (IS_TYPE_VECTOR(type)) {
emitpcode(PC_VMR, vi->reg, reg);
} else {
emitpcode(PC_MR, vi->reg, reg);
}
}
} else {
if (IS_TYPE_POINTER(type) || IS_TYPE_4BYTES_MEMBERPOINTER(type)) {
load_store_register(PC_STW, reg, local_base_register(obj), obj, 0);
} else if (IS_TYPE_INT(type) || IS_TYPE_ENUM(type)) {
switch (type->size) {
case 1:
load_store_register(PC_STB, reg, local_base_register(obj), obj, 0);
break;
case 2:
load_store_register(PC_STH, reg, local_base_register(obj), obj, 0);
break;
case 4:
load_store_register(PC_STW, reg, local_base_register(obj), obj, 0);
break;
case 8:
load_store_register(PC_STW, reg, local_base_register(obj), obj, 0);
if (reg < GPRLimit)
load_store_register(PC_STW, reg + 1, local_base_register(obj), obj, 4);
break;
default:
#line 993
CError_FATAL();
}
} else if (IS_TYPE_FLOAT(type)) {
load_store_register((type->size == 4) ? PC_STFS : PC_STFD, reg, local_base_register(obj), obj, 0);
} else if (IS_TYPE_VECTOR(type)) {
load_store_register(PC_STVX, reg, local_base_register(obj), obj, 0);
} else {
bytesLeft = (11 - reg) * 4;
if (bytesLeft > obj->type->size)
bytesLeft = obj->type->size;
offset = 0;
while (bytesLeft > 0) {
load_store_register(PC_STW, reg, local_base_register(obj), obj, offset);
reg++;
offset += 4;
bytesLeft -= 4;
}
}
}
} else {
if (vi->reg) {
if (IS_TYPE_POINTER(type) || IS_TYPE_4BYTES_MEMBERPOINTER(type)) {
load_store_register(PC_LWZ, vi->reg, local_base_register(obj), obj, 0);
} else if (IS_TYPE_FLOAT(type)) {
load_store_register((type->size == 4) ? PC_LFS : PC_LFD, vi->reg, local_base_register(obj), obj, 0);
} else if (IS_TYPE_VECTOR(type)) {
load_store_register(PC_LVX, vi->reg, local_base_register(obj), obj, 0);
} else {
switch (type->size) {
case 1:
load_store_register(PC_LBZ, vi->reg, local_base_register(obj), obj, 0);
break;
case 2:
load_store_register(is_unsigned(type) ? PC_LHZ : PC_LHA, vi->reg, local_base_register(obj), obj, 0);
break;
case 4:
load_store_register(PC_LWZ, vi->reg, local_base_register(obj), obj, 0);
break;
case 8:
load_store_register(PC_LWZ, vi->regHi, local_base_register(obj), obj, high_offset);
load_store_register(PC_LWZ, vi->reg, local_base_register(obj), obj, low_offset);
break;
default:
#line 1095
CError_FATAL();
}
}
} else if (!optimizing) {
local_base_register(obj);
}
}
}
static void load_TOC_pointers(void) {
VarInfo *vi;
Object *obj;
ObjectList *list;
PCode *pc;
if (uses_globals && pic_base_reg) {
pic_base_pcodelabel = makepclabel();
pc = makepcode(PC_BC, 20, 7, 3);
pcsetlinkbit(pc);
pcsetsideeffects(pc);
appendpcode(pclastblock, pc);
pcbranch(pclastblock, pic_base_pcodelabel);
makepcblock();
pclabel(pclastblock, pic_base_pcodelabel);
emitpcode(PC_MFLR, pic_base_reg);
}
// TODO: depends on Operands
for (list = toclist; list; list = list->next) {
}
}
static Boolean has_vararglist(Object *funcobj) {
FuncArg *arg;
arg = TYPE_FUNC(funcobj->type)->args;
while (arg && arg != &elipsis)
arg = arg->next;
return arg == &elipsis;
}
void assign_labels() {
// TODO
}
static Boolean islaststatement(Statement *stmt) {
for (stmt = stmt->next; stmt; stmt = stmt->next) {
if (stmt->type > ST_LABEL)
return 0;
}
return 1;
}
static void newstatement(SInt32 sourceoffset, UInt16 value, int flag) {
PCodeBlock *block = pclastblock;
pcloopweight = value;
if (!block->pcodeCount)
block->loopWeight = value;
if (block->pcodeCount > 100)
branch_label(makepclabel());
if (flag)
block->flags |= fPCBlockFlag4000;
}
static void expressionstatement(ENode *expr) {
}
static void labelstatement() {}
static void gotostatement() {}
static void gotoexpression() {}
static void conditionalstatement() {}
static void returnstatement() {}
static void capturestackpointer() {}
static void resetstackpointer() {}
static void callprofiler() {}
static void exitprofiler() {}
void CodeGen_Generator() {}
void CodeGen_GenVDispatchThunk() {}
void CodeGen_SetupRuntimeObjects() {}
Boolean CodeGen_ReInitRuntimeObjects(Boolean is_precompiler) {}
Boolean CodeGen_IsPublicRuntimeObject(Object *obj) {}
void CodeGen_SOMStub() {}
void CodeGen_ParseDeclSpec() {}
static void CodeGen_EOLCheck() {}
static void schedule_for() {}
static void pragma_scheduling() {}
static void CodeGen_ParseLongIntegerORonORoff() {}
void CodeGen_ParsePragma(HashNameNode *name) {}
void CodeGen_UpdateObject(Object *object) {}
void CodeGen_UpdateBackEndOptions() {}
void CodeGen_objc_method_self_offset() {}
void CodeGen_objc_method_sel_offset() {}
void CodeGen_objc_method_arg_offset() {}
void CodeGen_objc_method_args_size() {}
void CodeGen_HandleIntrinsicCall() {}
void CodeGen_HandleTypeCast() {}
void CodeGen_AssignCheck() {}
void CodeGen_CollapseVectorExpression() {}
void CodeGen_InsertSpecialMacros() {}
char *CodeGen_ExpandSpecialMacro(Macro *macro) {}
void CodeGen_reportheapinfo() {}
static void CodeGen_heaperror() {}
void CodeGen_InitialSanityCheck() {}

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,13 @@
#include "CompilerTools.h"
#include "PCode.h"
#include "compiler.h"
#include "compiler/CompilerTools.h"
#include "compiler/PCode.h"
#include "compiler/PCodeInfo.h"
// TODO RESOLVE ME
extern void initialize_aliases();
extern void *current_statement;
extern PCode *vformatpcode(short op, va_list args);
PCBlock *pcbasicblocks;
PCBlock *pclastblock;
PCodeBlock *pcbasicblocks;
PCodeBlock *pclastblock;
void *prologue;
void *epilogue;
PCBlock **depthfirstordering;
PCodeBlock **depthfirstordering;
int pcblockcount;
int pcloopweight;
static unsigned short pclabelcount;
@ -30,7 +27,7 @@ PCode *makepcode(short op, ...) {
va_start(list, op);
pcode = vformatpcode(op, list);
// TODO
pcode->sourceoffset = current_statement ? current_statement->sourceoffset : -1;
return pcode;
}
@ -40,34 +37,50 @@ void emitpcode(short op, ...) {
va_start(list, op);
pcode = vformatpcode(op, list);
// TODO
pcode->sourceoffset = current_statement ? current_statement->sourceoffset : -1;
appendpcode(pclastblock, pcode);
}
PCode *copypcode(PCode *pcode) {
PCode *newpc;
int flag;
int extra_arg;
int i;
flag = 0;
// TODO
extra_arg = 0;
if ((PCODE_FLAG_SET_F(pcode) & fPCodeFlag8000000) && !(PCODE_FLAG_SET_F(pcode) & fPCodeFlag20000000))
extra_arg = 1;
newpc = lalloc(sizeof(PCode) + sizeof(PCodeArg) * (pcode->argCount + extra_arg));
memclrw(newpc, sizeof(PCode) + sizeof(PCodeArg) * (pcode->argCount + extra_arg));
newpc->op = pcode->op;
newpc->flags = pcode->flags;
newpc->argCount = pcode->argCount;
newpc->_18 = pcode->_18;
for (i = 0; i < pcode->argCount; i++) {
newpc->args[i] = pcode->args[i];
}
if (extra_arg)
newpc->args[pcode->argCount].kind = PCOp_PLACEHOLDEROPERAND;
return newpc;
}
PCLabel *makepclabel() {
PCLabel *label;
PCodeLabel *makepclabel() {
PCodeLabel *label;
label = (PCLabel *) lalloc(sizeof(PCLabel));
memclrw(label, sizeof(PCLabel));
label = (PCodeLabel *) lalloc(sizeof(PCodeLabel));
memclrw(label, sizeof(PCodeLabel));
label->index = pclabelcount++;
return label;
}
PCBlock *makepcblock() {
PCBlock *block;
PCodeBlock *makepcblock() {
PCodeBlock *block;
block = (PCBlock *) lalloc(sizeof(PCBlock));
memclrw(block, sizeof(PCBlock));
block = (PCodeBlock *) lalloc(sizeof(PCodeBlock));
memclrw(block, sizeof(PCodeBlock));
block->loopWeight = pcloopweight;
block->blockIndex = pcblockcount++;
if (pclastblock) {
@ -80,7 +93,7 @@ PCBlock *makepcblock() {
return block;
}
void pclabel(PCBlock *block, PCLabel *label) {
void pclabel(PCodeBlock *block, PCodeLabel *label) {
PCLink *iter;
PCLink *next;
@ -97,7 +110,7 @@ void pclabel(PCBlock *block, PCLabel *label) {
block->labels = label;
}
void pcbranch(PCBlock *block, PCLabel *label) {
void pcbranch(PCodeBlock *block, PCodeLabel *label) {
PCLink *link;
link = (PCLink *) lalloc(sizeof(PCLink));
@ -105,13 +118,13 @@ void pcbranch(PCBlock *block, PCLabel *label) {
link->block = label->block;
if (!label->resolved)
label->block = (PCBlock *) link;
label->block = (PCodeBlock *) link;
link->nextLink = block->successors;
block->successors = link;
}
void pccomputepredecessors() {
PCBlock *block;
PCodeBlock *block;
PCLink *succ;
PCLink *pred;
@ -127,7 +140,7 @@ void pccomputepredecessors() {
}
}
void deleteblock(PCBlock *block) {
void deleteblock(PCodeBlock *block) {
block->prevBlock->nextBlock = block->nextBlock;
if (block->nextBlock)
block->nextBlock->prevBlock = block->prevBlock;
@ -135,7 +148,7 @@ void deleteblock(PCBlock *block) {
}
void deleteunreachableblocks() {
PCBlock *block;
PCodeBlock *block;
computedepthfirstordering();
@ -145,7 +158,7 @@ void deleteunreachableblocks() {
}
}
void appendpcode(PCBlock *block, PCode *pcode) {
void appendpcode(PCodeBlock *block, PCode *pcode) {
if (block->firstPCode) {
pcode->nextPCode = 0;
pcode->prevPCode = block->lastPCode;
@ -162,7 +175,7 @@ void appendpcode(PCBlock *block, PCode *pcode) {
}
void deletepcode(PCode *pcode) {
PCBlock *block;
PCodeBlock *block;
block = pcode->block;
if (pcode->prevPCode)
@ -180,7 +193,7 @@ void deletepcode(PCode *pcode) {
}
void insertpcodebefore(PCode *anchor, PCode *newpcode) {
PCBlock *block;
PCodeBlock *block;
block = anchor->block;
if (anchor->prevPCode)
@ -190,7 +203,7 @@ void insertpcodebefore(PCode *anchor, PCode *newpcode) {
newpcode->nextPCode = anchor;
newpcode->prevPCode = anchor->prevPCode;
anchor->prevPCode = newpcode;
newpcode->_1C = anchor->_1C;
newpcode->sourceoffset = anchor->sourceoffset;
newpcode->block = block;
block->pcodeCount++;
@ -198,7 +211,7 @@ void insertpcodebefore(PCode *anchor, PCode *newpcode) {
}
void insertpcodeafter(PCode *anchor, PCode *newpcode) {
PCBlock *block;
PCodeBlock *block;
block = anchor->block;
if (anchor->nextPCode)
@ -208,7 +221,7 @@ void insertpcodeafter(PCode *anchor, PCode *newpcode) {
newpcode->prevPCode = anchor;
newpcode->nextPCode = anchor->nextPCode;
anchor->nextPCode = newpcode;
newpcode->_1C = anchor->_1C;
newpcode->sourceoffset = anchor->sourceoffset;
newpcode->block = block;
block->pcodeCount++;
@ -227,7 +240,7 @@ void clearpcodeflags(int flags) {
int pccomputeoffsets() {
int offset;
PCBlock *block;
PCodeBlock *block;
offset = 0;
for (block = pcbasicblocks; block; block = block->nextBlock) {
@ -239,20 +252,20 @@ int pccomputeoffsets() {
}
typedef struct _DFO {
PCBlock *block;
PCodeBlock *block;
PCLink *link;
} DFO;
static int depthfirstorder;
void computedepthfirstordering() {
PCBlock *block;
PCodeBlock *block;
PCLink *link;
DFO *dfo;
int index;
depthfirstordering = (PCBlock **) lalloc(sizeof(PCBlock *) * pcblockcount);
memclrw(depthfirstordering, sizeof(PCBlock *) * pcblockcount);
depthfirstordering = (PCodeBlock **) lalloc(sizeof(PCodeBlock *) * pcblockcount);
memclrw(depthfirstordering, sizeof(PCodeBlock *) * pcblockcount);
depthfirstorder = pcblockcount;
for (block = pcbasicblocks; block; block = block->nextBlock) {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,348 @@
#include "compiler/PCodeUtilities.h"
#include "compiler/PCode.h"
#include "compiler/PCodeInfo.h"
#include "compiler/CError.h"
#include "compiler/enode.h"
#include "compiler/objects.h"
#include "compiler.h"
void pcsetrecordbit(PCode *pc) {
int reg;
PCodeArg *arg;
short argCount;
int argIdx;
pc->flags &= ~(fPCodeFlag10 | fCommutative | fIsCSE);
if ((pc->flags & (fPCodeFlag80000000 | fPCodeFlag40000000)) == fPCodeFlag40000000) {
reg = 1;
} else if ((pc->flags & (fPCodeFlag80000000 | fPCodeFlag40000000)) == (fPCodeFlag80000000 | fPCodeFlag40000000)) {
reg = 6;
} else {
reg = 0;
}
if (pc->op == PC_ANDI || pc->op == PC_ANDIS) {
pc->flags |= fPCodeFlag20000000;
} else if (pc->op == PC_ADDI || pc->op == PC_ADDIC) {
pc->flags |= fPCodeFlag10000000;
pc->flags |= fPCodeFlag20000000;
change_num_operands(pc, 5);
pc->op = PC_ADDICR;
#line 76
CError_ASSERT(pc->args[3].kind == PCOp_PLACEHOLDEROPERAND);
pc->args[3].kind = PCOp_REGISTER;
pc->args[3].arg = RegClass_SPR;
pc->args[3].data.reg.reg = 0;
pc->args[3].data.reg.effect = EffectWrite;
#line 80
CError_ASSERT(pc->args[4].kind == PCOp_PLACEHOLDEROPERAND);
pc->args[4].kind = PCOp_REGISTER;
pc->args[4].arg = RegClass_CRFIELD;
pc->args[4].data.reg.reg = reg;
pc->args[4].data.reg.effect = EffectWrite;
} else {
arg = pc->args;
argIdx = argCount = pc->argCount;
while (arg->kind != PCOp_PLACEHOLDEROPERAND && argIdx) {
if (arg->kind == PCOp_REGISTER && arg->arg == RegClass_CRFIELD && arg->data.reg.reg == reg) {
arg->data.reg.effect |= EffectWrite;
pc->flags |= fPCodeFlag20000000;
return;
}
arg++;
argIdx--;
}
if (argIdx <= 0) {
arg = &pc->args[argCount];
pc->argCount++;
}
#line 105
CError_ASSERT(arg->kind == PCOp_PLACEHOLDEROPERAND);
arg->kind = PCOp_REGISTER;
arg->arg = RegClass_CRFIELD;
arg->data.reg.reg = reg;
arg->data.reg.effect = EffectWrite;
if (pc->op != PC_ADDICR)
pc->flags |= fPCodeFlag20000000;
}
}
void pcsetsideeffects(PCode *pc) {
pc->flags &= ~(fPCodeFlag10 | fCommutative | fIsCSE);
pc->flags |= fSideEffects;
}
void pcsetlinkbit(PCode *pc) {
PCodeArg *arg;
int argIdx;
switch (pc->op) {
case PC_B:
pc->op = PC_BL;
break;
case PC_BCTR:
pc->op = PC_BCTRL;
break;
case PC_BLR:
pc->op = PC_BLRL;
break;
}
arg = pc->args;
argIdx = pc->argCount;
while (arg->kind != PCOp_PLACEHOLDEROPERAND && argIdx) {
if (arg->kind == PCOp_REGISTER && arg->arg == RegClass_SPR && arg->data.reg.reg == 1) {
arg->data.reg.effect |= EffectWrite;
pc->flags |= fLink;
return;
}
arg++;
argIdx--;
}
#line 169
CError_ASSERT(arg->kind == PCOp_PLACEHOLDEROPERAND);
arg->kind = PCOp_REGISTER;
arg->arg = RegClass_SPR;
arg->data.reg.reg = 1;
arg->data.reg.effect = EffectWrite;
if (opcodeinfo[pc->op].flags & fPCodeFlag8) {
pc->flags &= ~fPCodeFlag1;
pc->flags |= fPCodeFlag8;
}
pc->flags |= fLink;
}
void branch_label(PCodeLabel *label) {
if (pclastblock->pcodeCount) {
pcbranch(pclastblock, label);
makepcblock();
}
pclabel(pclastblock, label);
}
void branch_conditional(short a, short compareop, short c, PCodeLabel *label) {
PCodeBlock *tmpblock;
PCodeLabel *tmplabel;
int r28;
tmpblock = pclastblock;
tmplabel = makepclabel();
switch (compareop) {
case ENOTEQU:
c = !c;
case EEQU:
r28 = 2;
break;
case EGREATEREQU:
c = !c;
case ELESS:
r28 = 0;
break;
case ELESSEQU:
c = !c;
case EGREATER:
r28 = 1;
break;
}
emitpcode(c ? PC_BT : PC_BF, a, r28, label);
pcbranch(pclastblock, label);
pcbranch(pclastblock, tmplabel);
makepcblock();
pclabel(pclastblock, tmplabel);
}
void branch_always(PCodeLabel *label) {
emitpcode(PC_B, label);
pcbranch(pclastblock, label);
makepcblock();
}
void branch_decrement_always(short opcode, PCodeLabel *label) {
PCodeLabel *tmplabel = makepclabel();
emitpcode(opcode, label);
pcbranch(pclastblock, label);
pcbranch(pclastblock, tmplabel);
makepcblock();
pclabel(pclastblock, tmplabel);
}
void branch_indirect(Object *obj) {
emitpcode(PC_BCTR, obj, 0);
makepcblock();
}
int branch_count_volatiles(void) {
int count = 0;
int i;
char rclass;
for (rclass = 0; rclass < RegClassMax; rclass++) {
for (i = 0; i < n_scratch_registers[(char)rclass]; i++) {
count++;
}
}
return count;
}
PCodeArg *branch_record_volatiles(PCodeArg *arglist, UInt32 *masks) {
int i;
char rclass;
for (rclass = RegClassMax - 1; rclass >= 0; rclass--) {
for (i = 0; i < n_scratch_registers[(char)rclass]; i++) {
arglist->kind = PCOp_REGISTER;
arglist->arg = rclass;
arglist->data.reg.reg = scratch_registers[(char)rclass][i];
arglist->data.reg.effect = EffectWrite;
if (masks[(char)rclass] & (1 << scratch_registers[(char)rclass][i]))
arglist->data.reg.effect |= EffectRead;
arglist++;
}
}
return arglist;
}
void branch_subroutine(Object *obj, short add_nop, UInt32 *masks) {
int count;
PCode *pc;
PCodeArg *arg;
count = branch_count_volatiles();
if (copts.exceptions && current_statement)
count += countexceptionactionregisters(current_statement->dobjstack);
pc = makepcode(PC_BL, count, obj, 0);
arg = branch_record_volatiles(pc->args + 1, masks);
if (copts.exceptions && current_statement)
noteexceptionactionregisters(current_statement->dobjstack, arg);
appendpcode(pclastblock, pc);
if (add_nop)
emitpcode(PC_NOP);
branch_label(makepclabel());
if (copts.exceptions && current_statement)
recordexceptionactions(pc, current_statement->dobjstack);
}
void branch_subroutine_ctr(UInt32 *masks) {
int count;
PCode *pc;
PCodeArg *arg;
count = branch_count_volatiles();
if (copts.exceptions && current_statement)
count += countexceptionactionregisters(current_statement->dobjstack);
pc = makepcode(PC_BCTRL, count);
arg = branch_record_volatiles(pc->args + 1, masks);
if (copts.exceptions && current_statement)
noteexceptionactionregisters(current_statement->dobjstack, arg);
appendpcode(pclastblock, pc);
branch_label(makepclabel());
if (copts.exceptions && current_statement)
recordexceptionactions(pc, current_statement->dobjstack);
}
void add_immediate(short dest_reg, short base_reg, Object *obj, short offset) {
short tmp_reg = base_reg;
if (obj && offset && obj->datatype != DLOCAL) {
tmp_reg = used_virtual_registers[RegClass_GPR]++;
add_immediate_lo(tmp_reg, base_reg, obj, 0, 1);
obj = NULL;
}
if (!obj && !offset)
emitpcode(PC_MR, dest_reg, tmp_reg);
else
emitpcode(PC_ADDI, dest_reg, tmp_reg, obj, offset);
}
PCode *add_immediate_lo(short dest_reg, short base_reg, Object *obj, short offset, char add_to_block) {
PCode *pc;
#line 577
CError_ASSERT(obj);
pc = makepcode(PC_ADDI, dest_reg, base_reg, obj, offset);
if (add_to_block)
appendpcode(pclastblock, pc);
return pc;
}
PCode *op_absolute_ha(short dest_reg, short base_reg, Object *obj, short offset, char add_to_block) {
PCode *pc;
int tmp_reg;
if (obj->datatype == DLOCAL) {
pc = makepcode(PC_ADDIS, dest_reg, base_reg, obj, offset);
} else if (copts.codegen_pic) {
tmp_reg = base_reg;
#line 601
CError_ASSERT(tmp_reg);
pc = makepcode(PC_ADDIS, dest_reg, tmp_reg, obj, offset);
} else {
#line 606
CError_ASSERT(base_reg == 0);
pc = makepcode(PC_LIS, dest_reg, obj, offset);
}
if (add_to_block)
appendpcode(pclastblock, pc);
return pc;
}
void load_store_register(short opcode, short dest_reg, short base_reg, Object *obj, SInt32 offset) {
short addi_tmp;
short offset_reg1;
short offset_reg2;
offset_reg1 = base_reg;
if (obj && offset && obj->datatype != DLOCAL) {
offset_reg1 = used_virtual_registers[RegClass_GPR]++;
add_immediate_lo(offset_reg1, base_reg, obj, 0, 1);
obj = NULL;
}
if (offset != (short)offset) {
if (opcode == PC_LWZ && dest_reg == 12)
offset_reg2 = 12;
else if (opcode == PC_LWZ && dest_reg == 11)
offset_reg2 = 11;
else
offset_reg2 = used_virtual_registers[RegClass_GPR]++;
emitpcode(PC_ADDIS, offset_reg2, offset_reg1, 0, (short) ((offset >> 16) + ((offset & 0x8000) >> 15)));
offset = (short) offset;
offset_reg1 = offset_reg2;
}
if (opcode == PC_STVX || opcode == PC_LVX) {
offset_reg2 = 0;
if (obj) {
addi_tmp = used_virtual_registers[RegClass_GPR]++;
emitpcode(PC_ADDI, addi_tmp, offset_reg1, obj, offset);
offset_reg1 = addi_tmp;
} else if (offset) {
offset_reg2 = used_virtual_registers[RegClass_GPR]++;
emitpcode(PC_LI, offset_reg2, offset);
}
if (!offset_reg2)
emitpcode(opcode, dest_reg, 0, offset_reg1);
else
emitpcode(opcode, dest_reg, offset_reg1, offset_reg2);
} else {
emitpcode(opcode, dest_reg, offset_reg1, obj, offset);
}
}

View File

@ -0,0 +1,392 @@
#include "compiler.h"
#include "compiler/CError.h"
#include "compiler/objects.h"
#include "compiler/PCode.h"
short last_exception_register[RegClassMax];
short first_fe_temporary_register[RegClassMax];
short last_argument_register[RegClassMax];
short _FP_;
short _CALLER_SP_;
char *special_register_names[RegClassMax][RegisterMax];
static short used_regs_before_coloring;
static UInt8 save_state[RegisterMax];
char *XXspecial_register_names[RegClassMax * RegisterMax];
short spr_to_sysreg[4] = {1, 8, 9, 0x100};
void asm_used_register(char rclass, short reg) {
int i;
if ((reg < n_real_registers[rclass]) && (reg_state[rclass][reg] == RegState0)) {
if (reg == nonvolatile_registers[rclass][used_nonvolatile_registers[rclass]]) {
if (assignable_registers[rclass] > 0)
assignable_registers[rclass]--;
reg_state[rclass][reg] = RegState1;
used_nonvolatile_registers[rclass]++;
} else {
for (i = used_nonvolatile_registers[rclass]; i < n_nonvolatile_registers[rclass]; i++) {
if (reg == nonvolatile_registers[rclass][i]) {
reg_state[rclass][reg] = RegState1;
if (assignable_registers[rclass] > 0)
assignable_registers[rclass]--;
}
}
}
}
}
void retain_register(Object *obj, char rclass, short reg) {
VarInfo *vi;
#line 95
CError_ASSERT((short) reg < RegisterMax);
if (reg_state[rclass][reg] == RegState0) {
assignable_registers[rclass]--;
reg_state[rclass][reg] = RegState1;
if (reg == nonvolatile_registers[rclass][used_nonvolatile_registers[rclass]])
used_nonvolatile_registers[rclass]++;
}
if (obj) {
vi = Registers_GetVarInfo(obj);
vi->rclass = rclass;
vi->flags |= VarInfoFlag2;
vi->reg = reg;
}
}
void retain_GPR_pair(Object *obj, short reg, short regHi) {
VarInfo *vi;
retain_register(NULL, RegClass_GPR, reg);
retain_register(NULL, RegClass_GPR, regHi);
if (obj) {
vi = Registers_GetVarInfo(obj);
vi->rclass = RegClass_GPR;
vi->flags |= VarInfoFlag2 | VarInfoFlag4;
vi->reg = reg;
vi->regHi = regHi;
}
}
int is_register_object(Object *obj) {
return obj->sclass == OBJECT_SCLASS_101;
}
int GetABIFirstNonVolatile(char rclass) {
switch (rclass) {
case RegClass_SPR: return 3;
case RegClass_CRFIELD: return 2;
case RegClass_VR: return 20;
case RegClass_GPR: return 13;
case RegClass_FPR: return 14;
default: return -1;
}
}
char GetRegisterClassName(char rclass) {
switch (rclass) {
case RegClass_VR: return 'v';
case RegClass_GPR: return 'r';
case RegClass_FPR: return 'f';
default:
#line 242
CError_FATAL();
return '?';
}
}
static int first_nonvolatile_reg(char rclass) {
return GetABIFirstNonVolatile(rclass);
}
void setup_diagnostic_reg_strings() {
register_class_name[RegClass_SPR] = "SPR";
register_class_format[RegClass_SPR] = "spr%ld";
register_class_name[RegClass_CRFIELD] = "CRFIELD";
register_class_format[RegClass_CRFIELD] = "cr%ld";
register_class_name[RegClass_VR] = "VR";
register_class_format[RegClass_VR] = "vr%ld";
register_class_name[RegClass_FPR] = "FPR";
register_class_format[RegClass_FPR] = "f%ld";
register_class_name[RegClass_GPR] = "GPR";
register_class_format[RegClass_GPR] = "r%ld";
}
void init_target_registers() {
char rclass;
int reg;
int end;
int tmp;
static int last_nonvolatile_reg[] = {3, 5, 31, 31, 31};
static int nonvol_reserve[] = {0, 0, 0, 4, 3};
for (rclass = 0; rclass < RegClassMax; rclass++) {
for (reg = 0; reg < RegisterMax; reg++)
special_register_names[(char)rclass][reg] = NULL;
}
special_register_names[RegClass_SPR][0] = "XER";
special_register_names[RegClass_SPR][1] = "LR";
special_register_names[RegClass_SPR][2] = "CTR";
special_register_names[RegClass_SPR][3] = "VRSAVE";
special_register_names[RegClass_GPR][1] = "SP";
setup_diagnostic_reg_strings();
n_real_registers[RegClass_SPR] = 4;
n_real_registers[RegClass_CRFIELD] = 8;
n_real_registers[RegClass_VR] = 32;
n_real_registers[RegClass_FPR] = 32;
n_real_registers[RegClass_GPR] = 32;
reg_state[RegClass_GPR][1] = RegState2;
reg_state[RegClass_GPR][2] = RegState2;
reg_state[RegClass_CRFIELD][5] = RegState2;
for (rclass = 0; rclass < RegClassMax; rclass++) {
n_nonvolatile_registers[(char)rclass] = 0;
if (last_nonvolatile_reg[(char)rclass] >= 0) {
end = first_nonvolatile_reg(rclass);
for (reg = last_nonvolatile_reg[(char)rclass]; reg >= end; reg--) {
if (reg_state[(char)rclass][reg] == RegState0) {
tmp = n_nonvolatile_registers[(char)rclass]++;
nonvolatile_registers[(char)rclass][tmp] = reg;
}
}
}
assignable_registers[(char)rclass] = n_nonvolatile_registers[(char)rclass] - nonvol_reserve[(char)rclass];
if (assignable_registers[(char)rclass] < 0)
assignable_registers[(char)rclass] = 0;
n_scratch_registers[(char)rclass] = 0;
for (reg = 0; reg < n_real_registers[(char)rclass]; reg++) {
if (reg < GetABIFirstNonVolatile(rclass) || reg > last_nonvolatile_reg[(char)rclass]) {
if (reg_state[(char)rclass][reg] == RegState0) {
tmp = n_scratch_registers[(char)rclass]++;
scratch_registers[(char)rclass][tmp] = reg;
}
}
}
}
_FP_ = -1;
_CALLER_SP_ = -1;
optimizing = (copts.optimizationlevel > 0) && !disable_optimizer;
}
void assign_register_by_type(Object *obj) {
VarInfo *vi;
Type *ty;
Boolean flag;
ty = obj->type;
vi = Registers_GetVarInfo(obj);
flag = 0;
vi->rclass = RegClassMax;
vi->reg = 0;
vi->regHi = 0;
if ((ty->type == TYPEINT) || (ty->type == TYPEENUM) || ((ty->type == TYPEPOINTER || ty->type == TYPEARRAY) && (ty->type != TYPEARRAY)) || ((ty->type == TYPEMEMBERPOINTER) && (ty->size == 4U))) {
if (((ty->type == TYPEINT) || (ty->type == TYPEENUM)) && (ty->size == 8))
flag = 1;
vi->rclass = RegClass_GPR;
} else if (ty->type == TYPEFLOAT) {
vi->rclass = RegClass_FPR;
} else if ((ty->type == TYPESTRUCT) && (TYPE_STRUCT(ty)->stype >= STRUCT_TYPE_4) && (TYPE_STRUCT(ty)->stype <= STRUCT_TYPE_E)) {
vi->rclass = RegClass_VR;
} else {
return;
}
if (vi->rclass < RegClassMax) {
if (flag) {
#line 520
CError_ASSERT(vi->rclass == RegClass_GPR);
if (assignable_registers[vi->rclass] > 1)
assign_GPR_pair(obj);
} else {
if (assignable_registers[vi->rclass] > 0)
assign_register_to_variable(obj, vi->rclass);
}
}
}
void assign_GPR_pair(Object *obj) {
VarInfo *vi;
short reg;
short regHi;
vi = Registers_GetVarInfo(obj);
if (optimizing) {
reg = used_virtual_registers[RegClass_GPR]++;
regHi = used_virtual_registers[RegClass_GPR]++;
} else {
#line 554
CError_ASSERT(assignable_registers[RegClass_GPR] >= 2);
reg = obtain_nonvolatile_register(RegClass_GPR);
regHi = obtain_nonvolatile_register(RegClass_GPR);
retain_GPR_pair(obj, reg, regHi);
}
vi->rclass = RegClass_GPR;
if (reg > 0 && regHi > 0) {
vi->flags |= VarInfoFlag2 | VarInfoFlag4;
vi->reg = reg;
vi->regHi = regHi;
} else {
#line 567
CError_FATAL();
}
}
void open_fe_temp_registers() {
int r;
r = used_virtual_registers[RegClass_GPR];
first_fe_temporary_register[RegClass_GPR] = last_temporary_register[RegClass_GPR] = r;
r = used_virtual_registers[RegClass_FPR];
first_fe_temporary_register[RegClass_FPR] = last_temporary_register[RegClass_FPR] = r;
r = used_virtual_registers[RegClass_VR];
first_fe_temporary_register[RegClass_VR] = last_temporary_register[RegClass_VR] = r;
//first_fe_temporary_register[RegClass_GPR] = last_temporary_register[RegClass_GPR] = used_virtual_registers[RegClass_GPR];
//first_fe_temporary_register[RegClass_FPR] = last_temporary_register[RegClass_FPR] = used_virtual_registers[RegClass_FPR];
//first_fe_temporary_register[RegClass_VR] = last_temporary_register[RegClass_VR] = used_virtual_registers[RegClass_VR];
}
void set_last_exception_registers() {
last_exception_register[RegClass_GPR] = used_virtual_registers[RegClass_GPR] - 1;
last_exception_register[RegClass_FPR] = used_virtual_registers[RegClass_FPR] - 1;
last_exception_register[RegClass_VR] = used_virtual_registers[RegClass_VR] - 1;
}
static VarInfo *Registers_GetNewVarInfo() {
VarInfo *vi = galloc(sizeof(VarInfo));
memclrw(vi, sizeof(VarInfo));
return vi;
}
VarInfo *Registers_GetVarInfo(Object *obj) {
switch (obj->datatype) {
case DDATA:
if (!obj->u.data.info)
obj->u.data.info = Registers_GetNewVarInfo();
return obj->u.data.info;
case DNONLAZYPTR:
// not sure if this is the right union
if (!obj->u.toc.info) {
#line 639
CError_FATAL();
obj->u.toc.info = CodeGen_GetNewVarInfo();
}
return obj->u.toc.info;
case DLOCAL:
if (!obj->u.var.info) {
#line 647
CError_FATAL();
}
return obj->u.var.info;
case DABSOLUTE:
// not sure if this is the right union
if (!obj->u.data.info)
obj->u.data.info = Registers_GetNewVarInfo();
return obj->u.data.info;
default:
#line 660
CError_FATAL();
return NULL;
}
}
int used_vrstate_VRs() {
int count = 0;
int i;
for (i = 0; i < RegisterMax; i++) {
if (reg_state[RegClass_VR][i])
count++;
}
return count;
}
UInt32 colored_vrs_as_vrsave(PCodeBlock *block) {
PCode *pc;
UInt32 mask;
int i;
mask = 0;
if (copts.x1B == 2)
return 0xFFFFFFFF;
if (copts.x1B == 0)
return 0;
while (block) {
for (pc = block->firstPCode; pc; pc = pc->nextPCode) {
if (pc->flags & (fPCodeFlag40000000 | fPCodeFlag80000000)) {
for (i = 0; i < pc->argCount; i++) {
if (pc->args[i].kind == PCOp_REGISTER && pc->args[i].arg == RegClass_VR)
mask |= 1 << (31 - pc->args[i].data.reg.reg);
}
}
}
block = block->nextBlock;
}
return mask;
}
void save_before_coloring_nonvolatile_registers(char rclass) {
used_regs_before_coloring = used_nonvolatile_registers[rclass];
memcpy(save_state, reg_state[rclass], sizeof(save_state));
}
void reset_nonvolatile_registers(char rclass) {
used_nonvolatile_registers[rclass] = used_regs_before_coloring;
memcpy(reg_state[rclass], save_state, sizeof(save_state));
}
int is_nonvolatile_register(char rclass, int reg) {
int i;
for (i = 0; i < n_nonvolatile_registers[rclass]; i++) {
if (reg == nonvolatile_registers[rclass][i])
return 1;
}
return 0;
}
void init_endian() {
if (copts.little_endian) {
high_offset = 4;
low_offset = 0;
high_reg = 4;
low_reg = 3;
high_reg2 = 6;
low_reg2 = 5;
} else {
high_offset = 0;
low_offset = 4;
high_reg = 3;
low_reg = 4;
high_reg2 = 5;
low_reg2 = 6;
}
}
void update_asm_nonvolatile_registers() {
char rclass;
int r31;
for (rclass = 0; rclass < RegClassMax; rclass++) {
for (r31 = n_nonvolatile_registers[rclass] - 1; r31 >= 0; r31--) {
if (reg_state[rclass][nonvolatile_registers[rclass][r31]] == RegState1)
break;
}
if (r31 > used_nonvolatile_registers[rclass])
used_nonvolatile_registers[rclass] = r31;
}
}

View File

@ -0,0 +1,225 @@
#include "compiler.h"
#include "compiler/objects.h"
#include "compiler/PCode.h"
// haven't checked this object file for .data stuff yet
// ONLY FOR TESTING
// this file gets kinda fucked up by the loop unroller
//#pragma opt_unroll_loops off
int used_virtual_registers[RegClassMax];
int used_nonvolatile_registers[RegClassMax];
int assignable_registers[RegClassMax];
int n_real_registers[RegClassMax];
int n_scratch_registers[RegClassMax];
int scratch_registers[RegClassMax][RegisterMax];
int n_nonvolatile_registers[RegClassMax];
int nonvolatile_registers[RegClassMax][RegisterMax];
UInt8 reg_state[RegClassMax][RegisterMax];
int first_temporary_register[RegClassMax];
int last_temporary_register[RegClassMax];
char *register_class_name[RegClassMax];
char *register_class_format[RegClassMax];
int coloring;
int optimizing;
typedef struct ModifiedRegisters {
struct ModifiedRegisters *next;
Object *obj;
UInt32 mask[RegClassMax];
} ModifiedRegisters;
static ModifiedRegisters *mod_regs_table[128];
void init_registers() {
char rclass;
int j;
for (rclass = 0; rclass < RegClassMax; rclass++) {
for (j = 0; j < RegisterMax; j++) {
reg_state[(char)rclass][j] = RegState0;
}
}
for (rclass = 0; rclass < RegClassMax; rclass++)
used_nonvolatile_registers[(char)rclass] = 0;
optimizing = 1;
init_target_registers();
for (rclass = 0; rclass < RegClassMax; rclass++)
used_virtual_registers[(char)rclass] = n_real_registers[(char)rclass];
coloring = 1;
}
void assign_register_to_variable(Object *obj, char rclass) {
VarInfo *vi;
short reg;
vi = Registers_GetVarInfo(obj);
if (optimizing) {
reg = used_virtual_registers[rclass]++;
} else {
reg = obtain_nonvolatile_register(rclass);
retain_register(obj, rclass, reg);
}
vi->flags |= VarInfoFlag2;
vi->rclass = rclass;
vi->reg = reg;
}
void retain_register_for_argument(Object *obj, char rclass, short reg) {
VarInfo *vi = obj->u.var.info;
reg_state[rclass][reg] = RegState1;
vi->flags |= VarInfoFlag2;
vi->rclass = rclass;
vi->reg = reg;
}
int available_registers(char rclass) {
int i;
int count = 0;
for (i = 0; i < n_real_registers[rclass]; i++) {
if (reg_state[rclass][i] == RegState0)
count++;
}
return count;
}
UInt32 volatile_registers(char rclass) {
UInt32 mask = 0;
int i;
int reg;
for (i = 0; i < n_scratch_registers[rclass]; i++) {
reg = scratch_registers[rclass][i];
if (reg_state[rclass][reg] == RegState0)
mask |= 1 << reg;
}
return mask;
}
short obtain_nonvolatile_register(char rclass) {
int best = -1;
while (used_nonvolatile_registers[rclass] < n_nonvolatile_registers[rclass]) {
int tmp = nonvolatile_registers[rclass][used_nonvolatile_registers[rclass]++];
if (reg_state[rclass][tmp] == RegState0) {
best = tmp;
break;
}
}
return best;
}
void open_temp_registers() {
int rclass;
for (rclass = 0; (char)rclass < RegClassMax; rclass++) {
int r = used_virtual_registers[(char)rclass];
//last_temporary_register[rclass] = r;
//first_temporary_register[rclass] = r;
first_temporary_register[(char)rclass] = last_temporary_register[(char)rclass] = r;
}
/*rclass = 0;
while (rclass < RegClassMax) {
r = used_virtual_registers[(char)rclass];
last_temporary_register[(char)rclass] = r;
first_temporary_register[(char)rclass] = r;
rclass = rclass + 1;
}*/
}
void check_temp_registers() {
char rclass;
if (!optimizing) {
for (rclass = 0; rclass < RegClassMax; rclass++) {
if (used_virtual_registers[(char)rclass] > last_temporary_register[(char)rclass])
last_temporary_register[(char)rclass] = used_virtual_registers[(char)rclass];
if (used_virtual_registers[(char)rclass] > 256)
used_virtual_registers[(char)rclass] = first_temporary_register[(char)rclass];
}
}
}
void close_temp_registers() {
char rclass;
for (rclass = 0; rclass < RegClassMax; rclass++) {
if (used_virtual_registers[(char)rclass] < last_temporary_register[(char)rclass])
used_virtual_registers[(char)rclass] = last_temporary_register[(char)rclass];
else
last_temporary_register[(char)rclass] = used_virtual_registers[(char)rclass];
}
}
int count_scratch_registers() {
int rclass;
int count;
count = 0;
for (rclass = 0; (char)rclass < RegClassMax; rclass++)
count += n_scratch_registers[(char)rclass];
return count;
}
void init_modified_registers() {
int i = 0;
for (i = 0; i < 128; i++)
mod_regs_table[i] = NULL;
}
static void compute_modified_registers(UInt32 *masks) {
int rclass;
PCodeBlock *block;
PCode *pcode;
int i;
for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = 0;
for (block = pcbasicblocks; block; block = block->nextBlock) {
for (pcode = block->firstPCode; pcode; pcode = pcode->nextPCode) {
for (i = 0; i < pcode->argCount; i++) {
if (pcode->args[i].kind == PCOp_REGISTER && pcode->args[i].data.reg.effect & EffectWrite)
masks[pcode->args[i].arg] |= 1 << pcode->args[i].data.reg.reg;
}
}
}
}
void note_modified_registers(Object *obj) {
ModifiedRegisters *mr;
mr = galloc(sizeof(ModifiedRegisters));
mr->obj = obj;
compute_modified_registers(mr->mask);
mr->next = mod_regs_table[obj->name->hashval];
mod_regs_table[obj->name->hashval] = mr;
}
void find_modified_registers(Object *obj, UInt32 *masks) {
char rclass;
ModifiedRegisters *scan;
for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = 0xFFFFFFFF;
if (CParser_HasInternalLinkage(obj)) {
for (scan = mod_regs_table[obj->name->hashval]; scan; scan = scan->next) {
if (scan->obj == obj)
break;
}
if (scan) {
for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = scan->mask[(char)rclass];
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,276 +8,29 @@
#pragma options align=mac68k
#endif
enum {
AlignMode0_Mac68k,
AlignMode1_Mac68k4byte,
AlignMode2_PPC,
AlignMode3_1Byte,
AlignMode4_2Byte,
AlignMode5_4Byte,
AlignMode6_8Byte,
AlignMode7_16Byte,
AlignMode8
};
// not sure how many of these are char and how many are unsigned char or Boolean
typedef struct COpts {
char little_endian;
char codegen_dynamic;
char codegen_pic;
char no_common;
char no_implicit_templates;
char absolutepath; // determines the path written to debug info
char x06; // linker/objgen related
short cpu;
char schedule_cpu;
unsigned char schedule_mode; // may be an enum??
SInt32 debuglisting;
char profile;
char traceback;
char disable_registers;
char fp_contract;
char no_register_save_helpers;
char ppc_unroll_speculative;
short ppc_unroll_instructions_limit;
short ppc_unroll_factor_limit;
char altivec_model;
UInt8 x1B; // altivec/vrsave related
UInt8 code_alignment;
char x1D;
UInt8 x1E; // some register used in TOC_use_isel
UInt8 gen_fsel;
char ppc_opt_bclr_bcctr;
char use_lmw_stmw;
char report_heap_info;
char misaligned_mem_access;
char switch_tables;
char prepare_compress;
char some_alignment; // used in CMach_AllocationAlignment
char asmsemicolcomment;
char asmpoundcomment;
StringPtr oldprefixname;
short inlinelevel;
int inline_max_size;
int inline_max_total_size;
char inline_bottom_up;
Boolean cplusplus;
Boolean ecplusplus;
char objective_c;
char objc_strict;
char ARM_conform;
char ARM_scoping;
char require_prototypes;
char trigraphs;
char only_std_keywords;
char enumsalwaysint;
char ANSI_strict;
char mpwc_relax;
char mpwc_newline;
char ignore_oldstyle;
char cpp_extensions;
char pointercast_lvalue;
char useRTTI;
char delete_exception;
char _4B;
Boolean oldalignment;
char unsignedchars;
char multibyteaware;
char autoinline;
char defer_codegen;
Boolean direct_to_som;
char som_env_check;
char som_call_opt;
char booltruefalse;
char old_enum_mangler;
char longlong;
char longlong_enums;
char no_tfuncinline;
char _59;
char flat_include;
char syspath_once;
char always_import;
char simple_class_byval;
char wchar_type;
char vbase_ctor_offset;
char vbase_abi_v2;
char def_inherited;
char template_patch;
char template_friends;
char faster_pch_gen;
char array_new_delete;
Boolean dollar_identifiers;
char def_inline_tfuncs;
char arg_dep_lookup;
Boolean simple_prepdump;
char line_prepdump;
char fullpath_prepdump;
char old_mtemplparser;
char suppress_init_code;
char reverse_bitfields;
Boolean c9x;
char float_constants;
char no_static_dtors;
char longlong_prepeval;
char const_strings;
char dumpir;
char experimental;
char gcc_extensions;
char stdc_fp_contract;
char stdc_fenv_access;
char stdc_cx_limitedr;
char old_argmatch;
char optEH;
char optEH2;
char new_mangler;
char microsoft;
Boolean warningerrors;
char pedantic;
char check_header_flags;
Boolean supress_warnings;
Boolean warn_illpragma;
char warn_emptydecl;
char warn_possunwant;
char warn_unusedvar;
char warn_unusedarg;
char warn_extracomma;
char warn_hidevirtual;
char warn_largeargs;
char warn_implicitconv;
char warn_notinlined;
char warn_structclass;
char warn_padding;
char warn_no_side_effect;
char warn_resultnotused;
char warn_ptr_int_conv;
char align_mode;
Boolean align_array_members;
char dont_reuse_strings;
char pool_strings;
char explicit_zero_data;
char readonly_strings;
char exceptions;
char _99;
char dont_inline;
char always_inline;
char peephole;
char global_optimizer;
char side_effects;
char internal;
char import;
char export;
char lib_export;
char nosyminline;
char force_active;
char optimizationlevel;
char optimize_for_size;
char optimizewithasm;
char crippled;
char opt_common_subs;
char opt_loop_invariants;
char opt_propagation;
char opt_dead_assignments;
char opt_strength_reduction;
char opt_strength_reduction_strict;
char opt_dead_code;
char opt_lifetimes;
char _B1; // unused?
char opt_unroll_loops;
char opt_vectorize_loops;
char _B4; // amount of IRO passes?
char opt_pointer_analysis;
char opt_pointer_analysis_mode;
char loop_unroll_count;
char loop_unroll_size_threshold;
char isGeneratingDebugInfo;
CWDataType pchCreator;
CWDataType pchType;
CWDataType text;
HashNameNode *forcedSegment; // when set by #pragma segment
} COpts;
typedef struct CParams {
CWPluginContext context;
CWObjectData objectdata;
Handle objectDataHandle;
Handle browseDataHandle;
SInt32 pluginRequest;
SInt32 apiVersion;
FSSpec projectFile;
SInt32 projectFileCount;
SInt32 mainFileNumber;
FSSpec mainFileSpec;
const char *mainFileText;
SInt32 mainFileTextLength;
Boolean isPrecompiling;
Boolean isAutoPrecompiling;
Boolean isPreprocessing;
Boolean isGeneratingDebugInfo;
Boolean isCachingPrecompiledHeaders;
CWBrowseOptions browseOptions;
Boolean field276;
SInt16 mainFileID;
CWDataType targetOS;
CWDataType targetCPU;
char *targetName;
} CParams;
typedef struct VarInfo { // OK!
Object *func;
SInt32 usage;
TStreamElement deftoken;
SInt16 varnumber;
Boolean noregister;
Boolean used;
UInt8 flags;
UInt8 rclass;
SInt16 reg;
SInt16 regHi;
} VarInfo;
typedef struct DefArgCtorInfo {
struct DefArgCtorInfo {
Object *default_func;
ENode *default_arg;
} DefArgCtorInfo;
};
typedef struct XRefOffset {
UInt32 xrefoffset;
SInt32 offset;
} XRefOffset;
typedef struct InlineXRef {
struct InlineXRef *next;
struct InlineXRef {
InlineXRef *next;
Object *object;
UInt16 xrefmode;
UInt16 numxrefs;
XRefOffset xref[1];
} InlineXRef;
};
typedef enum StatementType {
ST_NOP = 1,
ST_LABEL,
ST_GOTO,
ST_EXPRESSION,
ST_SWITCH,
ST_IFGOTO,
ST_IFNGOTO,
ST_RETURN,
ST_OVF,
ST_EXIT,
ST_ENTRY,
ST_BEGINCATCH,
ST_ENDCATCH,
ST_ENDCATCHDTOR,
ST_GOTOEXPR,
ST_ASM,
ST_BEGINLOOP,
ST_ENDLOOP,
ST_ILLEGAL
} StatementType;
typedef enum ExceptionActionType {
EAT_NOP,
@ -301,8 +54,8 @@ typedef enum ExceptionActionType {
EAT_NACTIONS
} ExceptionActionType;
typedef struct ExceptionAction {
struct ExceptionAction *prev;
struct ExceptionAction {
ExceptionAction *prev;
union {
struct {
Object *local;
@ -385,32 +138,10 @@ typedef struct ExceptionAction {
} local;
} data;
ExceptionActionType type;
} ExceptionAction;
};
typedef struct Statement {
struct Statement *next;
StatementType type;
char marked;
UInt8 flags;
UInt16 value;
ENode *expr;
CLabel *label;
ExceptionAction *dobjstack;
SInt32 sourceoffset;
HashNameNode *sourcefilepath;
} Statement;
typedef struct CLabel {
struct CLabel *next;
Statement *stmt;
HashNameNode *uniquename;
HashNameNode *name;
PCodeLabel *pclabel;
void *sicg_label;
} CLabel;
typedef struct MemInitializer {
struct MemInitializer *next;
struct MemInitializer {
MemInitializer *next;
union {
ENodeList *nodes;
ENode *expr;
@ -421,7 +152,7 @@ typedef struct MemInitializer {
} u;
Boolean is_ivar;
Boolean is_expr;
} MemInitializer;
};
typedef enum DepNameType {
@ -434,8 +165,8 @@ typedef enum DepNameType {
DNT_TYPENAME
} DepNameType;
typedef struct DepName {
struct DepName *next;
struct DepName {
DepName *next;
union {
HashNameNode *name;
NameSpace *nspace;
@ -453,7 +184,7 @@ typedef struct DepName {
} tname;
} u;
DepNameType type;
} DepName;
};
@ -479,314 +210,110 @@ typedef struct Substitution {
SubKind kind;
} Substitution;
// Registers.c
enum {
RegisterMax = 32
};
const char RegClass_SPR = 0;
const char RegClass_CRFIELD = 1;
const char RegClass_VR = 2;
const char RegClass_FPR = 3;
const char RegClass_GPR = 4;
const char RegClassMax = 5;
/*enum RegClass {
RegClass_SPR,
RegClass_CRFIELD,
RegClass_VR,
RegClass_FPR,
RegClass_GPR,
RegClassMax
};*/
// CScope.c
extern Boolean cscope_is_member_func;
extern Object *cscope_currentfunc;
extern TypeClass *cscope_currentclass;
extern NameSpace *cscope_current;
extern NameSpace *cscope_root;
enum {
RegState0 = 0,
RegState1 = 1,
RegState2 = 2
};
typedef struct CScopeSave {
NameSpace *current;
TypeClass *currentclass;
Object *currentfunc;
Boolean is_member_func;
} CScopeSave; // assumed name
extern int used_virtual_registers[RegClassMax];
extern int used_nonvolatile_registers[RegClassMax];
extern int assignable_registers[RegClassMax];
extern int n_real_registers[RegClassMax];
extern int n_scratch_registers[RegClassMax];
extern int scratch_registers[RegClassMax][RegisterMax];
extern int n_nonvolatile_registers[RegClassMax];
extern int nonvolatile_registers[RegClassMax][RegisterMax];
extern UInt8 reg_state[RegClassMax][RegisterMax];
extern int first_temporary_register[RegClassMax];
extern int last_temporary_register[RegClassMax];
extern char *register_class_name[RegClassMax];
extern char *register_class_format[RegClassMax];
extern int coloring;
extern int optimizing;
typedef struct CScopeParseResult {
NameSpace *nspace_0;
HashNameNode *name_4;
Type *x8;
void *xC;
ObjBase *obj_10;
NameSpaceObjectList *nsol_14;
BClassList *bcl_18;
Boolean x1C;
Boolean x1D;
Boolean isambig;
Boolean x1F;
Boolean x20;
Boolean x21;
} CScopeParseResult;
extern void init_registers();
extern void assign_register_to_variable(Object *obj, char rclass);
extern void retain_register_for_argument(Object *obj, char rclass, short reg);
extern int available_registers(char rclass);
extern UInt32 volatile_registers(char rclass);
extern short obtain_nonvolatile_register(char rclass);
extern void open_temp_registers();
extern void check_temp_registers();
extern void close_temp_registers();
extern int count_scratch_registers();
extern void init_modified_registers();
extern void note_modified_registers(Object *obj);
extern void find_modified_registers(Object *obj, UInt32 *masks);
typedef struct CScopeNSIterator {
NameSpace *nspace;
NameSpaceLookupList *lookup;
CScopeParseResult *result;
} CScopeNSIterator;
// RegisterInfo.c
extern short last_exception_register[RegClassMax];
extern short first_fe_temporary_register[RegClassMax];
extern short last_argument_register[RegClassMax];
extern short _FP_;
extern short _CALLER_SP_;
extern char *special_register_names[RegClassMax][RegisterMax];
extern short spr_to_sysreg[4];
typedef struct CScopeObjectIterator {
NameSpace *nspace;
NameSpaceName *nextname;
NameSpaceObjectList *currlist;
int hashindex;
} CScopeObjectIterator;
extern void CScope_Setup();
extern void CScope_Cleanup();
extern void CScope_GetScope(CScopeSave *save);
extern void CScope_SetNameSpaceScope(NameSpace *nspace, CScopeSave *save);
extern void CScope_SetClassScope(TypeClass *cls, CScopeSave *save);
extern void CScope_SetClassDefScope(TypeClass *cls, CScopeSave *save);
extern void CScope_SetFunctionScope(Object *function, CScopeSave *save);
extern void CScope_SetMethodScope(Object *function, TypeClass *cls, Boolean unknownFlag, CScopeSave *save);
extern void CScope_RestoreScope(CScopeSave *saved);
extern Boolean CScope_IsEmptySymTable();
extern Boolean CScope_IsInLocalNameSpace(NameSpace *nspace);
extern NameSpaceObjectList *CScope_FindName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceName *CScope_FindNameSpaceName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceObjectList *CScope_InsertName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceObjectList *CScope_ArgumentDependentNameLookup(NameSpaceObjectList *list, HashNameNode *name, ENodeList *argNodes, Boolean flag);
extern NameSpace *CScope_NewHashNameSpace(HashNameNode *name);
extern NameSpace *CScope_NewListNameSpace(HashNameNode *name, Boolean is_global);
extern NameSpace *CScope_FindNonClassNonFunctionNS(NameSpace *nspace);
extern NameSpace *CScope_FindGlobalNS(NameSpace *nspoce);
extern Boolean CScope_IsStdNameSpace(NameSpace *nspace);
extern Boolean CScope_IsEmptyNameSpace(NameSpace *nspace);
extern void CScope_MergeNameSpace(NameSpace *dst, NameSpace *src);
extern void CScope_AddObject(NameSpace *nspace, HashNameNode *name, ObjBase *obj);
extern void CScope_AddGlobalObject(Object *obj);
extern NameSpaceLookupList *CScope_BuildNameSpaceLookupList(NameSpace *nspace);
extern Boolean CScope_FindQualifiedClassMember(CScopeParseResult *result, TypeClass *tclass, HashNameNode *name);
extern Type *CScope_GetType(NameSpace *nspace, HashNameNode *name, void **unk6);
extern Type *CScope_GetTagType(NameSpace *nspace, HashNameNode *name);
extern Boolean CScope_ParseExprName(CScopeParseResult *result);
extern Boolean CScope_ParseDeclName(CScopeParseResult *result);
extern Boolean CScope_ParseQualifiedNameSpace(CScopeParseResult *result, Boolean flag1, Boolean flag2);
extern Boolean CScope_ParseElaborateName(CScopeParseResult *result);
extern Boolean CScope_FindObject(NameSpace *nspace, CScopeParseResult *result, HashNameNode *name);
extern Boolean CScope_FindNonClassObject(NameSpace *nspace, CScopeParseResult *result, HashNameNode *name);
extern NameSpaceObjectList *CScope_FindObjectList(CScopeParseResult *result, HashNameNode *name);
extern Boolean CScope_PossibleTypeName(HashNameNode *name);
extern Boolean CScope_FindClassMemberObject(TypeClass *tclass, CScopeParseResult *result, HashNameNode *name);
extern void CScope_InitObjectIterator(CScopeObjectIterator *iterator, NameSpace *nspace);
extern ObjBase *CScope_NextObjectIteratorObject(CScopeObjectIterator *iterator);
extern NameSpaceObjectList *CScope_NextObjectIteratorObjectList(CScopeObjectIterator *iterator);
extern void CScope_DefineTypeTag(NameSpace *nspace, HashNameNode *name, Type *type);
extern Type *CScope_GetLocalTagType(NameSpace *nspace, HashNameNode *name);
extern Boolean CScope_FindTypeName(NameSpace *nspace, HashNameNode *name, CScopeParseResult *result);
extern NameSpaceObjectList *CScope_GetLocalObject(NameSpace *nspace, HashNameNode *name);
extern BClassList *CScope_GetClassAccessPath(BClassList *list, TypeClass *tclass);
extern Boolean CScope_ParseMemberName(TypeClass *tclass, CScopeParseResult *result, Boolean flag);
extern void CScope_AddClassUsingDeclaration(TypeClass *tclass, TypeClass *tclass2, HashNameNode *name, AccessType access);
extern void CScope_ParseUsingDeclaration(NameSpace *nspace, AccessType access);
extern void CScope_ParseNameSpaceAlias(HashNameNode *name);
extern void CScope_ParseUsingDirective(NameSpace *nspace);
// CMachine.c
extern TypeIntegral stbool;
extern TypeIntegral stchar;
extern TypeIntegral stsignedchar;
extern TypeIntegral stunsignedchar;
extern TypeIntegral stwchar;
extern TypeIntegral stsignedshort;
extern TypeIntegral stunsignedshort;
extern TypeIntegral stsignedint;
extern TypeIntegral stunsignedint;
extern TypeIntegral stsignedlong;
extern TypeIntegral stunsignedlong;
extern TypeIntegral stsignedlonglong;
extern TypeIntegral stunsignedlonglong;
extern TypeIntegral stfloat;
extern TypeIntegral stshortdouble;
extern TypeIntegral stdouble;
extern TypeIntegral stlongdouble;
extern TypeStruct stvectorunsignedchar;
extern TypeStruct stvectorsignedchar;
extern TypeStruct stvectorboolchar;
extern TypeStruct stvectorunsignedshort;
extern TypeStruct stvectorsignedshort;
extern TypeStruct stvectorboolshort;
extern TypeStruct stvectorunsignedlong;
extern TypeStruct stvectorsignedlong;
extern TypeStruct stvectorboollong;
extern TypeStruct stvectorfloat;
extern TypeStruct stvectorpixel;
extern TypeStruct stvector;
extern void CMach_Configure();
extern SInt32 CMach_GetQUALalign(UInt32 qual);
extern SInt32 CMach_ArgumentAlignment(Type *type);
extern SInt32 CMach_AllocationAlignment(Type *type, UInt32 qual);
extern CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right);
extern CInt64 CMach_CalcIntMonadic(Type *type, short op, CInt64 val);
extern CInt64 CMach_CalcIntConvertFromFloat(Type *type, Float fval);
extern void CMach_InitIntMem(Type *type, CInt64 val, void *mem);
extern void CMach_InitVectorMem(Type *type, MWVector128 val, void *mem);
extern Float CMach_CalcFloatDiadic(Type *type, Float left, short op, Float right);
extern Float CMach_CalcFloatMonadic(Type *type, short op, Float fval);
extern Boolean CMach_CalcFloatDiadicBool(Type *type, Float left, short op, Float right);
extern Boolean CMach_CalcVectorDiadicBool(Type *type, MWVector128 *left, short op, MWVector128 *right);
extern char *CMach_FloatScan(char *input, Float *result, Boolean *fail);
extern Float CMach_CalcFloatConvertFromInt(Type *type, CInt64 val);
extern Float CMach_CalcFloatConvert(Type *type, Float fval);
extern Boolean CMach_FloatIsZero(Float fval);
extern Boolean CMach_FloatIsOne(Float fval);
extern Boolean CMach_FloatIsNegOne(Float fval);
extern void CMach_InitFloatMem(Type *type, Float val, void *mem);
extern void CMach_PrintFloat(char *buf, Float val);
extern void CMach_PragmaParams();
extern void CMach_AdjustFuntionArgs();
extern SInt16 CMach_GetStructAlign(TypeStruct *tstruct);
extern SInt16 CMach_GetClassAlign(TypeClass *tclass);
extern SInt16 CMach_GetTypeAlign(Type *type);
extern SInt16 CMach_MemberAlignValue(Type *type, SInt32 var);
extern void CMach_StructLayoutInitOffset(SInt32 offset);
extern SInt32 CMach_StructLayoutGetCurSize();
extern SInt32 CMach_StructLayoutGetOffset(Type *type, UInt32 qual);
extern SInt32 CMach_StructLayoutBitfield(TypeBitfield *tbitfield, UInt32 qual);
extern UInt8 CMach_GetFunctionResultClass(TypeFunc *tfunc);
extern Boolean CMach_PassResultInHiddenArg(Type *type);
extern const char *CMach_GetCPU();
extern Boolean CMach_FloatIsPowerOf2(Float flt);
extern Float CMach_FloatReciprocal(Float flt);
extern SInt32 CMach_RoundedSizeOf(Object *object);
extern void CMach_ReInitRuntimeObjects();
// CPrep.c
typedef struct Macro {
struct Macro *next;
HashNameNode *name;
void *c;
Boolean xC;
Boolean xD;
Boolean is_special;
Boolean xF;
void *e;
} Macro;
typedef struct TokenStack {
char *pos;
char *macrostart;
Macro *macro;
Boolean macrocheck;
} TokenStack;
extern CParams *cparamblkptr;
extern short tk;
extern CInt64 tkintconst;
extern Float tkfloatconst;
extern char *tkstring;
extern HashNameNode *tkidentifier;
extern SInt32 tksize;
extern short ispascalstring;
extern short nlflag;
extern SInt32 lines;
extern Boolean spaceskip;
extern struct Macro **macrohashtable;
extern Boolean cprep_nomem_exit;
extern Boolean cprep_nostring;
extern Boolean cprep_eoltokens;
extern TokenStack tokenstack[128];
extern short tokenstacklevel;
extern SInt32 cprep_cursymfile; // might be a ptr?
extern char *pos;
extern char *macropos;
extern char *nextcharpos;
extern char CPrep_SkipNewCommentChar;
extern Boolean preprocessing_only;
extern Handle stringmem;
extern SInt32 maxstringsize;
extern char cprep_idarray[256];
extern Boolean was_escchar;
extern Boolean macrocheck;
extern Boolean widestring;
extern Boolean at_linestart;
extern char *prep_file_start;
extern char *prep_file_end;
extern char *macrostart;
extern Boolean cprep_strconcat;
extern CPrepFileInfo *prep_file;
extern short filesp;
extern SInt32 linenumber;
extern GList pplist;
extern TStreamElement *ts_current;
extern SInt32 ts_preread_elements;
extern void CPrep_InsertSpecialMacro(Macro *macro, char *name);
extern void CPrep_InsertSpecialMacros();
extern void CPrep_RemoveSpecialMacros();
extern Boolean setupprep();
extern void cleanupprep();
extern void CPrep_TSBufferGrow(int amount);
extern void CPrep_TokenStreamGetState(SInt32 *state);
extern void CPrep_TokenStreamSetState(SInt32 *state);
extern void CPrep_UnLex();
extern void CPrep_TokenStreamSetCurState(SInt32 *state);
extern void CPrep_StreamGetBlock();
extern void CPrep_StreamGetSemicolon();
extern void CPrep_StreamGetTemplate();
extern void CPrep_StreamInsert();
extern void CPrep_StreamRemove();
extern void CPrep_RemoveTokens();
extern void CPrep_TokenStreamFlush();
extern void CPrep_CurStreamElement();
extern void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SInt32 *selectionoffset, short *tokensize, SInt32 *linenumber, char *buf1, short *tokenoffset, short *tokenlength, char *buf2, short *lastarg);
extern void CPrep_Error(short code);
extern void CPrep_ErrorName(short code, const char *name);
extern void CPrep_Warning(short code);
extern void CPrep_WarningName(short code, const char *name);
extern void CPrep_ErrorMessage(int errTable, char *str, Boolean flag1, Boolean flag2);
extern void CPrep_ErrorMessageVA(int code, const char *format, va_list list, Boolean flag1, Boolean flag2);
extern void popfile();
extern void CPrep_SetSourceFile();
extern void CPrep_GetSourceFilePath();
extern void CPrep_NewFileOffsetInfo();
extern void CPrep_GetFileOffsetInfo();
extern void CPrep_GetFileOffsetInfo2();
extern void CPrep_ResetFileInfo();
extern void CPrep_GetPrepPos();
extern Boolean C_Compiler(CParams *param);
extern void poptokenseq();
extern void foundnl();
extern void newline();
extern short notendofline();
extern char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2);
extern void macrotest();
extern void CPrep_PragmaLex();
extern void CPrep_PushOption();
extern void CPrep_PopOption();
extern void preprocessor();
extern void CPrep_BrowserTokenOffset();
extern void CPrep_BrowserFileOffset();
extern void CPrep_BrowserFilePosition(CPrepFileInfo **fileinfo, SInt32 *offset);
extern CPrepFileInfo *CPrep_BrowserCurrentFile();
// CPrepTokenizer.c
extern short prepskipnextchar();
extern short prepnextchar();
extern short prepnextstringchar(char *str, Boolean flag);
extern void CPrep_MatchChar(char ch, Boolean flag);
extern char *CPrep_MatchChar2(char *str, char ch, Boolean flag);
extern short prepcurchar();
extern char *ReadIdentifier(char *str);
extern char *CPrep_SkipNewComment(char *str);
extern Boolean skipendoflinematch(char *str, Boolean flag);
extern void skipendofline();
extern void CPrep_SkipAsmComment();
extern short lookahead();
extern short lookahead_noeol();
extern short lex();
extern short plex();
extern short lexidentifier();
extern void asm_used_register(char rclass, short reg);
extern void retain_register(Object *obj, char rclass, short reg);
extern void retain_GPR_pair(Object *obj, short reg, short regHi);
extern int is_register_object(Object *obj);
extern int GetABIFirstNonVolatile(char rclass);
extern char GetRegisterClassName(char rclass);
extern void setup_diagnostic_reg_strings();
extern void init_target_registers();
extern void assign_register_by_type(Object *obj);
extern void assign_GPR_pair(Object *obj);
extern void open_fe_temp_registers();
extern void set_last_exception_registers();
extern VarInfo *Registers_GetVarInfo(Object *obj);
extern int used_vrstate_VRs();
extern UInt32 colored_vrs_as_vrsave(PCodeBlock *block);
extern void save_before_coloring_nonvolatile_registers(char rclass);
extern void reset_nonvolatile_registers(char rclass);
extern int is_nonvolatile_register(char rclass, int reg);
extern void init_endian();
extern void update_asm_nonvolatile_registers();
// LOOSE DECLS
extern Boolean C_Compiler(CParams *param);
extern short high_offset;
extern short low_offset;
extern short high_reg;
extern short low_reg;
extern short high_reg2;
extern short low_reg2;
extern void PrecompilerRead(short refnum, void *buffer);
extern void PrecompilerWrite();
extern void CodeGen_InitCompiler();
extern void CodeGen_TermCompiler();
extern void CodeGen_InitBackEndOptions();
extern void CodeGen_UpdateOptimizerOptions();
extern void CodeGen_UpdateBackEndOptions();
extern void MWUnmangle(const char *name, char *buf, int size);
extern COpts copts;
//extern COpts copts;
extern CParams *cparamblkptr;
extern FuncArg elipsis;
extern FuncArg oldstyle;
extern HashNameNode *constructor_name_node;
extern HashNameNode *destructor_name_node;
extern char *CMangler_GetOperator(HashNameNode *str);
extern jmp_buf errorreturn;
extern Boolean cprep_nomem_exit;
extern Boolean anyerrors;
@ -794,17 +321,7 @@ extern Boolean fatalerrors;
extern SInt32 lines;
extern char string[256];
extern TemplStack *ctempl_curinstance;
typedef struct ParserTryBlock {
struct ParserTryBlock *next;
jmp_buf jmpbuf;
NameSpace *cscope_current;
TypeClass *cscope_currentclass;
Object *cscope_currentfunc;
TemplStack *ctempl_curinstance;
TStreamElement *cerror_locktoken;
Boolean cscope_is_member_func;
} ParserTryBlock;
extern ParserTryBlock *trychain;
//extern ParserTryBlock *trychain;
extern Boolean in_assembler;
extern Boolean preprocessing_only;
extern void AssemblerError();
@ -817,14 +334,25 @@ extern short lookahead();
extern Object *CClass_Constructor(TypeClass *tclass);
extern Object *CClass_Destructor(TypeClass *tclass);
extern int CClass_CheckPures(TypeClass *tclass);
extern Boolean CClass_IsConstructor(Object *func);
extern short CABI_GetStructResultArgumentIndex();
extern Boolean CParser_HasInternalLinkage(Object *obj);
extern HashNameNode *CParser_GetUniqueName();
extern SInt32 CParser_GetUniqueID();
extern Boolean CParserIsVolatileExpr(ENode *expr);
extern Boolean CParserIsConstExpr(ENode *expr);
extern Boolean CParser_IsPublicRuntimeObject(Object *obj);
extern Boolean CParser_ParseOperatorName(short *token, Boolean flag1, Boolean flag2);
extern Boolean CTemplTool_EqualArgs(TemplArg *a, TemplArg *b);
extern Boolean CTemplTool_IsTemplateArgumentDependentType(Type *type);
extern TypeTemplDep *CDecl_NewTemplDepType(TypeTemplDepType tdtype);
extern Type *CDecl_NewPointerType(Type *type);
extern Type *CDecl_NewStructType(SInt32 size, SInt32 align);
extern Type *CDecl_NewArrayType(Type *type, SInt32 num);
extern GList name_mangle_list;
extern void CPrep_UnLex();
extern Type *CTempl_ClassGetType(TypeClass *tclass);
extern short is_typesame(Type *t1, Type *t2);
//extern short is_typesame(Type *t1, Type *t2);
extern Boolean is_unsigned(Type *type);
extern void CDecl_CompleteType(Type *type);
extern TemplArg *CTempl_ParseUncheckTemplArgs(void *fixmelater, Boolean flag);
@ -835,14 +363,95 @@ extern Boolean CParser_CheckTemplateClassUsage(TemplClass *tmclass, Boolean flag
extern Type *CTempl_ParseTemplTemplParam(Type *t);
extern void CClass_CheckPathAccess(BClassList *bcl, void *unk, AccessType access);
extern BClassList *CClass_GetPathCopy(BClassList *path, Boolean flag);
extern Object *CClass_ThisSelfObject();
extern AccessType global_access;
extern HashNameNode *this_name_node;
extern void CParser_Setup();
extern Boolean CParser_IsConst(Type *type, UInt32 qual);
extern void CParser_Cleanup();
extern void SetupPrecompiler(Boolean flag);
extern void CleanupPrecompiler();
extern void SetupAssembler();
extern void CleanupAssembler();
extern void ObjGen_Setup();
extern void ObjGen_Finish();
extern void ObjGen_Cleanup();
extern void ObjGen_CodeCleanup();
extern void ObjGen_DeclareFloatConst(Object *obj);
extern void ObjGen_DeclareVectorConst(Object *obj);
extern void ObjGen_DeclareCodeLabel(Object *labelobj, SInt32 offset, Object *funcobj);
extern Boolean ObjGen_IsExported(Object *obj);
extern void PointerAnalysis_Setup();
extern void PointerAnalysis_Cleanup();
extern Boolean CPrep_Preprocess();
extern void cparser();
extern void CBrowse_Setup(CParams *param);
extern void CBrowse_Finish(CParams *param);
extern void CBrowse_Cleanup(CParams *param);
extern UInt32 CParser_GetTypeQualifiers(Type *type, UInt32 qual);
extern void CTemplClass_RegisterUsingDecl(TemplClass *tclass, Type *target, AccessType access);
extern void CodeGen_InsertSpecialMacros();
extern char *CodeGen_ExpandSpecialMacro(Macro *macro);
extern void CPrep_PreprocessDumpFileInfo(Boolean flag);
extern void CPrep_PreprocessDumpNewLine();
extern Boolean gForceSourceLoc;
extern void ObjGen_SegmentName(); // might take an arg, not sure since it's empty
extern void ObjGen_SrcBreakName(HashNameNode *name, SInt32 modDate, Boolean flag);
extern char *precomp_target_str;
extern Object *CParser_ParseObject();
extern void PointerAnalysis_PragmaMode();
extern void CExcept_Terminate();
extern void CExcept_ArrayInit();
extern void CExcept_Magic();
extern void CSOM_PragmaReleaseOrder();
extern void CSOM_PragmaClassVersion();
extern void CSOM_PragmaMetaClass();
extern void CSOM_PragmaCallStyle();
extern short GetPrec(short t);
extern short localcount;
extern Boolean InlineAsm_gccmode;
extern void initialize_aliases();
extern Statement *current_statement;
extern int pclist_bad_operand;
extern int n_real_registers[];
extern short pic_base_reg;
extern Object pic_base;
extern ObjectList *exceptionlist;
extern ObjectList *arguments;
extern ObjectList *locals;
extern ObjectList *toclist;
extern Boolean uses_globals;
extern Boolean requires_frame;
extern void assign_locals_to_memory(ObjectList *locals);
extern PCodeLabel *pic_base_pcodelabel;
extern void *make_alias(Object *obj, SInt32 offset, SInt32 size);
extern Boolean is_volatile_object(Object *obj);
extern Boolean is_pascal_object(Object *obj);
extern Boolean local_is_16bit_offset(Object *obj);
extern Boolean can_add_displ_to_local(Object *obj, SInt32 displ);
extern int local_base_register(Object *obj);
extern int disable_optimizer;
extern Boolean IsTempName(HashNameNode *name);
extern void assign_local_memory(Object *obj);
extern void move_varargs_to_memory();
extern Type stvoid;
extern TypePointer void_ptr;
extern int countexceptionactionregisters(ExceptionAction *exc);
extern void noteexceptionactionregisters(ExceptionAction *exc, PCodeArg *);
extern void recordexceptionactions(PCode *pc, ExceptionAction *exc);
extern SInt32 functionbodyoffset;
extern Object *CParser_NewRTFunc(Type *returntype, HashNameNode *name, Boolean unkflag, int argcount, ...);
extern SInt32 curstmtvalue;
extern Object *__memcpy_object;
extern void CInit_RewriteString(ENode *expr, Boolean flag);
extern int is_intrinsic_function_call(ENode *expr);
extern SInt32 I8_log2n(SInt64 value);
extern void PPCError_Error(int code);
enum {
INTRINSIC_8 = 8,
INTRINSIC_35 = 35,
INTRINSIC_36 = 36
};
enum {
CPU_PPC401,
@ -875,6 +484,11 @@ enum {
extern char *ScanFloat(char *input, double *output, Boolean *fail);
#define FITS_IN_SHORT(value) ( (value) == ((short) (value)) )
// should HIGH_PART have (short) around it?
#define HIGH_PART(value) ( (((value) >> 16) + (((value) & 0x8000) >> 15)) )
#define LOW_PART(value) ( (short) (value) )
#ifdef __MWERKS__
#pragma options align=reset
#endif

39
includes/compiler/CABI.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef COMPILER_CABI_H
#define COMPILER_CABI_H
#include "compiler/common.h"
#include "compiler/CDecl.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern short CABI_GetStructResultArgumentIndex(void);
extern Type *CABI_GetSizeTType(void);
extern Type *CABI_GetPtrDiffTType(void);
extern SInt16 CABI_StructSizeAlignValue(Type *type, SInt32 size);
extern void CABI_ReverseBitField(TypeBitfield *tbitfield);
extern void CABI_AddVTable(TypeClass *tclass);
extern SInt32 CABI_GetVTableOffset(TypeClass *tclass);
extern void CABI_LayoutClass(DeclE *decle, TypeClass *tclass);
extern void CABI_MakeDefaultArgConstructor(Object *obj, TypeClass *tclass);
extern ENode *CABI_MakeThisExpr(TypeClass *tclass, SInt32 offset);
extern SInt32 CABI_GetCtorOffsetOffset(TypeClass *tclass, TypeClass *base);
extern Object *CABI_ConstructorCallsNew(TypeClass *tclass);
typedef Statement *(*TransConstructorCallback)(Statement *stmt, TypeClass *tclass, TypeClass *base, SInt32 offset, Boolean flag);
extern void CABI_TransConstructor(Object *obj, Statement *stmt, TypeClass *tclass, TransConstructorCallback callback, Boolean flag);
extern void CABI_MakeDefaultConstructor(TypeClass *tclass, Object *obj);
extern void CABI_MakeDefaultCopyConstructor(TypeClass *tclass, Object *obj);
extern void CABI_MakeDefaultAssignmentOperator(TypeClass *tclass, Object *obj);
extern void CABI_TransDestructor(Object *obj1, Object *obj2, Statement *stmt, TypeClass *tclass);
extern void CABI_MakeDefaultDestructor(TypeClass *tclass, Object *obj);
extern void CABI_MakeLayeredDestructor(TypeClass *tclass, Object *obj);
extern Object *CABI_GetDestructorObject(Object *obj, int what);
extern void CABI_AddLayeredDestructors(TypeClass *tclass);
extern ENode *CABI_DestroyObject(Object *dtor, ENode *objexpr, UInt8 mode, Boolean flag1, Boolean flag2);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -0,0 +1,71 @@
#ifndef COMPILER_CCLASS_H
#define COMPILER_CCLASS_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct VTableObjectLink {
struct VTableObjectLink *next;
Object *methodobj;
SInt32 offset;
SInt32 xC;
} VTableObjectLink;
extern void CClass_Init(void);
extern void CClass_GenThunks(void);
extern UInt8 CClass_GetOverrideKind(TypeFunc *a, TypeFunc *b, Boolean errorflag);
extern Boolean CClass_IsEmpty(TypeClass *tclass);
extern Boolean CClass_IsNonStaticMemberFunc(TypeMethod *tmethod);
extern Object *CClass_DefaultConstructor(TypeClass *tclass);
extern Object *CClass_DummyDefaultConstructor(TypeClass *tclass);
extern ENode *CClass_DefaultConstructorCall(TypeClass *a, TypeClass *b, ENode *expr, SInt32 unkshortparam, Boolean flag1, Boolean flag2, Boolean *errorflag);
extern Object *CClass_AssignmentOperator(TypeClass *tclass);
extern Object *CClass_CopyConstructor(TypeClass *tclass);
extern NameSpaceObjectList *CClass_MemberObject(TypeClass *tclass, HashNameNode *name);
extern Object *CClass_Constructor(TypeClass *tclass);
extern Object *CClass_Destructor(TypeClass *tclass);
extern Boolean CClass_IsConstructor(Object *obj);
extern Boolean CClass_IsDestructor(Object *obj);
extern Boolean CClass_IsPODClass(TypeClass *tclass);
extern Boolean CClass_IsTrivialCopyClass(TypeClass *tclass);
extern Boolean CClass_IsTrivialCopyAssignClass(TypeClass *tclass);
extern Boolean CClass_ReferenceArgument(TypeClass *tclass);
extern BClassList *CClass_GetPathCopy(BClassList *path, Boolean is_global);
extern BClassList *CClass_AppendPath(BClassList *a, BClassList *b);
extern Boolean CClass_IsMoreAccessiblePath(BClassList *path1, BClassList *path2);
extern BClassList *CClass_GetBasePath(TypeClass *a, TypeClass *b, short *founddepth, Boolean *isambigbase);
extern Boolean CClass_IsBaseClass(TypeClass *a, TypeClass *b, short *founddepth, Boolean pathcheckflag, Boolean ambigerrorflag);
extern TypeClass *CClass_GetQualifiedClass(void);
extern ENode *CClass_AccessPathCast(BClassList *path, ENode *expr, Boolean flag);
extern ENode *CClass_ClassPointerCast(ENode *expr, TypeClass *a, TypeClass *b, Boolean typconflag, Boolean ambigerrorflag, Boolean pathcheckflag);
extern ENode *CClass_DirectBasePointerCast(ENode *expr, TypeClass *a, TypeClass *b);
extern SInt32 CClass_GetPathOffset(BClassList *path);
extern Boolean CClass_ClassDominates(TypeClass *a, TypeClass *b);
extern SInt32 CClass_VirtualBaseOffset(TypeClass *a, TypeClass *b);
extern SInt32 CClass_VirtualBaseVTableOffset(TypeClass *a, TypeClass *b);
extern SInt32 CClass_GetMemberOffset(TypeClass *tclass, HashNameNode *name, ObjMemberVar **obj);
extern Boolean CClass_OverridesBaseMember(TypeClass *tclass, HashNameNode *name, Object *obj);
extern void CClass_DefineCovariantFuncs(Object *method, CI_FuncData *ifuncdata);
extern void CClass_CheckOverrides(TypeClass *tclass);
extern void CClass_ClassDefaultFuncAction(TypeClass *tclass);
extern void CClass_ClassAction(TypeClass *tclass);
extern void CClass_MakeStaticActionClass(TypeClass *tclass);
extern Object *CClass_CheckPures(TypeClass *tclass);
extern void CClass_MemberDef(Object *obj, TypeClass *tclass);
extern Object *CClass_ThisSelfObject(void);
extern ENode *CClass_CreateThisSelfExpr(void);
extern void CClass_CheckPathAccess(BClassList *path, Object *obj, AccessType access);
extern void CClass_CheckStaticAccess(BClassList *path, TypeClass *tclass, AccessType access);
extern void CClass_CheckObjectAccess(BClassList *path, Object *obj);
extern void CClass_CheckEnumAccess(BClassList *path, ObjEnumConst *objec);
extern Type *CClass_CombineClassAccessQualifiers(Type *type, UInt32 qual1, UInt32 qual2, UInt32 *outflags);
extern ENode *CClass_AccessMember(ENode *classexpr, Type *type, UInt32 qual, SInt32 offset);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

127
includes/compiler/CDecl.h Normal file
View File

@ -0,0 +1,127 @@
#ifndef COMPILER_CDECL_H
#define COMPILER_CDECL_H
#include "compiler/common.h"
#include "compiler/tokens.h"
#include "compiler/types.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
// named because it's 0xE bytes big (hurr)
typedef struct DeclE {
ObjBase **objlist;
void *x4;
unsigned short x8;
unsigned short xA;
Boolean xC;
} DeclE;
struct DeclInfo {
Type *thetype;
UInt32 qual;
NameSpace *nspace;
HashNameNode *name;
Object *x10;
NameSpaceObjectList *x14;
void *x18;
void *x1C;
Type *x20;
ENode *x24;
TemplClass *x28;
TemplArg *expltargs;
void *x30;
void *x34;
void *x38;
Boolean x3C;
Boolean x3D;
short x3E;
short storageclass;
UInt8 section;
UInt8 exportflags;
Boolean x44;
Boolean x45;
Boolean x46;
Boolean x47;
Boolean x48;
Boolean x49;
Boolean x4A;
Boolean x4B;
Boolean x4C;
Boolean x4D;
Boolean x4E;
Boolean x4F;
Boolean x50;
Boolean x51;
Boolean has_expltargs;
Boolean x53;
Boolean x54;
Boolean x55;
Boolean x56;
Boolean x57;
FileOffsetInfo fileoffsetinfo;
};
typedef struct BigDeclInfo {
DeclInfo declinfo;
DeclInfo declinfo2;
Boolean xCC;
Boolean xCD;
} BigDeclInfo;
extern AccessType global_access;
extern FileOffsetInfo member_fileoffset;
extern Type *CDecl_NewStructType(SInt32 size, SInt16 align);
extern Type *CDecl_NewArrayType(Type *type, SInt32 size);
extern Type *CDecl_NewPointerType(Type *type);
extern Type *CDecl_NewRefPointerType(Type *type);
extern Type *CDecl_NewTemplDepType(TypeTemplDepType tdt);
extern void CDecl_SetResultReg(TypeFunc *tfunc);
extern void CDecl_SetFuncFlags(TypeFunc *tfunc, UInt32 flags);
extern void CDecl_NewConvFuncType(DeclInfo *declinfo);
extern void CDecl_CompleteType(Type *type);
extern Boolean IsCompleteType(Type *type);
extern Boolean CanAllocObject(Type *type);
extern Boolean CanCreateObject(Type *type);
extern void makethetypepointer(DeclInfo *declinfo, UInt32 qual);
extern void CDecl_AddThisPointerArgument(TypeFunc *tfunc, TypeClass *tclass);
extern void CDecl_MakePTMFuncType(TypeFunc *tfunc);
extern void CDecl_AddArgument(TypeFunc *tfunc, Type *argtype);
extern Boolean CDecl_CheckArrayIntegr(Type *type);
extern void CDecl_ParseDirectFuncDecl(DeclInfo *declinfo);
extern void makememberpointertype(DeclInfo *declinfo, TypeClass *tclass, UInt32 qual);
extern void CDecl_ScanPointer(DeclInfo *declinfo, NameSpace *nspace, Boolean flag);
extern void scandeclarator(DeclInfo *declinfo);
extern void conversion_type_name(DeclInfo *declinfo);
extern void MergeDefaultArgs(FuncArg *a, FuncArg *b);
extern void CheckDefaultArgs(FuncArg *args);
extern Object *CDecl_GetFunctionObject(DeclInfo *declinfo, NameSpace *nspace, Boolean *pflag, Boolean someotherflag);
extern void CDecl_TypedefDeclarator(DeclInfo *declinfo);
extern Boolean CDecl_FunctionDeclarator(DeclInfo *declinfo, NameSpace *nspace, Boolean flag, Boolean flag2);
extern void CDecl_ScanDeclarator(DeclInfo *declinfo);
extern void scandeclaratorlist(DeclInfo *declinfo);
extern void CDecl_ComputeUnderlyingEnumType(TypeEnum *tenum);
extern void scanenum(DeclInfo *declinfo);
extern void CDecl_ScanStructDeclarator(BigDeclInfo *bde);
extern void scanstruct(DeclInfo *declinfo, short structtype);
extern void CDecl_ExtractClassExportFlags(DeclInfo *declinfo, UInt8 flags);
extern TypeMethod *CDecl_MakeTypeMemberFunc(TypeFunc *tfunc, TypeClass *tclass, Boolean flag);
extern void CDecl_PackDeclInfo(PackedDeclInfo *packed, DeclInfo *declinfo);
extern void CDecl_UnpackDeclInfo(DeclInfo *declinfo, PackedDeclInfo *packed);
extern void CDecl_AddFriend(TypeClass *tclass, Object *friendfunc, TypeClass *friendclass);
extern void CDecl_CheckCtorIntegrity(FuncArg *args, TypeClass *tclass);
extern void CDecl_MakeVBaseList(TypeClass *tclass);
extern Boolean CDecl_CheckNewBase(TypeClass *a, TypeClass *b, Boolean flag);
extern TypeMethod *CDecl_MakeDefaultDtorType(TypeClass *tclass, Boolean is_virtual);
extern void CDecl_CompleteClass(DeclE *decle, TypeClass *tclass);
extern TypeClass *CDecl_DefineClass(NameSpace *nspace, HashNameNode *name, TypeClass *tclass, short mode, Boolean flag2, Boolean flag3);
extern void CDecl_ParseClassDeclSpec(UInt8 *declspec);
extern void CDecl_ParseClass(DeclInfo *declinfo, short mode, Boolean flag1, UInt8 class_declspec);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -311,6 +311,11 @@ typedef struct _CErrorBuffer {
UInt32 remaining;
} CErrorBuffer;
extern TStreamElement *cerror_locktoken;
extern char cerror_synchdata[32];
extern short cerror_synchoffset;
extern int CError_BreakPointcount;
extern void CError_Init();
extern void CError_SetErrorToken(TStreamElement *token);
extern void CError_SetNullErrorToken();
@ -354,7 +359,7 @@ extern void CError_OverloadedFunctionError(Object *obj, ObjectList *olst);
extern void CError_AbstractClassError(TypeClass *tclass);
extern void CError_Warning(int code, ...);
extern void CError_BreakPoint(const char *a, const char *b);
extern void CError_Internal();
extern void CError_Internal(char *filename, int line);
extern void CError_ExpressionTooComplex();
extern void CError_NoMem();
extern void CError_UserBreak();

237
includes/compiler/CExpr.h Normal file
View File

@ -0,0 +1,237 @@
#ifndef COMPILER_CEXPR_H
#define COMPILER_CEXPR_H
#include "compiler/common.h"
#include "compiler/enode.h"
#include "compiler/types.h"
#include "compiler/CScope.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct ConIteratorList {
struct ConIteratorList *next;
struct ConIterator *iter;
} ConIteratorList;
typedef struct ConIterator {
struct ConIterator *parent;
ConIteratorList *children;
TypeClass *tclass;
} ConIterator;
typedef struct ConversionIterator {
CScopeObjectIterator objiter;
ConIterator myconiter;
ConIterator *coniter;
} ConversionIterator;
enum {
CheckResult0,
CheckResult1,
CheckResult2,
CheckResult3,
CheckResult4
};
// Rename me to StdMatch?
typedef struct Match5 {
short x0;
short x2;
short x4;
short x6;
short x8;
} Match5;
typedef struct Match13 {
short x0;
short x2;
short x4;
short x6;
short x8;
short xA;
short xC;
short xE;
Match5 match5;
} Match13;
// CExpr.c
extern Boolean (*name_obj_check)(void *, Object *); // TODO figure out the right type
extern Boolean disallowgreaterthan;
// CExpr2.c
extern ENode *assign_node;
extern Boolean temp_reference_init;
// CExpr.c
extern void CExpr_RewriteConst();
extern void optimizecomm(ENode *expr);
extern short canadd(ENode *expr, SInt32 value);
extern ENode *checkreference(ENode *expr);
extern ENode *pointer_generation(ENode *expr);
extern void CExpr_PointerGeneration();
extern void oldassignmentpromotion();
extern ENode *argumentpromotion(ENode *expr, Type *type, short qual, Boolean flag);
extern ENode *classargument(ENode *expr);
extern ENodeList *CExpr_ScanExpressionList(Boolean flag);
extern void CExpr_DoExplicitConversion();
extern void CExpr_MakeNameLookupResultExpr();
extern void scansizeof();
extern void scanalignof();
extern ENode *getnodeaddress(ENode *expr, Boolean flag);
extern void getpointertomemberfunc();
extern void CExpr_New_ELOGNOT_Node();
extern void CExpr_New_EMONMIN_Node();
extern void CExpr_New_EBINNOT_Node();
extern ENode *unary_expression(void);
extern ENode *do_castnullcheck(ENode *a, ENode *b);
extern void CExpr_SafeClassPointerCast();
extern ENode *PointerToMemberCast(ENode *expr, TypeMemberPointer *tm1, TypeMemberPointer *tm2, Boolean flag);
extern void CExpr_MemberPointerConversion();
extern ENode *do_typecast(ENode *expr, Type *type, UInt32 qual);
extern void cast_expression();
extern void CExpr_New_EMUL_Node();
extern void CExpr_New_EDIV_Node();
extern void CExpr_New_EMODULO_Node();
extern void CExpr_New_EADD_Node();
extern void CExpr_New_ESUB_Node();
extern void CExpr_New_ESHL_Node();
extern void CExpr_New_ESHR_Node();
extern void CExpr_New_ELESS_Node();
extern void CExpr_New_ELESSEQU_Node();
extern void CExpr_New_EGREATER_Node();
extern void CExpr_New_EGREATEREQU_Node();
extern ENode *memberpointercompare(ENodeType t, ENode *left, ENode *right);
extern void CExpr_New_EEQU_Node();
extern void CExpr_New_ENOTEQU_Node();
extern void CExpr_New_EAND_Node();
extern void CExpr_New_EXOR_Node();
extern void CExpr_New_EOR_Node();
extern void CExpr_New_ELAND_Node();
extern void CExpr_New_ELOR_Node();
extern void CExpr_NewDyadicNode();
extern void CExpr_New_ECOND_Node();
extern ENode *assignment_expression(void);
extern ENode *conv_assignment_expression(void);
extern void CExpr_CheckUnusedExpression();
extern void s_expression();
extern ENode *expression(void);
extern CInt64 CExpr_IntegralConstExprType(Type **tint);
extern ENode *CExpr_IntegralConstOrDepExpr(void);
extern CInt64 CExpr_IntegralConstExpr(void);
extern void CExpr_CheckUnwantedAssignment();
extern void CExpr_ParseAsmExpr();
// CExpr2.c
typedef void (*CExprSearchCB)(ENode *expr);
typedef ENode *(*CExprReplaceCB)(ENode *expr);
extern void CExpr_SearchExprTree(ENode *expr, CExprSearchCB callback, int count, ...);
extern ENode *CExpr_SearchExprTreeReplace(ENode *expr, CExprReplaceCB callback, int count, ...);
extern Boolean CExpr_HasFuncCall(ENode *expr);
extern void CExpr_AliasTransform(ENode *expr);
extern ENode *CExpr_UnaryFloatExpression(ENode *expr);
extern ENode *CExpr_BinaryFloatExpression(ENode *expr);
extern ENode *CExpr_NewENode(ENodeType ty);
extern ENode *CExpr_NewTemplDepENode(TemplDepSubType t);
extern ENode *nullnode(void);
extern ENode *intconstnode(Type *type, SInt32 value);
extern ENode *stringconstnode(char *str);
extern ENode *forceintegral(ENode *expr);
extern ENode *makemonadicnode(ENode *inner, ENodeType ty);
extern ENode *makediadicnode(ENode *left, ENode *right, ENodeType ty);
extern ENode *makecommaexpression(ENode *left, ENode *right);
extern short iszero(ENode *expr);
extern short isnotzero(ENode *expr);
extern Boolean CExpr_IsOne(ENode *expr);
extern Boolean CExpr_AllBitsSet(ENode *expr);
extern ENode *CExpr_NewETEMPNode(Type *type, Boolean assign_id);
extern ENode *CExpr_GetETEMPCopy(ENode *expr);
extern ENode *integralpromote(ENode *expr);
extern CInt64 CExpr_IntConstConvert(Type *a, Type *b, CInt64 val);
extern ENode *promote(ENode *expr, Type *type);
extern void CExpr_ArithmeticConversion(ENode **left, ENode **right);
extern ENode *CExpr_TempModifyExpr(ENode *expr);
extern Boolean CExpr_IsLValue(ENode *expr);
extern ENode *CExpr_LValue(ENode *expr, Boolean flag1, Boolean flag2);
extern ENode *CExpr_MakeObjRefNode(Object *obj, Boolean flag);
extern ENode *create_objectrefnode(Object *obj);
extern ENode *create_objectnode2(Object *obj);
extern ENode *create_objectnode(Object *obj);
extern ENode *CExpr_IsTempConstruction(ENode *expr, Type *type, ENode **resultexpr);
extern ENode *CExpr_AdjustFunctionCall(ENode *expr);
extern ENode *funccallexpr(Object *func, ENode *arg1, ENode *arg2, ENode *arg3, ENode *arg4);
extern ENode *CExpr_FuncCallSix(Object *func, ENode *arg1, ENode *arg2, ENode *arg3, ENode *arg4, ENode *arg5, ENode *arg6);
extern void CExpr_MatchCV(Type *t1, UInt32 q1, Type *t2, UInt32 q2, Match13 *match);
extern Boolean CExpr_MatchAssign(Type *type, UInt32 qual, ENode *expr, Match13 *match);
extern ENode *CExpr_ClassPointerCast(BClassList *cls, ENode *expr, Boolean nullcheckflag);
extern ENode *CExpr_GetClassAccessNode(BClassList *a, BClassList *b, ENode *expr, Object *obj, AccessType access, Boolean flag);
extern ENode *CExpr_ConvertToBool(ENode *expr, Boolean flag);
extern void CExpr_ConversionIteratorInit(ConversionIterator *iter, TypeClass *tclass);
extern Object *CExpr_ConversionIteratorNext(ConversionIterator *iter);
extern void user_assign_check();
extern ENode *CExpr_ConvertToCondition(ENode *expr);
extern void CExpr_ConvertToIntegral();
extern void CExpr_CheckArithmConversion();
extern void get_address_of_temp_copy();
extern short assign_check(ENode *expr, Type *type, UInt32 qual, Boolean flag1, Boolean flag2, Boolean flag3);
extern void CExpr_MatchCompare();
extern void CExpr_GetFuncMatchArgs();
extern ENode *CExpr_GetDefaultArgument(ENode *funcexpr, FuncArg *arg);
extern ENode *CExpr_VarArgPromotion(ENode *expr, Boolean flag);
extern void CExpr_GenericFuncCall();
extern void CExpr_GenericPtmfCall();
extern void CExpr_MakeFunctionCall();
extern void CExpr_CheckOperatorConversion();
extern void CExpr_CheckOperator();
extern ENode *CExpr_ConstructObject(TypeClass *tclass, ENode *addr_expr, ENodeList *args, Boolean flag1, Boolean flag2, Boolean flag3, Boolean flag4, Boolean flag5);
extern void scannew();
extern void scandelete();
// CExprConvMatch.c
// static void CExpr_GetImplictObjectParamType();
// static void CExpr_GetParamType();
// static void CExpr_HasNParams();
// static void CExpr_TypeCompare();
// static void CExpr_IsReferenceCompatible();
// static void CExpr_IsBaseOf();
// static void CExpr_IsBetterClassConversion();
// static void CExpr_IsBetterStandardConv();
// static void CExpr_IsBetterImplicitConv();
// static void CExpr_SetupStandardConversionResult();
// static void CExpr_SetQualConversionResult();
// static void CExpr_OverloadFuncMatch();
// static void CExpr_StandardConversionMatch();
// static void CExpr_UserConversion();
// static void CExpr_UserConversionMatch();
// static void CExpr_ImplicitConversionMatch();
extern Boolean CExpr_CanImplicitlyConvert(ENode *expr, Type *type, UInt32 qual);
// static void CExpr_DerivedToBase();
// static void CExpr_ClassReferenceConversion();
// static void CExpr_BindToReference();
extern ENode *CExpr_Convert(ENode *expr, Type *type, UInt32 qual, Boolean flag1, Boolean flag2);
extern ENode *CExpr_AssignmentPromotion(ENode *expr, Type *type, UInt32 qual, Boolean flag);
// static void CExpr_IsBetterMatch();
// static void CExpr_MatchArgs();
// static void CExpr_GetMatchObject();
// static void CExpr_FindBestMatch();
extern void CExpr_FuncArgMatch();
// static void CExpr_BuildConversionTypeList();
// static void CExpr_NextPromotedIntegralType();
// static void CExpr_NextArithmeticType();
// static void CExpr_NextPromotedArithmeticType();
// static void CExpr_MatchBuiltin();
// static void CExpr_CheckIncDecBuiltin();
// static void CExpr_CheckUnaryBuiltin();
// static void CExpr_CheckBinaryBuiltin();
// static void CExpr_MatchOperands();
extern void CExpr_CondOperatorMatch();
extern void CExpr_OperatorMatch();
// static void CExpr_ClassCopyInit();
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

147
includes/compiler/CFunc.h Normal file
View File

@ -0,0 +1,147 @@
#ifndef COMPILER_CFUNC_H
#define COMPILER_CFUNC_H
#include "compiler/common.h"
#include "compiler/CScope.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct DeclBlock {
struct DeclBlock *next;
ExceptionAction *dobjstack; // is type right?
NameSpace *parent_nspace;
short index;
} DeclBlock;
struct CLabel {
CLabel *next;
Statement *stmt;
HashNameNode *uniquename;
HashNameNode *name;
PCodeLabel *pclabel;
//void *sicg_label;
};
typedef enum StatementType {
ST_NOP = 1,
ST_LABEL,
ST_GOTO,
ST_EXPRESSION,
ST_SWITCH,
ST_IFGOTO,
ST_IFNGOTO,
ST_RETURN,
ST_OVF,
ST_EXIT,
ST_ENTRY,
ST_BEGINCATCH,
ST_ENDCATCH,
ST_ENDCATCHDTOR,
ST_GOTOEXPR,
ST_ASM,
ST_BEGINLOOP,
ST_ENDLOOP,
ST_ILLEGAL
} StatementType;
enum {
StmtFlag_1 = 1
};
struct Statement {
Statement *next;
StatementType type;
char marked;
UInt8 flags;
UInt16 value;
ENode *expr;
CLabel *label;
ExceptionAction *dobjstack;
SInt32 sourceoffset;
HashNameNode *sourcefilepath;
};
typedef struct InitExpr {
struct InitExpr *next;
ENode *expr;
Object *object;
} InitExpr;
typedef struct CtorChain {
struct CtorChain *next;
UInt8 what;
ENode *objexpr;
union {
ClassList *base; // 0
VClassList *vbase; // 1
ObjMemberVar *membervar; // 2
} u;
} CtorChain;
typedef struct CFuncSave {
CScopeSave scope;
// lots of fields
} CFuncSave;
struct DeclThing {
Type *thetype;
UInt32 qual;
NameSpace *nspace;
CLabel *xC;
CLabel *x10;
};
extern FuncArg elipsis;
extern FuncArg oldstyle;
extern ObjectList *arguments;
extern ObjectList *locals;
extern short localcount;
extern SInt32 curstmtvalue;
extern SInt32 sourceoffset;
extern HashNameNode *sourcefilepath;
extern SInt32 functionbodyoffset;
extern HashNameNode *functionbodypath;
extern InitExpr *init_expressions;
extern CLabel *Labels;
extern CtorChain *ctor_chain;
extern Statement *curstmt;
extern DeclBlock *CFunc_NewDeclBlock(void);
extern void CFunc_RestoreBlock(DeclBlock *block);
extern void CFunc_SetupLocalVarInfo(Object *obj);
extern void CFunc_DefaultArg(Type *type, short qual, FuncArg *args);
extern Boolean CFunc_ParseFakeArgList(Boolean flag);
extern FuncArg *parameter_type_list(DeclInfo *declinfo);
extern CLabel *findlabel(void);
extern CLabel *newlabel(void);
extern Statement *CFunc_AppendStatement(StatementType sttype);
extern Statement *CFunc_InsertStatement(StatementType sttype, Statement *after);
extern Statement *CFunc_InsertBeforeStatement(StatementType sttype, Statement *before);
extern void CheckCLabels(void);
extern Object *create_temp_object(Type *type);
extern ENode *create_temp_node(Type *type);
extern ENode *create_temp_node2(Type *type);
extern void CFunc_WarnUnused(void);
extern void CFunc_CodeCleanup(Statement *stmt);
extern void CFunc_DestructorCleanup(Statement *stmt);
extern Statement *CFunc_GenerateLoop(Statement *stmt, Type *type, ENode *expr1, ENode *expr2, ENode *expr3, ENode *expr4, ENode (*callback)(ENode *, ENode *));
extern void CFunc_CompoundStatement(DeclThing *thing);
extern void CFunc_SetupNewFuncArgs(Object *obj, FuncArg *args);
extern NameSpace *CFunc_FuncGenSetup(Statement *stmt);
extern void CFunc_GetGlobalCompilerState(CFuncSave *state);
extern void CFunc_SetGlobalCompilerState(CFuncSave *state);
extern void CFunc_Gen(Statement *stmt, Object *obj, UInt8 unk);
extern void CFunc_CheckClassCtors(TypeClass *tclass);
extern void CFunc_ParseFuncDef(Object *obj, DeclInfo *declinfo, TypeClass *tclass, Boolean is_method, Boolean is_static, NameSpace *nspace);
extern void InitExpr_Register(ENode *expr, Object *object);
extern void CFunc_GenerateDummyFunction(Object *a);
extern void CFunc_GenerateSingleExprFunc(Object *a, ENode *expr);
extern void CFunc_GenerateDummyCtorFunc(Object *a, Object *b);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

77
includes/compiler/CInit.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef COMPILER_CINIT_H
#define COMPILER_CINIT_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef void (*ExprCB)(Type *type, ENode *expr, Boolean flag);
typedef void (*InitExprRegisterCB)(ENode *expr);
typedef void (*InsertExprCB)(ENode *expr);
// fix last arg
typedef ENode *(*RegisterObjectCB)(Type *type, Object *obj, SInt32 offset, void *);
typedef ENode *(*TempNodeCB)(Type *type, Boolean flag);
typedef struct OLinkList {
struct OLinkList *next;
Object *obj;
SInt32 offset;
SInt32 somevalue;
} OLinkList;
typedef struct PooledString {
struct PooledString *next;
Object *obj;
int offset;
char *data;
SInt32 size;
Boolean ispascal;
Boolean iswide;
} PooledString;
typedef struct InitInfo {
Object *obj;
OLinkList *list;
void *x8;
SInt32 expr_offset;
ExprCB expr_cb;
Boolean expr_cb_called;
Boolean x15;
Boolean x16;
InitExprRegisterCB init_expr_register_cb;
Object *obj1C;
InsertExprCB insert_expr_cb;
RegisterObjectCB register_object_cb;
char *buffer;
SInt32 size;
SInt32 bufferSize;
struct InitInfo *next;
} InitInfo;
extern TempNodeCB cinit_tempnodefunc;
extern InitInfo *cinit_initinfo;
#ifdef __MWERKS__
#pragma options align=reset
#endif
extern void CInit_Init(void);
extern Boolean CInit_RelocInitCheck(ENode *expr, Object **objptr, CInt64 *valptr, Boolean flag);
extern void CInit_ExportConst(Object *obj);
extern Statement *CInit_ConstructClassArray(Statement *stmt, TypeClass *tclass, Object *ctor, Object *dtor, ENode *firstarg, SInt32 count);
extern ENode *CInit_AutoObject(Object *obj, Type *type, UInt32 qual);
extern void CInit_InitializeAutoData(Object *obj, InsertExprCB insert_cb, RegisterObjectCB register_cb);
extern void CInit_InitializeStaticData(Object *obj, InitExprRegisterCB cb);
extern void CInit_InitializeData(Object *obj);
extern Object *CInit_DeclareString(char *data, SInt32 size, Boolean ispascal, Boolean iswide);
extern PooledString *CInit_DeclarePooledString(char *data, SInt32 size, Boolean ispascal);
extern PooledString *CInit_DeclarePooledWString(char *data, SInt32 size);
extern void CInit_RewriteString(ENode *expr, Boolean flag);
extern void CInit_DeclarePooledStrings(void);
extern void CInit_DeclareData(Object *obj, void *data, OLinkList *list, SInt32 size);
extern void CInit_DeclareReadOnlyData(Object *obj, void *data, OLinkList *list, SInt32 size);
extern void CInit_DefineTentativeData(void);
#endif

121
includes/compiler/CInline.h Normal file
View File

@ -0,0 +1,121 @@
#ifndef COMPILER_CINLINE_H
#define COMPILER_CINLINE_H
#include "compiler/common.h"
#include "compiler/tokens.h"
#include "compiler/CFunc.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct CI_Var {
HashNameNode *name;
Type *type;
UInt32 qual;
UInt8 sflags;
UInt8 xD;
UInt8 xE;
} CI_Var;
typedef struct CI_Switch {
int fix_me;
} CI_Switch;
typedef struct CI_Statement {
StatementType type;
UInt8 flags;
UInt16 value;
SInt32 sourceoffset;
HashNameNode *sourcefilepath;
ExceptionAction *dobjstack;
union {
SInt16 statementnum;
ENode *expr;
struct {
ENode *expr;
SInt16 statementnum;
} ifgoto;
CI_Switch *switchdata;
// TODO: Figure out the one for Inline ASM
} u;
} CI_Statement;
struct CI_FuncData {
short numarguments;
CI_Var *arguments;
short numlocals;
CI_Var *locals;
short numstatements;
CI_Statement *statements;
FileOffsetInfo fileoffset;
SInt32 symdecloffset;
SInt32 functionbodyoffset;
HashNameNode *functionbodypath;
SInt32 symdeclend;
Boolean can_inline;
};
typedef enum {
CI_ActionInlineFunc = 0,
CI_ActionMemberFunc = 1,
CI_ActionTemplateFunc = 2,
CI_ActionDefaultFunc = 3
} CI_ActionType;
typedef struct CI_Action {
struct CI_Action *next;
Object *obj;
union {
struct {
FileOffsetInfo fileoffset;
TStream stream;
TypeClass *tclass;
CI_ActionType actiontype;
} inlinefunc;
struct {
Type *a;
Type *b;
TemplateMember *tmemb;
} memberfunc;
struct {
TemplateFunction *func;
TemplFuncInstance *inst;
} templatefunc;
} u;
} CI_Action;
typedef enum {
CopyMode0,
CopyMode1,
CopyMode2,
CopyMode3,
CopyMode4
} CInlineCopyMode;
extern CI_Action *cinline_tactionlist;
extern void CInline_Init(void);
extern SInt32 CInline_GetLocalID(Object *obj);
extern Boolean CInline_ExpressionHasSideEffect(ENode *expr);
extern ENode *CInline_CopyExpression(ENode *expr, CInlineCopyMode mode);
extern void CInline_SerializeStatement(Statement *stmt);
extern Object *CInline_GetLocalObj(SInt32 id, Boolean flag);
extern SInt32 CInline_GetStatementNumber(Statement *first, Statement *stmt);
extern void CInline_PackIFunctionData(CI_FuncData *packed, Statement *stmt, Object *obj);
extern void CInline_UnpackIFunctionData(Object *obj, CI_FuncData *packed, Statement *stmt);
extern void CInline_AddDefaultFunctionAction(Object *obj);
extern void CInline_AddInlineFunctionAction(Object *obj, TypeClass *tclass, FileOffsetInfo *fileoffset, TStream *stream, Boolean flag);
extern void CInline_AddMemberFunctionAction(Object *obj, Type *a, Type *b, TemplateMember *tmemb);
extern void CInline_AddTemplateFunctionAction(Object *obj, TemplateFunction *func, TemplFuncInstance *inst);
extern void CInline_ObjectAddrRef(Object *obj);
extern void CInline_GenFunc(Statement *stmt, Object *obj, UInt8 unk);
extern Boolean CInline_CanFreeLHeap(void);
extern Boolean CInline_GenerateDeferredFuncs(void);
extern void CInline_Finish(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -13,6 +13,10 @@ extern const CInt64 cint64_min;
inline int CInt64_IsNegative(const CInt64 *n) {
return (n->hi & 0x80000000) != 0;
}
inline UInt32 CInt64_GetULong(const CInt64 *n) { // 42E660 in mwcppc.exe
return n->lo;
}
inline void CInt64_SetLong(CInt64 *pN, SInt32 n) {
pN->lo = n;
pN->hi = (n < 0) ? 0xFFFFFFFF : 0;
@ -22,7 +26,7 @@ inline void CInt64_SetULong(CInt64 *pN, UInt32 n) {
pN->hi = 0;
}
inline int CInt64_IsZero(CInt64 *n) {
inline Boolean CInt64_IsZero(CInt64 *n) {
//if (n->hi == 0 && n->lo == 0)
// return 1;
//else

View File

@ -0,0 +1,84 @@
#ifndef COMPILER_CMACHINE_H
#define COMPILER_CMACHINE_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern TypeIntegral stbool;
extern TypeIntegral stchar;
extern TypeIntegral stsignedchar;
extern TypeIntegral stunsignedchar;
extern TypeIntegral stwchar;
extern TypeIntegral stsignedshort;
extern TypeIntegral stunsignedshort;
extern TypeIntegral stsignedint;
extern TypeIntegral stunsignedint;
extern TypeIntegral stsignedlong;
extern TypeIntegral stunsignedlong;
extern TypeIntegral stsignedlonglong;
extern TypeIntegral stunsignedlonglong;
extern TypeIntegral stfloat;
extern TypeIntegral stshortdouble;
extern TypeIntegral stdouble;
extern TypeIntegral stlongdouble;
extern TypeStruct stvectorunsignedchar;
extern TypeStruct stvectorsignedchar;
extern TypeStruct stvectorboolchar;
extern TypeStruct stvectorunsignedshort;
extern TypeStruct stvectorsignedshort;
extern TypeStruct stvectorboolshort;
extern TypeStruct stvectorunsignedlong;
extern TypeStruct stvectorsignedlong;
extern TypeStruct stvectorboollong;
extern TypeStruct stvectorfloat;
extern TypeStruct stvectorpixel;
extern TypeStruct stvector;
extern void CMach_Configure(void);
extern SInt32 CMach_GetQUALalign(UInt32 qual);
extern SInt32 CMach_ArgumentAlignment(Type *type);
extern SInt32 CMach_AllocationAlignment(Type *type, UInt32 qual);
extern CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right);
extern CInt64 CMach_CalcIntMonadic(Type *type, short op, CInt64 val);
extern CInt64 CMach_CalcIntConvertFromFloat(Type *type, Float fval);
extern void CMach_InitIntMem(Type *type, CInt64 val, void *mem);
extern void CMach_InitVectorMem(Type *type, MWVector128 val, void *mem, Boolean flag);
extern Float CMach_CalcFloatDiadic(Type *type, Float left, short op, Float right);
extern Float CMach_CalcFloatMonadic(Type *type, short op, Float fval);
extern Boolean CMach_CalcFloatDiadicBool(Type *type, Float left, short op, Float right);
extern Boolean CMach_CalcVectorDiadicBool(Type *type, MWVector128 *left, short op, MWVector128 *right);
extern char *CMach_FloatScan(char *input, Float *result, Boolean *fail);
extern Float CMach_CalcFloatConvertFromInt(Type *type, CInt64 val);
extern Float CMach_CalcFloatConvert(Type *type, Float fval);
extern Boolean CMach_FloatIsZero(Float fval);
extern Boolean CMach_FloatIsOne(Float fval);
extern Boolean CMach_FloatIsNegOne(Float fval);
extern void CMach_InitFloatMem(Type *type, Float val, void *mem);
extern void CMach_PrintFloat(char *buf, Float val);
extern void CMach_PragmaParams(void);
extern void CMach_AdjustFuntionArgs(void);
extern SInt16 CMach_GetStructAlign(TypeStruct *tstruct);
extern SInt16 CMach_GetClassAlign(TypeClass *tclass);
extern SInt16 CMach_GetTypeAlign(Type *type);
extern SInt16 CMach_MemberAlignValue(Type *type, SInt32 var);
extern void CMach_StructLayoutInitOffset(SInt32 offset);
extern SInt32 CMach_StructLayoutGetCurSize(void);
extern SInt32 CMach_StructLayoutGetOffset(Type *type, UInt32 qual);
extern SInt32 CMach_StructLayoutBitfield(TypeBitfield *tbitfield, UInt32 qual);
extern UInt8 CMach_GetFunctionResultClass(TypeFunc *tfunc);
extern Boolean CMach_PassResultInHiddenArg(Type *type);
extern const char *CMach_GetCPU(void);
extern Boolean CMach_FloatIsPowerOf2(Float flt);
extern Float CMach_FloatReciprocal(Float flt);
extern SInt32 CMach_RoundedSizeOf(Object *object);
extern void CMach_ReInitRuntimeObjects(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -0,0 +1,35 @@
#ifndef COMPILER_CMANGLER_H
#define COMPILER_CMANGLER_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern HashNameNode *constructor_name_node;
extern HashNameNode *destructor_name_node;
extern HashNameNode *asop_name_node;
extern void CMangler_Setup(void);
extern HashNameNode *CMangler_BasicDtorName(void);
extern HashNameNode *CMangler_VBaseDtorName(void);
extern HashNameNode *CMangler_ArrayDtorName(void);
extern HashNameNode *CMangler_SDeleteDtorName(void);
extern HashNameNode *CMangler_DeleteDtorName(void);
extern char *CMangler_GetOperator(HashNameNode *opname);
extern HashNameNode *CMangler_OperatorName(short token);
extern HashNameNode *CMangler_VTableName(TypeClass *tclass);
extern HashNameNode *CMangler_RTTIObjectName(Type *type, UInt32 qual);
extern HashNameNode *CMangler_ThunkName(Object *obj, int a, int b, int c);
extern HashNameNode *CMangler_TemplateInstanceName(HashNameNode *basename, TemplArg *args);
extern void CMangler_MangleType(Type *type, UInt32 qual);
extern HashNameNode *CMangler_ConversionFuncName(Type *type, UInt32 qual);
extern HashNameNode *CMangler_GetCovariantFunctionName(Object *obj, Type *type);
extern HashNameNode *CMangler_GetLinkName(Object *obj);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

385
includes/compiler/CParser.h Normal file
View File

@ -0,0 +1,385 @@
#ifndef COMPILER_CPARSER_H
#define COMPILER_CPARSER_H
#include "compiler/common.h"
#include "compiler/enode.h"
#include "compiler/tokens.h"
#include "compiler/types.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
enum {
AlignMode0_Mac68k,
AlignMode1_Mac68k4byte,
AlignMode2_PPC,
AlignMode3_1Byte,
AlignMode4_2Byte,
AlignMode5_4Byte,
AlignMode6_8Byte,
AlignMode7_16Byte,
AlignMode8_Packed
};
// not sure how many of these are char and how many are unsigned char or Boolean
typedef struct COpts {
Boolean little_endian;
Boolean codegen_dynamic;
Boolean codegen_pic;
Boolean no_common;
char no_implicit_templates;
char absolutepath; // determines the path written to debug info
char x06; // linker/objgen related
short cpu;
char schedule_cpu;
unsigned char schedule_mode; // may be an enum??
SInt32 debuglisting;
char profile;
char traceback;
Boolean disable_registers;
char fp_contract;
Boolean no_register_save_helpers;
char ppc_unroll_speculative;
short ppc_unroll_instructions_limit;
short ppc_unroll_factor_limit;
Boolean altivec_model;
UInt8 x1B; // altivec/vrsave related
UInt8 code_alignment;
char x1D;
UInt8 x1E; // some register used in TOC_use_isel
UInt8 gen_fsel;
char ppc_opt_bclr_bcctr;
Boolean use_lmw_stmw;
char report_heap_info;
char misaligned_mem_access;
char switch_tables;
char prepare_compress;
char some_alignment; // used in CMach_AllocationAlignment
Boolean asmsemicolcomment;
Boolean asmpoundcomment;
StringPtr oldprefixname;
short inlinelevel;
int inline_max_size;
int inline_max_total_size;
char inline_bottom_up;
Boolean cplusplus;
Boolean ecplusplus;
Boolean objective_c;
char objc_strict;
Boolean ARM_conform;
char ARM_scoping;
Boolean require_prototypes;
Boolean trigraphs;
Boolean only_std_keywords;
Boolean enumsalwaysint;
Boolean ANSI_strict;
Boolean mpwc_relax;
Boolean mpwc_newline;
Boolean ignore_oldstyle;
Boolean cpp_extensions;
Boolean pointercast_lvalue;
char useRTTI;
char delete_exception;
char _4B;
Boolean oldalignment;
Boolean unsignedchars;
Boolean multibyteaware;
char autoinline;
char defer_codegen;
Boolean direct_to_som;
char som_env_check;
char som_call_opt;
Boolean booltruefalse;
char old_enum_mangler;
Boolean longlong;
Boolean longlong_enums;
char no_tfuncinline;
char _59;
Boolean flat_include;
char syspath_once;
Boolean always_import;
char simple_class_byval;
Boolean wchar_type;
Boolean vbase_ctor_offset;
char vbase_abi_v2;
Boolean def_inherited;
char template_patch;
char template_friends;
char faster_pch_gen;
Boolean array_new_delete;
Boolean dollar_identifiers;
char def_inline_tfuncs;
char arg_dep_lookup;
Boolean simple_prepdump;
char line_prepdump;
char fullpath_prepdump;
char old_mtemplparser;
char suppress_init_code;
Boolean reverse_bitfields;
Boolean c9x;
Boolean float_constants;
Boolean no_static_dtors;
Boolean longlong_prepeval;
Boolean const_strings;
char dumpir;
char experimental;
Boolean gcc_extensions;
char stdc_fp_contract;
char stdc_fenv_access;
char stdc_cx_limitedr;
Boolean old_argmatch;
char optEH;
char optEH2;
Boolean new_mangler;
char microsoft;
Boolean warningerrors;
Boolean pedantic;
char check_header_flags;
Boolean supress_warnings;
Boolean warn_illpragma;
Boolean warn_emptydecl;
char warn_possunwant;
char warn_unusedvar;
char warn_unusedarg;
Boolean warn_extracomma;
char warn_hidevirtual;
Boolean warn_largeargs;
char warn_implicitconv;
char warn_notinlined;
Boolean warn_structclass;
Boolean warn_padding;
char warn_no_side_effect;
char warn_resultnotused;
char warn_ptr_int_conv;
char align_mode;
Boolean align_array_members;
Boolean dont_reuse_strings;
Boolean pool_strings;
Boolean explicit_zero_data;
Boolean readonly_strings;
Boolean exceptions;
char _99;
char dont_inline;
char always_inline;
Boolean peephole;
char global_optimizer;
char side_effects;
Boolean internal;
Boolean import;
Boolean export;
Boolean lib_export;
char nosyminline;
char force_active;
char optimizationlevel;
Boolean optimize_for_size;
char optimizewithasm;
Boolean crippled;
char opt_common_subs;
char opt_loop_invariants;
char opt_propagation;
char opt_dead_assignments;
char opt_strength_reduction;
char opt_strength_reduction_strict;
char opt_dead_code;
char opt_lifetimes;
char _B1; // unused?
char opt_unroll_loops;
char opt_vectorize_loops;
char _B4; // amount of IRO passes?
char opt_pointer_analysis;
char opt_pointer_analysis_mode;
char loop_unroll_count;
char loop_unroll_size_threshold;
Boolean isGeneratingDebugInfo;
CWDataType pchCreator;
CWDataType pchType;
CWDataType text;
HashNameNode *forcedSegment; // when set by #pragma segment
} COpts;
typedef struct ParserTryBlock {
struct ParserTryBlock *next;
jmp_buf jmpbuf;
NameSpace *cscope_current;
TypeClass *cscope_currentclass;
Object *cscope_currentfunc;
TemplStack *ctempl_curinstance;
TStreamElement *cerror_locktoken;
Boolean cscope_is_member_func;
} ParserTryBlock;
typedef struct CallbackAction {
struct CallbackAction *next;
Object *obj;
TypeClass *tclass;
} CallbackAction;
extern FileOffsetInfo cparser_fileoffset;
extern TStreamElement symdecltoken;
extern ParserTryBlock *trychain;
extern Boolean inassembler;
extern Boolean dont_set_references;
extern TypeStruct ptmstruct;
extern TypeStruct catchinfostruct;
extern Boolean in_assembler;
extern Boolean illegalimplicitconversion;
extern Boolean in_func_arglist;
extern NameSpaceName *newp_fobj;
extern NameSpaceName *newa_fobj;
extern NameSpaceName *delp_fobj;
extern NameSpaceName *dela_fobj;
extern Object *newh_func;
extern Object *delh_func;
extern Object *copy_func;
extern Object *clear_func;
extern Object *Rgtid_func;
extern Object *Rdync_func;
extern Object *rt_ptmf_cast;
extern Object *rt_ptmf_cmpr;
extern Object *rt_ptmf_test;
extern Object *rt_ptmf_call;
extern Object *rt_ptmf_scall;
extern Object *rt_ptmf_call4;
extern Object *rt_ptmf_scall4;
extern Object *rt_ptmf_null;
extern Object *rt_som_new;
extern Object *rt_som_newcheck;
extern Object *rt_som_check;
extern Object *rt_som_glue1;
extern Object *rt_som_glue2;
extern Object *rt_som_glue3;
extern Object *carr_func;
extern Object *cnar_func;
extern Object *darr_func;
extern Object *dnar_func;
extern Object *dnar3_func;
extern Object *Xgreg_func;
extern Object *Xthrw_func;
extern Object *Xicth_func;
extern Object *Xecth_func;
extern Object *Xunex_func;
extern COpts copts;
extern struct GList name_mangle_list;
extern HashNameNode *no_name_node;
extern HashNameNode *temp_argument_name;
extern HashNameNode *this_name_node;
extern HashNameNode *self_name_node;
extern HashNameNode *vptr_name_node;
extern CallbackAction *callbackactions;
extern Boolean fatalerrors;
extern Boolean anyerrors;
extern jmp_buf errorreturn;
extern char string[256];
extern SInt32 compilererrornum;
extern SInt32 compilererrfile;
extern SInt32 compilererrline;
extern Type sttemplexpr;
extern Type stillegal;
extern Type stvoid;
extern TypePointer void_ptr;
extern TypeFunc rt_func;
enum {
ATOM_VOID = 1,
ATOM_CHAR,
ATOM_UCHAR,
ATOM_WCHAR,
ATOM_SHORT,
ATOM_USHORT,
ATOM_INT,
ATOM_UINT,
ATOM_LONG,
ATOM_ULONG,
ATOM_LONGLONG,
ATOM_ULONGLONG,
ATOM_FLOAT,
ATOM_SHORTDOUBLE,
ATOM_DOUBLE,
ATOM_LONGDOUBLE
};
extern Object *CParser_NewRTFunc(Type *rettype, HashNameNode *name, Boolean flag, int argcount, ...);
extern Boolean CParser_IsPublicRuntimeObject(Object *obj);
extern Object *CParser_FindPublicRuntimeObject(HashNameNode *name);
extern Boolean CParser_ReInitRuntimeObjects(Boolean is_precompiler);
extern void CParser_Setup(void);
extern void CParser_Cleanup(void);
extern short GetPrec(short token);
extern Boolean CParser_ParseOperatorName(short *token, Boolean flag1, Boolean flag2);
extern SInt32 CParser_GetUniqueID(void);
extern void CParser_PrintUniqueID(char *buf);
extern void CParser_SetUniqueID(SInt32 id);
extern HashNameNode *CParser_GetUniqueName(void);
extern HashNameNode *CParser_NameConcat(char *a, char *b);
extern HashNameNode *CParser_AppendUniqueName(char *prefix);
extern HashNameNode *CParser_AppendUniqueNameFile(char *prefix);
extern Boolean IsTempName(HashNameNode *name);
extern void CParser_UpdateObject(Object *object, DeclInfo *declinfo);
extern Object *CParser_NewObject(DeclInfo *declinfo);
extern Object *CParser_NewLocalDataObject(DeclInfo *declinfo, Boolean add_to_locals);
extern Object *CParser_NewGlobalDataObject(DeclInfo *declinfo);
extern Object *CParser_NewCompilerDefDataObject(void);
extern Object *CParser_NewFunctionObject(DeclInfo *declinfo);
extern Object *CParser_NewCompilerDefFunctionObject(void);
extern Object *CParser_NewAliasObject(Object *object, SInt32 offset);
extern FuncArg *CParser_NewFuncArg(void);
extern Type *atomtype(void);
extern Object *CParser_FindDeallocationObject(Type *type, FuncArg *args, Boolean flag1, Boolean flag2, Boolean *outflag);
extern short is_memberpointerequal(Type *a, Type *b);
extern short is_typeequal(Type *a, Type *b);
extern short iscpp_typeequal(Type *a, Type *b);
extern short CParser_CompareArgLists(FuncArg *a, FuncArg *b);
extern Boolean is_arglistsame(FuncArg *a, FuncArg *b);
extern short is_typesame(Type *a, Type *b);
extern Type *CParser_GetBoolType(void);
extern Type *CParser_GetWCharType(void);
extern short CParser_GetOperator(ENodeType t);
extern Boolean CParser_IsMoreCVQualified(UInt32 a, UInt32 b);
extern Boolean CParser_IsSameOrMoreCVQualified(UInt32 a, UInt32 b);
extern Boolean is_unsigned(Type *type);
extern StructMember *ismember(TypeStruct *tstruct, HashNameNode *name);
extern void appendmember(TypeStruct *tstruct, StructMember *member);
extern Boolean isdeclaration(UInt8 flag1, UInt8 flag2, UInt8 flag3, short token);
extern Boolean islookaheaddeclaration(void);
extern Type *CParser_ParseTypeID(UInt32 *qual, Boolean *flag);
extern Boolean CParser_TryFuncDecl(void);
extern Boolean CParser_TryParamList(Boolean flag);
extern Type *CParser_RemoveTopMostQualifiers(Type *type, UInt32 *qual);
extern UInt32 CParser_GetTypeQualifiers(Type *type, UInt32 qual);
extern UInt32 CParser_GetCVTypeQualifiers(Type *type, UInt32 qual);
extern Boolean CParser_IsConst(Type *type, UInt32 qual);
extern Boolean CParser_IsVolatile(Type *type, UInt32 qual);
extern Boolean is_const_object(Object *obj);
extern Boolean is_volatile_object(Object *obj);
extern Boolean CParserIsConstExpr(ENode *expr);
extern Boolean CParserIsVolatileExpr(ENode *expr);
extern Boolean CParser_HasInternalLinkage(Object *obj);
extern Boolean CParser_HasInternalLinkage2(Object *obj);
extern Boolean CParser_IsVirtualFunction(Object *obj, TypeClass **tclass, SInt32 *index);
extern Boolean is_pascal_object(Object *obj);
extern Boolean is_cfm_type(Type *type);
extern Boolean CParser_IsVTableObject(Object *obj);
extern void TypedefDeclInfo(DeclInfo *declinfo, Type *type, UInt32 qual);
extern void CParser_ParseAttribute(Type *type, DeclInfo *declinfo);
extern void CParser_ParseDeclSpec(DeclInfo *declinfo, Boolean flag);
extern Boolean CParser_CheckTemplateClassUsage(TemplClass *tmclass, Boolean flag);
extern void CParser_GetDeclSpecs(DeclInfo *di, Boolean flag);
extern void CParser_RegisterNonGlobalClass(TypeClass *tclass);
extern void CParser_RegisterSingleExprFunction(Object *func, ENode *expr);
extern void CParser_RegisterDummyCtorFunction(Object *func, Object *obj);
extern Boolean CParser_IsAnonymousUnion(DeclInfo *di, Boolean flag);
extern void CParser_CheckAnonymousUnion(DeclInfo *di, Boolean flag);
extern void CParser_NewCallBackAction(Object *obj, TypeClass *tclass);
extern void CParser_NewClassAction(TypeClass *tclass);
extern void CParser_CallBackAction(Object *obj);
extern Object *CParser_ParseObject(void);
extern void CParser_ParseGlobalDeclaration(void);
extern void cparser(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

122
includes/compiler/CPrep.h Normal file
View File

@ -0,0 +1,122 @@
#ifndef COMPILER_CPREP_H
#define COMPILER_CPREP_H
#include "compiler/common.h"
#include "compiler/tokens.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct Macro {
struct Macro *next;
HashNameNode *name;
void *c;
unsigned short xC;
Boolean is_special;
Boolean xF;
void *e;
} Macro;
typedef struct TokenStack {
char *pos;
char *macrostart;
Macro *macro;
Boolean macrocheck;
} TokenStack;
extern CParams *cparamblkptr;
extern short tk;
extern CInt64 tkintconst;
extern Float tkfloatconst;
extern char *tkstring;
extern HashNameNode *tkidentifier;
extern SInt32 tksize;
extern short ispascalstring;
extern short nlflag;
extern SInt32 lines;
extern Boolean spaceskip;
extern struct Macro **macrohashtable;
extern Boolean cprep_nomem_exit;
extern Boolean cprep_nostring;
extern Boolean cprep_eoltokens;
extern TokenStack tokenstack[128];
extern short tokenstacklevel;
extern CPrepFileInfo *cprep_cursymfile;
extern char *pos;
extern char *macropos;
extern char *nextcharpos;
extern unsigned char CPrep_SkipNewCommentChar;
extern Boolean preprocessing_only;
extern Handle stringmem;
extern SInt32 maxstringsize;
extern char cprep_idarray[256];
extern Boolean was_escchar;
extern Boolean macrocheck;
extern Boolean widestring;
extern Boolean at_linestart;
extern char *prep_file_start;
extern char *prep_file_end;
extern char *macrostart;
extern Boolean cprep_strconcat;
extern CPrepFileInfo *prep_file;
extern short filesp;
extern SInt32 linenumber;
extern struct GList pplist;
extern TStreamElement *ts_current;
extern SInt32 ts_preread_elements;
extern void CPrep_InsertSpecialMacro(Macro *macro, char *name);
extern void CPrep_InsertSpecialMacros(void);
extern void CPrep_RemoveSpecialMacros(void);
extern Boolean setupprep(void);
extern void cleanupprep(void);
extern void CPrep_TSBufferGrow(int amount);
extern void CPrep_TokenStreamGetState(SInt32 *state);
extern void CPrep_TokenStreamSetState(SInt32 *state);
extern void CPrep_UnLex(void);
extern void CPrep_TokenStreamSetCurState(SInt32 *state);
typedef void (*CPrepStreamFuncPtr)(TStreamElement *);
extern void CPrep_StreamGetBlock(TStream *stream, CPrepStreamFuncPtr func, int arg);
extern void CPrep_StreamGetSemicolon(TStream *stream, CPrepStreamFuncPtr func);
extern void CPrep_StreamGetTemplate(TStream *stream, CPrepStreamFuncPtr func);
extern void CPrep_StreamInsert(TStream *stream, SInt32 *state);
extern void CPrep_StreamRemove(TStream *stream, SInt32 *state);
extern void CPrep_RemoveTokens(SInt32 amount);
extern void CPrep_TokenStreamFlush(void);
extern TStreamElement *CPrep_CurStreamElement(void);
extern void CPrep_GetTokenContext(TStreamElement *token, CPrepFileInfo **tokenfile, SInt32 *selectionoffset, short *tokensize, SInt32 *linenumber, char *buf1, short *tokenoffset, short *tokenlength, char *buf2, short *lastarg);
extern void CPrep_Error(short code);
extern void CPrep_ErrorName(short code, const char *name);
extern void CPrep_Warning(short code);
extern void CPrep_WarningName(short code, const char *name);
extern void CPrep_ErrorMessage(int errTable, char *str, Boolean flag1, Boolean flag2);
extern void CPrep_ErrorMessageVA(int code, const char *format, va_list list, Boolean flag1, Boolean flag2);
extern void popfile(void);
extern void CPrep_SetSourceFile(FileOffsetInfo *foi);
extern HashNameNode *CPrep_GetSourceFilePath(CPrepFileInfo *fileinfo);
extern void CPrep_NewFileOffsetInfo(FileOffsetInfo *foi, TStreamElement *ts);
extern SInt32 CPrep_GetFileOffsetInfo(FileOffsetInfo *foi);
extern void CPrep_GetFileOffsetInfo2(FileOffsetInfo *foi, SInt32 *pLine, HashNameNode **pName);
extern void CPrep_ResetFileInfo(FileOffsetInfo *foi);
extern void CPrep_GetPrepPos(CPrepFileInfo **file, SInt32 *ppos);
extern UInt8 C_Compiler(CParams *param);
extern void poptokenseq(void);
extern void foundnl(void);
extern void newline(void);
extern short notendofline(void);
extern char *CPrep_GetFileName(char *buffer, Boolean flag1, Boolean flag2);
extern Boolean macrotest(void);
extern short CPrep_PragmaLex(Boolean no_err);
extern void CPrep_PushOption(SInt32 id, char value);
extern void CPrep_PopOption(SInt32 id);
extern void preprocessor(void);
extern SInt32 CPrep_BrowserTokenOffset(FileOffsetInfo *foi);
extern SInt32 CPrep_BrowserFileOffset(void);
extern void CPrep_BrowserFilePosition(CPrepFileInfo **fileinfo, SInt32 *offset);
extern CPrepFileInfo *CPrep_BrowserCurrentFile(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -0,0 +1,32 @@
#ifndef COMPILER_CPREPTOKENIZER_H
#define COMPILER_CPREPTOKENIZER_H
#include "compiler/common.h"
#include "compiler/tokens.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern short prepskipnextchar(void);
extern short prepnextchar(void);
extern short prepnextstringchar(char *str, Boolean flag);
extern void CPrep_MatchChar(char ch, Boolean flag);
extern char *CPrep_MatchChar2(char *start, char ch, Boolean flag);
extern short prepcurchar(void);
extern char *ReadIdentifier(char *p);
extern char *CPrep_SkipNewComment(char *str);
extern Boolean skipendoflinematch(char *str, short token);
extern void skipendofline(void);
extern void CPrep_SkipAsmComment(void);
extern short lookahead(void);
extern short lookahead_noeol(void);
extern short lex(void);
extern short plex(void);
extern short lexidentifier(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

107
includes/compiler/CScope.h Normal file
View File

@ -0,0 +1,107 @@
#ifndef COMPILER_CSCOPE_H
#define COMPILER_CSCOPE_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern Boolean cscope_is_member_func;
extern Object *cscope_currentfunc;
extern TypeClass *cscope_currentclass;
extern NameSpace *cscope_current;
extern NameSpace *cscope_root;
typedef struct CScopeSave {
NameSpace *current;
TypeClass *currentclass;
Object *currentfunc;
Boolean is_member_func;
} CScopeSave; // assumed name
typedef struct CScopeParseResult {
NameSpace *nspace_0;
HashNameNode *name_4;
Type *x8;
UInt32 xC; // qual
ObjBase *obj_10;
NameSpaceObjectList *nsol_14;
BClassList *bcl_18;
Boolean x1C;
Boolean x1D;
Boolean isambig;
Boolean x1F;
Boolean x20;
Boolean x21;
} CScopeParseResult;
typedef struct CScopeNSIterator {
NameSpace *nspace;
NameSpaceLookupList *lookup;
CScopeParseResult *result;
} CScopeNSIterator;
typedef struct CScopeObjectIterator {
NameSpace *nspace;
NameSpaceName *nextname;
NameSpaceObjectList *currlist;
int hashindex;
} CScopeObjectIterator;
extern void CScope_Setup(void);
extern void CScope_Cleanup(void);
extern void CScope_GetScope(CScopeSave *save);
extern void CScope_SetNameSpaceScope(NameSpace *nspace, CScopeSave *save);
extern void CScope_SetClassScope(TypeClass *cls, CScopeSave *save);
extern void CScope_SetClassDefScope(TypeClass *cls, CScopeSave *save);
extern void CScope_SetFunctionScope(Object *function, CScopeSave *save);
extern void CScope_SetMethodScope(Object *function, TypeClass *cls, Boolean unknownFlag, CScopeSave *save);
extern void CScope_RestoreScope(CScopeSave *saved);
extern Boolean CScope_IsEmptySymTable(void);
extern Boolean CScope_IsInLocalNameSpace(NameSpace *nspace);
extern NameSpaceObjectList *CScope_FindName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceName *CScope_FindNameSpaceName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceObjectList *CScope_InsertName(NameSpace *nspace, HashNameNode *name);
extern NameSpaceObjectList *CScope_ArgumentDependentNameLookup(NameSpaceObjectList *list, HashNameNode *name, ENodeList *argNodes, Boolean flag);
extern NameSpace *CScope_NewHashNameSpace(HashNameNode *name);
extern NameSpace *CScope_NewListNameSpace(HashNameNode *name, Boolean is_global);
extern NameSpace *CScope_FindNonClassNonFunctionNS(NameSpace *nspace);
extern NameSpace *CScope_FindGlobalNS(NameSpace *nspoce);
extern Boolean CScope_IsStdNameSpace(NameSpace *nspace);
extern Boolean CScope_IsEmptyNameSpace(NameSpace *nspace);
extern void CScope_MergeNameSpace(NameSpace *dst, NameSpace *src);
extern void CScope_AddObject(NameSpace *nspace, HashNameNode *name, ObjBase *obj);
extern void CScope_AddGlobalObject(Object *obj);
extern NameSpaceLookupList *CScope_BuildNameSpaceLookupList(NameSpace *nspace);
extern Boolean CScope_FindQualifiedClassMember(CScopeParseResult *result, TypeClass *tclass, HashNameNode *name);
extern Type *CScope_GetType(NameSpace *nspace, HashNameNode *name, UInt32 *qual);
extern Type *CScope_GetTagType(NameSpace *nspace, HashNameNode *name);
extern Boolean CScope_ParseExprName(CScopeParseResult *result);
extern Boolean CScope_ParseDeclName(CScopeParseResult *result);
extern Boolean CScope_ParseQualifiedNameSpace(CScopeParseResult *result, Boolean flag1, Boolean flag2);
extern Boolean CScope_ParseElaborateName(CScopeParseResult *result);
extern Boolean CScope_FindObject(NameSpace *nspace, CScopeParseResult *result, HashNameNode *name);
extern Boolean CScope_FindNonClassObject(NameSpace *nspace, CScopeParseResult *result, HashNameNode *name);
extern NameSpaceObjectList *CScope_FindObjectList(CScopeParseResult *result, HashNameNode *name);
extern Boolean CScope_PossibleTypeName(HashNameNode *name);
extern Boolean CScope_FindClassMemberObject(TypeClass *tclass, CScopeParseResult *result, HashNameNode *name);
extern void CScope_InitObjectIterator(CScopeObjectIterator *iterator, NameSpace *nspace);
extern ObjBase *CScope_NextObjectIteratorObject(CScopeObjectIterator *iterator);
extern NameSpaceObjectList *CScope_NextObjectIteratorObjectList(CScopeObjectIterator *iterator);
extern void CScope_DefineTypeTag(NameSpace *nspace, HashNameNode *name, Type *type);
extern Type *CScope_GetLocalTagType(NameSpace *nspace, HashNameNode *name);
extern Boolean CScope_FindTypeName(NameSpace *nspace, HashNameNode *name, CScopeParseResult *result);
extern NameSpaceObjectList *CScope_GetLocalObject(NameSpace *nspace, HashNameNode *name);
extern BClassList *CScope_GetClassAccessPath(BClassList *list, TypeClass *tclass);
extern Boolean CScope_ParseMemberName(TypeClass *tclass, CScopeParseResult *result, Boolean flag);
extern void CScope_AddClassUsingDeclaration(TypeClass *tclass, TypeClass *tclass2, HashNameNode *name, AccessType access);
extern void CScope_ParseUsingDeclaration(NameSpace *nspace, short access, Boolean flag);
extern void CScope_ParseNameSpaceAlias(HashNameNode *name);
extern void CScope_ParseUsingDirective(NameSpace *nspace);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -0,0 +1,79 @@
#ifndef COMPILER_CODEGEN_H
#define COMPILER_CODEGEN_H
#include "compiler/common.h"
#include "compiler/CPrep.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern Macro vecM;
extern Macro altivecM;
extern Object *gFunction;
extern PCodeLabel *returnlabel;
extern PCodeLabel *cleanreturnlabel;
extern Boolean needs_cleanup;
extern Statement *current_statement;
extern int has_catch_blocks;
extern int disable_optimizer;
extern SInt32 current_linenumber;
extern Boolean has_altivec_arrays;
extern short high_reg;
extern short low_reg;
extern short high_offset;
extern short low_offset;
extern short low_reg2;
extern short high_reg2;
extern PCodeLabel *pic_base_pcodelabel;
extern Object *dyld_stub_binding_helper;
extern Object *rt_cvt_fp2unsigned;
extern Object *rt_profile_entry;
extern Object *rt_profile_exit;
extern Object *rt_div2i;
extern Object *rt_div2u;
extern Object *rt_mod2i;
extern Object *rt_mod2u;
extern Object *rt_shr2i;
extern Object *rt_shr2u;
extern Object *rt_shl2i;
extern Object *rt_cvt_ull_dbl;
extern Object *rt_cvt_sll_dbl;
extern Object *rt_cvt_ull_flt;
extern Object *rt_cvt_sll_flt;
extern Object *rt_cvt_dbl_usll;
extern VarInfo *CodeGen_GetNewVarInfo(void);
extern Object *maketemporary(Type *type);
typedef void (*ArgumentProcessor)(Object *obj, short reg);
extern void process_arguments(ArgumentProcessor func, Boolean flag);
extern void move_assigned_argument(Object *obj, short reg);
extern void assign_labels();
extern void CodeGen_Generator();
extern void CodeGen_GenVDispatchThunk();
extern void CodeGen_SetupRuntimeObjects();
extern Boolean CodeGen_ReInitRuntimeObjects(Boolean is_precompiler);
extern Boolean CodeGen_IsPublicRuntimeObject(Object *obj);
extern void CodeGen_SOMStub();
extern void CodeGen_ParseDeclSpec(HashNameNode *identifier, DeclInfo *declinfo);
extern void CodeGen_ParsePragma(HashNameNode *name);
extern void CodeGen_UpdateObject(Object *object);
extern void CodeGen_UpdateBackEndOptions();
extern void CodeGen_objc_method_self_offset();
extern void CodeGen_objc_method_sel_offset();
extern void CodeGen_objc_method_arg_offset();
extern void CodeGen_objc_method_args_size();
extern void CodeGen_HandleIntrinsicCall();
extern void CodeGen_HandleTypeCast();
extern short CodeGen_AssignCheck(ENode *expr, Type *type, Boolean flag1, Boolean flag2);
extern void CodeGen_CollapseVectorExpression();
extern void CodeGen_InsertSpecialMacros();
extern char *CodeGen_ExpandSpecialMacro(Macro *macro);
extern void CodeGen_reportheapinfo();
extern void CodeGen_InitialSanityCheck();
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -0,0 +1,85 @@
#ifndef COMPILER_OPERANDS_H
#define COMPILER_OPERANDS_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
extern Float one_point_zero;
enum OperandType {
// Value in a register (identified by 'reg')
OpndType_GPR = 0,
// Uses 'reg', 'object, 'immOffset'
OpndType_GPR_ImmOffset = 1,
// Uses 'reg', 'regOffset'
OpndType_GPR_Indexed = 2,
// Value in two registers (identified by 'reg' and 'regHi')
OpndType_GPRPair = 3,
// Value at an absolute address (identified by 'abs_address')
OpndType_Absolute = 4,
// Value in a float register (identified by 'reg')
OpndType_FPR = 5,
// Value in a vector register (identified by 'reg')
OpndType_VR = 6,
// Condition value: 'reg' stores which condition register, and 'regOffset' is equal to ENOTEQU, EEQU, EGREATEREQU,
// ELESS, ELESS or ELESSEQU
OpndType_CRField = 7,
// Value of a symbol (identified by 'object')
OpndType_Symbol = 8,
// Reference to a location (at 'reg', offset using 'object' and 'immOffset')
OpndType_IndirectGPR_ImmOffset = 9,
// Reference to a location (at 'reg', offset using the value of register 'regOffset')
OpndType_IndirectGPR_Indexed = 0xA,
// Reference to a symbol (identified by 'object')
OpndType_IndirectSymbol = 0xB
};
// These are probably the same as the PCode Flags and can be unified?
enum {
OpndFlags_Const = 0x40,
OpndFlags_Volatile = 0x80
};
struct Operand {
enum OperandType optype;
SInt16 reg;
SInt16 regHi;
SInt16 regOffset;
SInt32 immOffset;
SInt32 abs_address;
Object *object;
UInt32 flags;
};
extern void load_immediate(short reg, SInt32 value);
extern void symbol_operand(Operand *op, Object *obj);
extern void indirect(Operand *op, ENode *expr);
extern void combine(Operand *opA, Operand *opB, short output_reg, Operand *opOut);
extern void coerce_to_addressable(Operand *op);
extern void Coerce_to_register(Operand *op, Type *type, short output_reg);
extern void coerce_to_register_pair(Operand *op, Type *type, short output_reg, short output_regHi);
extern void Coerce_to_fp_register(Operand *op, TypeIntegral *tint, short output_reg);
extern void Coerce_to_v_register(Operand *op, TypeStruct *tstruct, short output_reg);
extern void store(short reg, Operand *op, Type *type);
extern void store_pair(short reg, short regHi, Operand *op, Type *type);
extern void store_fp(short reg, Operand *op, TypeIntegral *tint);
extern void store_v(short reg, Operand *op, TypeStruct *tstruct);
extern void extend32(Operand *op, Type *type, short output_reg);
extern void extend64(Operand *op, Type *type, short output_reg, short output_regHi);
extern void load_floating_constant(short reg, TypeIntegral *type, double *data);
extern void convert_integer_to_floating(Operand *op, Boolean is_single, short output_reg);
extern void convert_unsigned_to_floating(Operand *op, Boolean is_single, short output_reg);
extern void convert_floating_to_integer(Operand *op, short output_reg);
extern void convert_floating_to_unsigned(Operand *op, short output_reg);
extern void extract_bitfield(Operand *input_op, TypeBitfield *tbitfield, short output_reg, Operand *output_op);
extern void insert_bitfield(short reg, Operand *op, TypeBitfield *tbitfield);
extern void load_address(short dest_reg, Operand *op);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

194
includes/compiler/PCode.h Normal file
View File

@ -0,0 +1,194 @@
#ifndef COMPILER_PCODE_H
#define COMPILER_PCODE_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#define PCODE_FLAG_SET_T(pcode) (((pcode)->flags & (fPCodeFlag1 | fPCodeFlag8)) ? (pcode)->flags : 0)
#define PCODE_FLAG_SET_F(pcode) (((pcode)->flags & (fPCodeFlag1 | fPCodeFlag8)) ? 0 : (pcode)->flags)
enum {
EffectRead = 1,
EffectWrite = 2
};
typedef enum {
PCOp_REGISTER,
PCOp_SYSREG,
PCOp_IMMEDIATE,
PCOp_MEMORY,
PCOp_LABEL,
PCOp_LABELDIFF,
PCOp_PLACEHOLDEROPERAND
} PCOpKind;
typedef enum {
RefType_0,
RefType_1,
RefType_2,
RefType_3,
RefType_4,
RefType_5,
RefType_6,
RefType_7,
RefType_8,
RefType_9,
RefType_A,
RefType_B,
RefType_C,
RefType_D
} PCRefType;
struct PCodeArg {
PCOpKind kind;
char arg;
union {
struct {
unsigned short effect;
short reg;
} reg;
struct {
SInt32 value;
Object *obj;
} imm;
struct {
SInt32 offset;
Object *obj;
} mem;
struct {
PCodeLabel *label;
} label;
struct {
SInt16 offset;
PCodeLabel *labelA;
PCodeLabel *labelB;
} labeldiff;
unsigned char placeholder[10]; // keep the size
} data;
};
struct PCode {
PCode *nextPCode;
PCode *prevPCode;
PCodeBlock *block;
unsigned int xx_C;
unsigned int _10;
int flags;
void *_18;
SInt32 sourceoffset;
short op;
short argCount;
PCodeArg args[0];
};
struct PCodeLabel {
PCodeLabel *nextLabel;
PCodeBlock *block;
short resolved;
short index;
};
typedef struct _PCLink {
struct _PCLink *nextLink;
struct PCodeBlock *block;
} PCLink;
struct PCodeBlock {
struct PCodeBlock *nextBlock;
struct PCodeBlock *prevBlock;
PCodeLabel *labels;
PCLink *predecessors;
PCLink *successors;
PCode *firstPCode;
PCode *lastPCode;
int blockIndex;
int codeOffset; // in bytes
int loopWeight;
short pcodeCount;
unsigned short flags;
};
/* PCode Flags */
enum {
fPCodeFlag1 = 1,
fPCodeFlag2 = 2,
fPCodeFlag4 = 4,
fPCodeFlag8 = 8,
fPCodeFlag10 = 0x10,
fPCodeFlag20 = 0x20,
// Always valid
fIsConst = 0x40,
fIsVolatile = 0x80,
fSideEffects = 0x100,
fPCodeFlag200 = 0x200, // ?
fPCodeFlag400 = 0x400, // ?
fPCodeFlag800 = 0x800, // ?
fPCodeFlag1000 = 0x1000, // ?
fCommutative = 0x2000,
fIsCSE = 0x4000,
fPCodeFlag8000 = 0x8000,
fPCodeFlag20000 = 0x20000, // ?
fPCodeFlag40000 = 0x40000, // ?
// Set 1 only
fLink = 0x1000000,
fBranchNotTaken = 0x4000000,
fBranchTaken = 0x8000000,
fAbsolute = 0x10000000,
// Set 2 only
fIsPtrOp = 0x20,
fOverflow = 0x800000,
fSetsCarry = 0x10000000,
// ??
fPCodeFlag8000000 = 0x8000000,
fPCodeFlag10000000 = 0x10000000,
fPCodeFlag20000000 = 0x20000000,
fPCodeFlag40000000 = 0x40000000,
fPCodeFlag80000000 = 0x80000000
};
enum {
fPCBlockFlag1 = 1, // prologue
fPCBlockFlag2 = 2, // epilogue
fPCBlockFlag4 = 4,
fPCBlockFlag8 = 8,
fPCBlockFlag10 = 0x10,
fPCBlockFlag20 = 0x20,
fPCBlockFlag4000 = 0x4000
};
extern PCodeBlock *pcbasicblocks;
extern PCodeBlock *pclastblock;
extern PCodeBlock *prologue;
extern PCodeBlock *epilogue;
extern PCodeBlock **depthfirstordering;
extern int pcblockcount;
extern int pcloopweight;
extern void initpcode();
extern PCode *makepcode(short op, ...);
extern void emitpcode(short op, ...);
extern PCode *copypcode(PCode *pcode);
extern PCodeLabel *makepclabel();
extern PCodeBlock *makepcblock();
extern void pclabel(PCodeBlock *block, PCodeLabel *label);
extern void pcbranch(PCodeBlock *block, PCodeLabel *label);
extern void pccomputepredecessors();
extern void deleteblock(PCodeBlock *block);
extern void deleteunreachableblocks();
extern void appendpcode(PCodeBlock *block, PCode *pcode);
extern void deletepcode(PCode *pcode);
extern void insertpcodebefore(PCode *anchor, PCode *newpcode);
extern void insertpcodeafter(PCode *anchor, PCode *newpcode);
extern void setpcodeflags(int flags);
extern void clearpcodeflags(int flags);
extern int pccomputeoffsets();
extern void computedepthfirstordering();
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
#ifndef COMPILER_PCODEUTILITIES_H
#define COMPILER_PCODEUTILITIES_H
#include "compiler/common.h"
extern void pcsetrecordbit(PCode *pc);
extern void pcsetsideeffects(PCode *pc);
extern void pcsetlinkbit(PCode *pc);
extern void branch_label(PCodeLabel *label);
extern void branch_conditional(short a, short compareop, short c, PCodeLabel *label);
extern void branch_always(PCodeLabel *label);
extern void branch_decrement_always(short opcode, PCodeLabel *label);
extern void branch_indirect(Object *obj);
extern int branch_count_volatiles(void);
extern PCodeArg *branch_record_volatiles(PCodeArg *arglist, UInt32 *masks);
extern void branch_subroutine(Object *obj, short add_nop, UInt32 *masks);
extern void branch_subroutine_ctr(UInt32 *masks);
extern void add_immediate(short dest_reg, short base_reg, Object *obj, short offset);
extern PCode *add_immediate_lo(short dest_reg, short base_reg, Object *obj, short offset, char add_to_block);
extern PCode *op_absolute_ha(short dest_reg, short base_reg, Object *obj, short offset, char add_to_block);
extern void load_store_register(short opcode, short dest_reg, short base_reg, Object *obj, SInt32 offset);
#endif

View File

@ -0,0 +1,60 @@
#ifndef COMPILER_STACKFRAME_H
#define COMPILER_STACKFRAME_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
enum ObjClass {
ObjClass0,
ObjClass1,
ObjClass2,
ObjClassMax
};
extern Boolean requires_frame;
extern Boolean makes_call;
extern Boolean uses_globals;
extern Boolean dynamic_stack;
extern Boolean large_stack;
extern Object *dummyvaparam;
extern void *dummyprofiler;
extern void init_stack_globals(void);
extern void init_frame_sizes(void);
extern void assign_local_memory(Object *obj);
extern void assign_locals_to_memory(ObjectList *first);
extern void compute_frame_sizes(void);
extern void generate_prologue(PCodeBlock *block);
extern void generate_epilogue(PCodeBlock *block, Boolean add_blr);
extern void allocate_dynamic_stack_space(Boolean flag1, int reg1, int reg2, SInt32 size);
extern char *generate_traceback(SInt32 funcsize, char *funcname, SInt32 *tbsize, Object *func);
extern void check_dynamic_aligned_frame(void);
extern void move_varargs_to_memory(void);
extern void assign_arguments_to_memory(Object *func, UInt8 mysteryFlag, Boolean hasVarargs);
extern SInt32 set_out_param_displ(SInt32 a, Type *type, Boolean flag, SInt32 *outvar, SInt32 b);
extern SInt32 out_param_displ_to_offset(SInt32 displ);
extern Boolean needs_frame(void);
extern void update_out_param_size(SInt32 size);
extern void estimate_out_param_size(SInt32 size);
extern void update_out_param_align(SInt32 align);
extern void update_in_param_align(SInt32 align);
extern void update_frame_align(SInt32 align);
extern SInt32 local_offset_32(Object *obj);
extern SInt16 local_offset_lo(Object *obj, SInt32 offset);
extern SInt16 local_offset_ha(Object *obj, SInt32 offset);
extern SInt16 local_offset_16(Object *obj);
extern Boolean local_is_16bit_offset(Object *obj);
extern int local_base_register(Object *obj);
extern Boolean is_large_frame(void);
extern void no_frame_for_asm(void);
extern Boolean can_add_displ_to_local(Object *obj, SInt32 displ);
extern SInt32 get_alloca_alignment(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

60
includes/compiler/TOC.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef COMPILER_TOC_H
#define COMPILER_TOC_H
#include "compiler/common.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
typedef struct CodeLabelList {
struct CodeLabelList *next;
Object *object;
CLabel *label;
} CodeLabelList;
extern ObjectList *toclist;
extern ObjectList *exceptionlist;
extern void *descriptorlist;
extern void *floatconstpool;
extern void *doubleconstpool;
extern ObjectList *floatconstlist;
extern void *vectorconstpool;
extern ObjectList *vectorconstlist;
extern Object toc0;
extern Boolean no_descriptors;
extern Object pic_base;
extern VarInfo pic_base_varinfo;
extern short pic_base_reg;
extern CodeLabelList *codelabellist;
extern void setupaddressing(void);
extern void createNonLazyPointer(Object *obj);
extern void referenceIndirectPointer(Object *obj);
extern Object *createIndirect(Object *obj, Boolean flag1, Boolean flag2);
extern Object *createfloatconstant(Type *type, Float *data);
extern Object *createvectorconstant(Type *type, MWVector128 *data);
extern void DeclarePooledConstants();
extern Object *CreateFloatConst(Type *type, Float *data, SInt32 *unkptr);
extern void dumpcodelabels(Object *func);
typedef struct COVCResult {
// this struct might be used in other places too???
short op1;
short op2;
unsigned char arg;
} COVCResult;
extern Boolean canoptimizevectorconst(MWVector128 *vecp, Type *type, COVCResult *result);
extern Boolean TOC_use_fsel(ENode *expr);
extern Boolean TOC_use_isel(ENode *expr, Boolean flag);
extern SInt32 GetSizeSkip(ENode *expr);
extern void Optimize64bitMath(ENode *expr);
extern void expandTOCreferences(Statement **stmts);
extern void resetTOCvarinfo(void);
extern Boolean needdescriptor(void);
extern Object *createstaticinitobject(void);
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -94,27 +94,34 @@ typedef enum Section {
SECT_MW_SWITCH = 30,
SECT_8BYTE_LITERALS = 31,
SECT_4BYTE_LITERALS = 32,
// one of these next 2 is missing in pro7
SECT_MOD_INIT_FUNC = 33,
SECT_MOD_TERM_FUNC = 34,
SECT_CONST = 35,
SECT_CONST_PTR = 36,
SECT_NONLAZY_PTRS = 37,
SECT_COMMON_VARS = 38,
SECT_16BYTE_LITERALS = 39,
SECT_TEXT_COALESCE = 40,
SECT_DATA_COALESCE = 41,
SECT_UDATA_COALESCE = 42,
SECT_CONST_COALESCE = 43,
SECT_CONST_PTR_COALESCE = 44,
SECT_CSTR_COALESCE = 45,
N_SECTIONS = 46
SECT_CONST = 34,
SECT_CONST_PTR = 35,
// everything after here is known ok
SECT_NONLAZY_PTRS = 36,
SECT_COMMON_VARS = 37,
SECT_16BYTE_LITERALS = 38,
SECT_TEXT_COALESCE = 39,
SECT_DATA_COALESCE = 40,
SECT_UDATA_COALESCE = 41,
SECT_CONST_COALESCE = 42,
SECT_CONST_PTR_COALESCE = 43,
SECT_CSTR_COALESCE = 44,
N_SECTIONS = 45
} Section;
typedef struct BClassList BClassList;
typedef struct CI_FuncData CI_FuncData;
typedef struct CLabel CLabel;
typedef struct ClassList ClassList;
typedef struct CParams CParams;
typedef struct DeclInfo DeclInfo;
typedef struct DeclThing DeclThing; // rename me please
typedef struct DefArgCtorInfo DefArgCtorInfo;
typedef struct DepName DepName;
typedef struct EMemberInfo EMemberInfo;
typedef struct ENode ENode;
typedef struct ENodeList ENodeList;
typedef struct ExceptionAction ExceptionAction;
@ -139,6 +146,11 @@ typedef struct Object Object;
typedef struct ObjectList ObjectList;
typedef struct ObjCInfo ObjCInfo;
typedef struct ObjCMethod ObjCMethod;
typedef struct Operand Operand;
typedef struct PackedDeclInfo PackedDeclInfo;
typedef struct PCode PCode;
typedef struct PCodeArg PCodeArg;
typedef struct PCodeBlock PCodeBlock;
typedef struct PCodeLabel PCodeLabel;
typedef struct PointsToFunction PointsToFunction;
typedef struct PTFList PTFList;
@ -166,6 +178,7 @@ typedef struct TypeClass TypeClass;
typedef struct TypeEnum TypeEnum;
typedef struct TypeFunc TypeFunc;
typedef struct TypeIntegral TypeIntegral;
typedef struct TypeList TypeList;
typedef struct TypeMemberPointer TypeMemberPointer;
typedef struct TypeMethod TypeMethod;
typedef struct TypePointer TypePointer;
@ -173,6 +186,7 @@ typedef struct TypeStruct TypeStruct;
typedef struct TypeTemplDep TypeTemplDep;
typedef struct VarInfo VarInfo;
typedef struct VarRecord VarRecord;
typedef struct VClassList VClassList;
// Common bits for templates
typedef enum TemplParamType {
@ -262,7 +276,12 @@ enum {
Q_BYCOPY = 0x2000,
Q_BYREF = 0x4000,
Q_ONEWAY = 0x8000,
Q_10000 = 0x10000,
Q_20000 = 0x20000,
Q_OVERLOAD = 0x40000, // weak
Q_80000 = 0x80000,
Q_RESTRICT = 0x200000,
Q_1000000 = 0x1000000,
Q_ALIGNED_1 = 0x2000000,
Q_ALIGNED_2 = 0x4000000,
Q_ALIGNED_4 = 0x6000000,
@ -280,4 +299,42 @@ enum {
Q_ALIGNED_MASK = 0x1E000000
};
enum {
EXPORT_FLAGS_INTERNAL = 0x10,
EXPORT_FLAGS_IMPORT = 0x20,
EXPORT_FLAGS_EXPORT = 0x40
};
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
struct CParams {
CWPluginContext context;
CWObjectData objectdata;
Handle objectDataHandle;
Handle browseDataHandle;
SInt32 pluginRequest;
SInt32 apiVersion;
FSSpec projectFile;
SInt32 projectFileCount;
SInt32 mainFileNumber;
FSSpec mainFileSpec;
const char *mainFileText;
SInt32 mainFileTextLength;
Boolean isPrecompiling;
Boolean isAutoPrecompiling;
Boolean isPreprocessing;
Boolean isGeneratingDebugInfo;
Boolean isCachingPrecompiledHeaders;
CWBrowseOptions browseOptions;
Boolean field276;
SInt16 mainFileID;
CWDataType targetOS;
CWDataType targetCPU;
char *targetName;
};
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -75,6 +75,7 @@ typedef enum ENodeType {
ESETCONST,
ENEWEXCEPTION,
ENEWEXCEPTIONARRAY,
EMYSTERY67, // no name???
EOBJLIST,
EMEMBER,
ETEMPLDEP,
@ -88,6 +89,15 @@ typedef enum ENodeType {
} ENodeType;
struct EMemberInfo {
BClassList *path;
ENodeList *nodes;
void *x8;
void *xC;
void *x10;
};
struct ENodeList {
ENodeList *next;
ENode *node;
@ -116,7 +126,7 @@ typedef union ENodeUnion {
ENodeList *args;
TypeFunc *functype;
} funccall;
ObjAccess objaccess;
//ObjAccess objaccess;
struct {
ENode *accessnode;
ENode *mfpointer;
@ -135,7 +145,7 @@ typedef union ENodeUnion {
struct {
SInt32 size;
char *data;
SInt32 segnum;
//SInt32 segnum; ??
char ispascal;
char ispacked;
} string;
@ -159,6 +169,10 @@ typedef union ENodeUnion {
Object *objref;
SInt32 offset;
} addr;
struct {
NameSpaceObjectList *list;
TemplArg *templargs;
} objlist;
void *inst;
MemInitializer *ctorinit;
Statement *stmt;
@ -187,7 +201,7 @@ typedef union ENodeUnion {
HashNameNode *name;
TemplArg *args;
} qualtempl;
ObjAccess objaccess;
//ObjAccess objaccess;
struct {
ENode *expr;
TStreamElement *token;
@ -197,7 +211,8 @@ typedef union ENodeUnion {
ENode *expr;
ENodeList *args;
} funccall;
struct {
// have my doubts about this one
/*struct {
Type *type;
UInt32 qual;
ENode *arraydim;
@ -205,7 +220,7 @@ typedef union ENodeUnion {
ENodeList *initlist;
Boolean is_global;
Boolean has_init;
} nw;
} nw;*/
struct {
ENode *expr;
Boolean is_global;
@ -242,7 +257,7 @@ typedef union ENodeUnion {
struct ENode {
ENodeType type;
UInt8 cost;
UInt16 flags; // &1, &2 correspond to quals
UInt16 flags;
Boolean ignored;
Boolean hascall;
// void *loc; - might not be in pro7?
@ -254,9 +269,16 @@ struct ENode {
enum {
ENODE_FLAG_CONST = Q_CONST,
ENODE_FLAG_VOLATILE = Q_VOLATILE,
ENODE_FLAG_QUALS = Q_CONST | Q_VOLATILE
ENODE_FLAG_QUALS = Q_CONST | Q_VOLATILE,
ENODE_FLAG_10 = 0x10,
ENODE_FLAG_80 = 0x80
};
#define ENODE_IS(_enode, _etype) ( (_enode)->type == (_etype) )
#define ENODE_IS2(_enode, _etype1, _etype2) ( ENODE_IS(_enode, (_etype1)) || ENODE_IS(_enode, (_etype2)) )
#define ENODE_IS3(_enode, _etype1, _etype2, _etype3) ( ENODE_IS(_enode, (_etype1)) || ENODE_IS(_enode, (_etype2)) || ENODE_IS(_enode, (_etype3)) )
#define ENODE_IS_RANGE(_enode, _lo, _hi) ( ((_enode)->type >= (_lo)) && ((_enode)->type <= (_hi)) )
#ifdef __MWERKS__
#pragma options align=reset
#endif

View File

@ -47,7 +47,7 @@ struct ObjType {
ObjectType otype;
AccessType access;
Type *type;
void *unk6;
UInt32 qual;
};
@ -184,6 +184,25 @@ struct Object {
} u;
};
enum {
OBJECT_FLAGS_UNUSED = 1,
OBJECT_FLAGS_2 = 2,
OBJECT_FLAGS_4 = 4,
OBJECT_FLAGS_8 = 8,
OBJECT_FLAGS_10 = 0x10, // internal
OBJECT_FLAGS_20 = 0x20, // import
OBJECT_FLAGS_40 = 0x40, // export
OBJECT_FLAGS_60 = 0x60 // lib export
};
enum {
OBJECT_SCLASS_101 = 0x101,
OBJECT_SCLASS_102 = 0x102,
OBJECT_SCLASS_103 = 0x103,
OBJECT_SCLASS_104 = 0x104,
OBJECT_SCLASS_12B = 0x12B
};
#define OBJ_BASE(obj) ((ObjBase *) (obj))
#define OBJ_ENUM_CONST(obj) ((ObjEnumConst *) (obj))
#define OBJ_TYPE(obj) ((ObjType *) (obj))
@ -193,8 +212,30 @@ struct Object {
#define OBJ_MEMBER_VAR_PATH(obj) ((ObjMemberVarPath *) (obj))
#define OBJECT(obj) ((Object *) (obj))
#endif
struct VarInfo { // OK!
Object *func;
SInt32 usage;
TStreamElement deftoken;
SInt16 varnumber;
Boolean noregister;
Boolean used;
UInt8 flags;
UInt8 rclass;
SInt16 reg;
SInt16 regHi;
};
enum {
VarInfoFlag1 = 1, // is parameter?
VarInfoFlag2 = 2,
VarInfoFlag4 = 4,
VarInfoFlag40 = 0x40,
VarInfoFlag80 = 0x80
};
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif

View File

@ -143,6 +143,10 @@ struct TemplClass {
UInt8 flags;
};
enum {
TEMPLCLASS_FLAGS_2 = 2
};
struct TemplClassInst {
TypeClass theclass;
TemplClassInst *next;
@ -150,7 +154,8 @@ struct TemplClassInst {
TemplClass *templ;
TemplArg *inst_args;
TemplArg *oargs;
void *x46;
Boolean x46;
Boolean x47;
};
#define TEMPL_CLASS(ty) ( (TemplClass *) (ty) )

View File

@ -39,7 +39,15 @@ typedef enum EToken {
TK_UNION,
TK_ENUM,
TK_CLASS,
TK_UU_VECTOR = 283,
TK_UNK_113,
TK_UNK_114,
TK_UNK_115,
TK_UNK_116,
TK_UNK_117,
TK_UNK_118,
TK_UNK_119,
TK_UNK_11A,
TK_UU_VECTOR,
TK_UU_TYPEOF_UU,
TK_BOOL,
TK_WCHAR_T,
@ -138,7 +146,9 @@ typedef enum EToken {
TK_AT_DEFS,
TK_SELF,
TK_SUPER,
TK_UU_ALIGNOF_UU = 388,
TK_NEW_ARRAY,
TK_DELETE_ARRAY,
TK_UU_ALIGNOF_UU,
TK_RESTRICT,
TK_UU_ATTRIBUTE_UU,
TK_UU_UUIDOF
@ -146,7 +156,7 @@ typedef enum EToken {
typedef struct FileOffsetInfo {
CPrepFileInfo *file;
SInt32 offset;
SInt32 tokenline;
SInt32 tokenoffset;
Boolean is_inline;
} FileOffsetInfo;

View File

@ -90,6 +90,7 @@ struct StructMember {
enum {
STRUCT_TYPE_STRUCT = 0,
STRUCT_TYPE_UNION = 1,
STRUCT_TYPE_CLASS = 2,
STRUCT_TYPE_4 = 4,
STRUCT_TYPE_5 = 5,
STRUCT_TYPE_6 = 6,
@ -104,23 +105,23 @@ enum {
};
typedef struct ClassList { // checked via CPrec
struct ClassList *next;
struct ClassList { // checked via CPrec
ClassList *next;
TypeClass *base;
SInt32 offset;
SInt32 voffset;
AccessType access;
Boolean is_virtual;
} ClassList;
};
typedef struct VClassList { // checked via CPrec
struct VClassList *next;
struct VClassList { // checked via CPrec
VClassList *next;
TypeClass *base;
SInt32 offset;
SInt32 voffset;
Boolean has_override;
char alignsave;
} VClassList;
};
typedef struct ClassFriend { // checked via CPrec
struct ClassFriend *next;
@ -162,14 +163,42 @@ struct TypeClass {
UInt8 eflags;
};
typedef enum {
CLASS_MODE_0 = 0,
CLASS_MODE_1 = 1,
CLASS_MODE_2 = 2
} ClassMode;
enum {
CLASS_FLAGS_1 = 1,
CLASS_FLAGS_2 = 2,
CLASS_FLAGS_ABSTRACT = 8,
CLASS_FLAGS_10 = 0x10,
CLASS_FLAGS_20 = 0x20,
CLASS_FLAGS_40 = 0x40,
CLASS_FLAGS_80 = 0x80,
CLASS_FLAGS_100 = 0x100, // is TemplClass
CLASS_FLAGS_800 = 0x800, // is TemplClassInst
CLASS_FLAGS_900 = 0x900
CLASS_FLAGS_900 = 0x900,
CLASS_FLAGS_1000 = 0x1000,
CLASS_FLAGS_2000 = 0x2000,
CLASS_FLAGS_4000 = 0x4000,
CLASS_FLAGS_8000 = 0x8000
};
/// maps to TypeClass::eflags
enum {
CLASS_EFLAGS_INTERNAL = 1,
CLASS_EFLAGS_IMPORT = 2,
CLASS_EFLAGS_EXPORT = 4
};
enum {
CLASS_ACTION_0 = 0,
CLASS_ACTION_1 = 1,
CLASS_ACTION_2 = 2,
CLASS_ACTION_3 = 3 // __javaobject
};
typedef struct ExceptSpecList {
struct ExceptSpecList *next;
@ -199,14 +228,29 @@ struct TypeFunc {
};
enum {
FUNC_FLAGS_PASCAL = 1, // on TypeFunc::flags
FUNC_FLAGS_2 = 2,
FUNC_FLAGS_4 = 4,
FUNC_FLAGS_8 = 8, // abstract?
FUNC_FLAGS_METHOD = 0x10,
FUNC_FLAGS_40 = 0x40, // func that's like "operator SomeOtherType()"
FUNC_FLAGS_80 = 0x80,
FUNC_FLAGS_100 = 0x100,
FUNC_FLAGS_200 = 0x200,
FUNC_FLAGS_NOTHROW = 0x400,
FUNC_FLAGS_800 = 0x800,
FUNC_FLAGS_1000 = 0x1000,
FUNC_FLAGS_2000 = 0x2000,
FUNC_FLAGS_100000 = 0x100000,
FUNC_FLAGS_900000 = 0x900000
FUNC_FLAGS_CONST = 0x8000,
FUNC_FLAGS_VOLATILE = 0x10000,
FUNC_FLAGS_100000 = 0x100000, // is template?
FUNC_FLAGS_800000 = 0x800000,
FUNC_FLAGS_900000 = 0x900000,
FUNC_FLAGS_4000000 = 0x4000000,
FUNC_FLAGS_10000000 = 0x10000000,
FUNC_FLAGS_F0000000 = 0xF0000000
};
// This is actually called TypeMemberFunc...
// There seems to be a version of this which adds a class pointer at the end
struct TypeMethod {
TypeType type;
@ -217,7 +261,7 @@ struct TypeMethod {
UInt32 qual;
UInt32 flags;
TypeClass *theclass;
void *x1E;
SInt32 x1E; // vtable offset?
void *x22;
Boolean x26;
};
@ -227,7 +271,7 @@ struct TypeBitfield {
TypeType type;
SInt32 size;
Type *bitfieldtype;
unsigned char unkA;
char unkA;
char unkB;
};
@ -305,7 +349,14 @@ struct TypePointer {
// ObjCID
struct TypeList {
TypeList *next;
Type *type;
};
// Not sure if these existed originally, but they'll help
#define TYPE(ty) ((Type *) (ty))
#define TYPE_INTEGRAL(ty) ((TypeIntegral *) (ty))
#define TYPE_ENUM(ty) ((TypeEnum *) (ty))
#define TYPE_STRUCT(ty) ((TypeStruct *) (ty))
@ -317,6 +368,34 @@ struct TypePointer {
#define TYPE_MEMBER_POINTER(ty) ((TypeMemberPointer *) (ty))
#define TYPE_POINTER(ty) ((TypePointer *) (ty))
#define IS_TYPE_VOID(ty) ( (ty)->type == TYPEVOID )
#define IS_TYPE_INT(ty) ( (ty)->type == TYPEINT )
#define IS_TYPE_ENUM(ty) ( (ty)->type == TYPEENUM )
#define IS_TYPE_INT_OR_ENUM(ty) ( IS_TYPE_INT(ty) || IS_TYPE_ENUM(ty) )
#define IS_TYPE_FLOAT(ty) ( (ty)->type == TYPEFLOAT )
#define IS_TYPE_STRUCT(ty) ( (ty)->type == TYPESTRUCT )
#define IS_TYPE_CLASS(ty) ( (ty)->type == TYPECLASS )
#define IS_TYPE_FUNC(ty) ( (ty)->type == TYPEFUNC )
#define IS_TYPEFUNC_METHOD(ty) ( (ty)->flags & FUNC_FLAGS_METHOD )
#define IS_TYPE_TEMPLATE(ty) ( (ty)->type == TYPETEMPLATE )
#define IS_TYPE_POINTER(ty) ( (ty)->type == TYPEPOINTER || (ty)->type == TYPEARRAY )
#define IS_TYPE_POINTER_ONLY(ty) ( (ty)->type == TYPEPOINTER )
#define IS_TYPE_REFERENCE(ty) ( (ty)->type == TYPEPOINTER && (TYPE_POINTER(ty)->qual & Q_REFERENCE) )
#define IS_TYPEPOINTER_REFERENCE(ty) ( (ty)->qual & Q_REFERENCE )
#define IS_TYPE_ARRAY(ty) ( (ty)->type == TYPEARRAY )
#define IS_TYPE_BITFIELD(ty) ( (ty)->type == TYPEBITFIELD )
#define IS_TYPESTRUCT_VECTOR(ty) ( (ty)->stype >= STRUCT_TYPE_4 && (ty)->stype <= STRUCT_TYPE_E )
#define IS_TYPE_VECTOR(ty) ( (ty)->type == TYPESTRUCT && IS_TYPESTRUCT_VECTOR(TYPE_STRUCT(ty)) )
#define IS_TYPE_NONVECTOR_STRUCT(ty) ( (ty)->type == TYPESTRUCT && !IS_TYPESTRUCT_VECTOR(TYPE_STRUCT(ty)) )
#define IS_TYPE_MEMBERPOINTER(ty) ( (ty)->type == TYPEMEMBERPOINTER )
#define IS_TYPE_4BYTES_MEMBERPOINTER(ty) ( ((ty)->type == TYPEMEMBERPOINTER) && ((ty)->size == 4u) )
#define IS_TYPE_12BYTES_MEMBERPOINTER(ty) ( ((ty)->type == TYPEMEMBERPOINTER) && ((ty)->size == 12u) )
#define TYPE_FITS_IN_REGISTER(ty) ( ((ty)->type == TYPEINT) || ((ty)->type == TYPEENUM) || (IS_TYPE_POINTER(ty) && ((ty)->type != TYPEARRAY)) || IS_TYPE_4BYTES_MEMBERPOINTER(ty) )
#define TYPE_IS_8BYTES(ty) ( (((ty)->type == TYPEINT) || ((ty)->type == TYPEENUM)) && ((ty)->size == 8) )
#define OBJ_GET_TARGET_VOLATILE(obj) ( IS_TYPE_POINTER((obj)->type) ? (TYPE_POINTER((obj)->type)->qual & Q_VOLATILE) : ((obj)->qual & Q_VOLATILE) )
#define OBJ_GET_TARGET_CONST(obj) ( IS_TYPE_POINTER((obj)->type) ? (TYPE_POINTER((obj)->type)->qual & Q_CONST) : ((obj)->qual & Q_CONST) )
#ifdef __MWERKS__
#pragma options align=reset
#endif

View File

@ -22,7 +22,7 @@ extern SInt32 COS_GetTicks();
extern SInt32 COS_GetTime();
extern void COS_GetString(char *buffer, SInt16 strListID, SInt16 index);
extern void COS_GetPString(StringPtr buffer, SInt16 strListID, SInt16 index);
extern Boolean COS_IsMultiByte(const char *str, int offset);
extern Boolean COS_IsMultiByte(const char *str1, const char *str2);
extern OSErr COS_FileNew(const FSSpec *spec, SInt16 *refNum, OSType creator, OSType fileType);
extern OSErr COS_FileOpen(const FSSpec *spec, SInt16 *refNum);
extern OSErr COS_FileGetType(const FSSpec *spec, OSType *fileType);

View File

@ -176,7 +176,7 @@ extern int OS_OpenLibrary(const char *a, void **lib);
extern int OS_GetLibrarySymbol(void *a, void *b, void **sym);
extern int OS_CloseLibrary(void *a);
extern int OS_LoadMacResourceFork(const OSSpec *spec, void **file_data, SInt32 *file_len);
extern Boolean OS_IsMultiByte(const char *str, int offset);
extern Boolean OS_IsMultiByte(const char *str1, const char *str2);
/********************************/
/* FileHandles */

50
notes
View File

@ -57,30 +57,30 @@ DONE compiler_and_linker/CmdLine_Tools/MacOS_PPC/Tools_PPC/Src/Plugin/libimp-ma
---- ?? TargetSetWarningFlags, TargetDisplayWarningOptions
---- WarningHelpers.c
---- CCompiler.c
---- CParser.c
DONE CCompiler.c
STUB CParser.c
DONE compiler_and_linker/FrontEnd/Common/CompilerTools.c (except for endian work)
---- CodeGenOptPPC.c
---- IrOptimizer.c
---- CodeGen.c
---- CPrep.c
---- CScope.c
---- CMachine.c
---- CExpr.c
---- CFunc.c
PART CodeGen.c
MOST CPrep.c
MOST CScope.c
MOST CMachine.c
STUB CExpr.c
STUB CFunc.c
---- CTemplateNew.c
STUB CError.c
---- ObjGenMachO.c
---- CDecl.c
---- CMangler.c
STUB CDecl.c
DONE CMangler.c
---- CSOM.c
---- CABI.c
---- CInit.c
---- CClass.c
STUB CABI.c
STUB CInit.c
STUB CClass.c
---- CIRTransform.c
---- CObjC.c
---- CInline.c
---- CPrepTokenizer.c
STUB CInline.c
PART CPrepTokenizer.c
---- CTemplateTools.c
---- IroPointerAnalysis.c
---- InstrSelection.c
@ -102,15 +102,15 @@ STUB CError.c
---- IroLoop.c
---- IroExprRegeneration.c
---- IroSubable.c
---- RegisterInfo.c
---- TOC.c
---- StackFrame.c
---- Register.sc
PART PCode.c
MOST RegisterInfo.c
MOST TOC.c
MOST StackFrame.c
MOST Registers.c
DONE PCode.c
---- Switch.c
---- ValueNumbering.c
---- PCodeUtilities.c
---- Operands.c
DONE PCodeUtilities.c
MOST Operands.c
---- Exceptions.c
---- ?? Dumping (DumpIR, DumpExpression, ...)
---- COptimizer.c
@ -122,9 +122,9 @@ PART PCode.c
---- PCodeAssembly.c
---- Intrinsics.c
---- PPCError.c
---- CExpr2.c
STUB CExpr2.c
DONE* CInt64.c
---- CPrec.c
PART CPrec.c
---- CBrowse.c
---- CPreprocess.c
---- FuncLevelAsmPPC.c
@ -140,7 +140,7 @@ DONE* CInt64.c
---- GenStabs.c
---- CTemplateFunc.c
---- IroMalloc.c
STUB PCodeInfo.c
PART PCodeInfo.c
---- StructMoves.c
---- FunctionCalls.c
---- IroBitVect.c

View File

@ -140,8 +140,8 @@ void COS_GetPString(StringPtr buffer, SInt16 strListID, SInt16 index) {
GetIndString((StringPtr) buffer, strListID, index);
}
Boolean COS_IsMultiByte(const char *str, int offset) {
return OS_IsMultiByte(str, offset);
Boolean COS_IsMultiByte(const char *str1, const char *str2) {
return OS_IsMultiByte(str1, str2);
}
OSErr COS_FileNew(const FSSpec *spec, SInt16 *refNum, OSType creator, OSType fileType) {