yet more fixes, some debugging code

This commit is contained in:
Ash Wolf 2023-01-13 13:40:30 +00:00
parent 7a5280b96b
commit 7a34d06bc7
8 changed files with 41 additions and 14 deletions

View File

@ -7,6 +7,8 @@ include_directories(.)
include_directories(includes) include_directories(includes)
include_directories(sdk_hdrs) include_directories(sdk_hdrs)
add_compile_definitions(CW_PATCH_DEBUG)
add_executable(mwcc add_executable(mwcc
command_line/CmdLine/Src/Clients/CLStaticMain.c command_line/CmdLine/Src/Clients/CLStaticMain.c
command_line/CmdLine/Src/Clients/ClientGlue.c command_line/CmdLine/Src/Clients/ClientGlue.c

View File

@ -1796,6 +1796,7 @@ static ENode *CExcept_TempTransExpr(ENode *expr) {
return expr; return expr;
case ELAND: case ELAND:
case ELOR: case ELOR:
case ECOMMA:
expr->data.diadic.left = CExcept_TempTransExpr(expr->data.diadic.left); expr->data.diadic.left = CExcept_TempTransExpr(expr->data.diadic.left);
expr->data.diadic.right = CExcept_TempTransExprCond(expr->data.diadic.right); expr->data.diadic.right = CExcept_TempTransExprCond(expr->data.diadic.right);
return expr; return expr;
@ -1829,7 +1830,6 @@ static ENode *CExcept_TempTransExpr(ENode *expr) {
case EANDASS: case EANDASS:
case EXORASS: case EXORASS:
case EORASS: case EORASS:
case ECOMMA:
case EROTL: case EROTL:
case EROTR: case EROTR:
expr->data.diadic.left = CExcept_TempTransExpr(expr->data.diadic.left); expr->data.diadic.left = CExcept_TempTransExpr(expr->data.diadic.left);
@ -1851,8 +1851,11 @@ static ENode *CExcept_TempTransExpr(ENode *expr) {
case EFLOATCONST: case EFLOATCONST:
case ESTRINGCONST: case ESTRINGCONST:
case EOBJREF: case EOBJREF:
case EMFPOINTER:
case EPRECOMP: case EPRECOMP:
case ELABEL: case ELABEL:
case EOBJLIST:
case EMEMBER:
case EINSTRUCTION: case EINSTRUCTION:
case EVECTOR128CONST: case EVECTOR128CONST:
return expr; return expr;

View File

@ -1244,7 +1244,7 @@ static void BasicBlockAnalyze(Statement *stmt) {
block->x1C = counter; block->x1C = counter;
continue; continue;
case ST_NOP: case ST_NOP:
case ST_GOTO: case ST_LABEL:
case ST_ENTRY: case ST_ENTRY:
if (stmt->next && stmt->next->type != ST_LABEL) { if (stmt->next && stmt->next->type != ST_LABEL) {
stmt = stmt->next; stmt = stmt->next;

View File

@ -343,7 +343,7 @@ static void WriteSymtabLoadCommand(void) {
cmd.cmdsize = CTool_EndianConvertWord32(sizeof(cmd)); cmd.cmdsize = CTool_EndianConvertWord32(sizeof(cmd));
cmd.symoff = CTool_EndianConvertWord32(FileOffset); cmd.symoff = CTool_EndianConvertWord32(FileOffset);
total = SymNum + NumStabs; total = SymNum + NumStabs;
cmd.nsyms = total; cmd.nsyms = CTool_EndianConvertWord32(total);
FileOffset += total * sizeof(struct nlist); FileOffset += total * sizeof(struct nlist);
cmd.stroff = CTool_EndianConvertWord32(FileOffset); cmd.stroff = CTool_EndianConvertWord32(FileOffset);
cmd.strsize = CTool_EndianConvertWord32(StringTable.size); cmd.strsize = CTool_EndianConvertWord32(StringTable.size);

View File

@ -1517,7 +1517,7 @@ void CodeGen_GenDynLinkStub(MachOSection *a, MachOSection *b, SInt32 relocID) {
if (copts.codegen_pic) { if (copts.codegen_pic) {
UInt32 i; UInt32 i;
for (i = 0; i < 9; i++) for (i = 0; i < 9; i++)
AppendGListLong(gl, pic_stub[i]); AppendGListLong(gl, CTool_EndianConvertWord32(pic_stub[i]));
pic_base_offset = offset + 8; pic_base_offset = offset + 8;
ObjGen_Relocate(a, offset + 16, relocID, RT_4, MW_RELOC_7_HA16); ObjGen_Relocate(a, offset + 16, relocID, RT_4, MW_RELOC_7_HA16);
ObjGen_Relocate(a, offset + 20, relocID, RT_4, MW_RELOC_5_LO16); ObjGen_Relocate(a, offset + 20, relocID, RT_4, MW_RELOC_5_LO16);
@ -1525,7 +1525,7 @@ void CodeGen_GenDynLinkStub(MachOSection *a, MachOSection *b, SInt32 relocID) {
} else { } else {
UInt32 i; UInt32 i;
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
AppendGListLong(gl, abs_stub[i]); AppendGListLong(gl, CTool_EndianConvertWord32(abs_stub[i]));
ObjGen_Relocate(a, offset, relocID, RT_4, MW_RELOC_7_HA16); ObjGen_Relocate(a, offset, relocID, RT_4, MW_RELOC_7_HA16);
ObjGen_Relocate(a, offset + 4, relocID, RT_4, MW_RELOC_5_LO16); ObjGen_Relocate(a, offset + 4, relocID, RT_4, MW_RELOC_5_LO16);
ObjGen_Relocate(a, offset + 12, relocID, RT_4, MW_RELOC_5_LO16); ObjGen_Relocate(a, offset + 12, relocID, RT_4, MW_RELOC_5_LO16);

View File

@ -284,6 +284,7 @@ PCode *vformatpcode(short opcode, va_list argList) {
format += pcode_const_from_format(format + 1, &thing); format += pcode_const_from_format(format + 1, &thing);
else else
CError_FATAL(319); CError_FATAL(319);
case 's':
tmp = va_arg(argList, int); tmp = va_arg(argList, int);
tmp2 = -1; tmp2 = -1;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -879,8 +880,8 @@ void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) {
buf += sprintf(buf, "!!!r"); buf += sprintf(buf, "!!!r");
} }
buf += sprintf(buf, "0"); buf += sprintf(buf, "0");
break;
} }
break;
case 'r': case 'r':
buf += expectandformatoperand(pa, PCOp_REGISTER, RegClass_GPR, -1, buf); buf += expectandformatoperand(pa, PCOp_REGISTER, RegClass_GPR, -1, buf);
break; break;
@ -956,7 +957,7 @@ void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) {
break; break;
case 'Q': case 'Q':
buf += expectandformatoperand(pa, PCOp_REGISTER, RegClass_SPR, -1, buf); buf += expectandformatoperand(pa, PCOp_REGISTER, RegClass_CRFIELD, -1, buf);
*(buf++) = ','; *(buf++) = ',';
pa++; pa++;
arg_index++; arg_index++;
@ -999,9 +1000,11 @@ void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) {
case 't': case 't':
if (pa->kind == PCOp_IMMEDIATE && pa->data.imm.value > 0 && pa->data.imm.value < 31 && (name = to[pa->data.imm.value])[0]) { if (pa->kind == PCOp_IMMEDIATE && pa->data.imm.value > 0 && pa->data.imm.value < 31 && (name = to[pa->data.imm.value])[0]) {
buf += sprintf(buf, "%s", name); buf += sprintf(buf, "%s", name);
} else { break;
buf += expectandformatoperand(pa, PCOp_IMMEDIATE, 'x', 5, buf);
} }
case 'B':
buf += expectandformatoperand(pa, PCOp_IMMEDIATE, 'x', 5, buf);
break; break;
case 'l': case 'l':

View File

@ -48,10 +48,10 @@ static void pclistblock(PCodeBlock *block, char *format, UInt32 vecSize) {
PCLink *link; PCLink *link;
PCodeLabel *label; PCodeLabel *label;
int cpu; int cpu;
int chr; // r21 int chr;
PCode *instr; // r20 PCode *instr;
int offset; // r19 int offset;
int latency; // r18 int latency;
UInt32 opcode; UInt32 opcode;
MachineInfo *mi; MachineInfo *mi;
char buf[500]; char buf[500];
@ -150,9 +150,28 @@ void pcinitlisting() {
} }
void pccleanuplisting(void) { void pccleanuplisting(void) {
#ifdef CW_PATCH_DEBUG
// this code is not based on the original as we don't have it
if (pcfile) {
fclose(pcfile);
pcfile = NULL;
}
#endif
} }
void pclistblocks(char *name1, char *name2) { void pclistblocks(char *name1, char *name2) {
#ifdef CW_PATCH_DEBUG
// this code is not based on the original as we don't have it
if (!pcfile) {
PCodeBlock *block;
pcfile = fopen("pcdump.txt", "a");
fprintf(pcfile, "\n%s\n%s\n", name1, name2);
for (block = pcbasicblocks; block; block = block->nextBlock)
pclistblock(block, NULL, 0);
}
#endif
} }
void pclistdataflow() { void pclistdataflow() {

View File

@ -2353,7 +2353,7 @@ static void adjustforward(PCodeBlock *block) {
} else if ( } else if (
instr->op == PC_EXTSB && instr->op == PC_EXTSB &&
(reg0 = instr->args[0].data.reg.reg) == (reg1 = instr->args[1].data.reg.reg) (reg0 = instr->args[0].data.reg.reg) != (reg1 = instr->args[1].data.reg.reg)
) )
{ {
short flag = 0; short flag = 0;