Added conditional attribute to instruction tracing.

This uses a lot less directive spam at the cost of the function still
being compiled into the IL in release.
This commit is contained in:
arookas 2016-03-08 16:20:13 -05:00
parent 23aee05fb4
commit c556939972

View file

@ -138,198 +138,138 @@ namespace arookas {
case 0: WriteINT0(); return; case 0: WriteINT0(); return;
case 1: WriteINT1(); return; case 1: WriteINT1(); return;
} }
#if DEBUG
TraceInstruction("int {0} # ${0:X}", value); TraceInstruction("int {0} # ${0:X}", value);
#endif
mText.Writer.Write8(0x00); mText.Writer.Write8(0x00);
mText.Writer.WriteS32(value); mText.Writer.WriteS32(value);
} }
public override void WriteFLT(float value) { public override void WriteFLT(float value) {
#if DEBUG
TraceInstruction("flt {0}", value); TraceInstruction("flt {0}", value);
#endif
mText.Writer.Write8(0x01); mText.Writer.Write8(0x01);
mText.Writer.WriteF32(value); mText.Writer.WriteF32(value);
} }
public override void WriteSTR(int index) { public override void WriteSTR(int index) {
#if DEBUG
TraceInstruction("str {0}", index); TraceInstruction("str {0}", index);
#endif
mText.Writer.Write8(0x02); mText.Writer.Write8(0x02);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
} }
public override void WriteADR(uint value) { public override void WriteADR(uint value) {
#if DEBUG
TraceInstruction("adr ${0:X8}", value); TraceInstruction("adr ${0:X8}", value);
#endif
mText.Writer.Write8(0x03); mText.Writer.Write8(0x03);
mText.Writer.Write32(value); mText.Writer.Write32(value);
} }
public override void WriteVAR(int display, int index) { public override void WriteVAR(int display, int index) {
#if DEBUG
TraceInstruction("var {0} {1}", display, index); TraceInstruction("var {0} {1}", display, index);
#endif
mText.Writer.Write8(0x04); mText.Writer.Write8(0x04);
mText.Writer.WriteS32(display); mText.Writer.WriteS32(display);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
} }
public override void WriteNOP() { public override void WriteNOP() {
#if DEBUG
TraceInstruction("nop"); TraceInstruction("nop");
#endif
mText.Writer.Write8(0x05); mText.Writer.Write8(0x05);
} }
public override void WriteINC(int display, int index) { public override void WriteINC(int display, int index) {
#if DEBUG
TraceInstruction("inc {0} {1}", display, index); TraceInstruction("inc {0} {1}", display, index);
#endif
mText.Writer.Write8(0x06); mText.Writer.Write8(0x06);
mText.Writer.WriteS32(display); mText.Writer.WriteS32(display);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
} }
public override void WriteDEC(int display, int index) { public override void WriteDEC(int display, int index) {
#if DEBUG
TraceInstruction("dec {0} {1}", display, index); TraceInstruction("dec {0} {1}", display, index);
#endif
mText.Writer.Write8(0x07); mText.Writer.Write8(0x07);
mText.Writer.WriteS32(display); mText.Writer.WriteS32(display);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
} }
public override void WriteADD() { public override void WriteADD() {
#if DEBUG
TraceInstruction("add"); TraceInstruction("add");
#endif
mText.Writer.Write8(0x08); mText.Writer.Write8(0x08);
} }
public override void WriteSUB() { public override void WriteSUB() {
#if DEBUG
TraceInstruction("sub"); TraceInstruction("sub");
#endif
mText.Writer.Write8(0x09); mText.Writer.Write8(0x09);
} }
public override void WriteMUL() { public override void WriteMUL() {
#if DEBUG
TraceInstruction("mul"); TraceInstruction("mul");
#endif
mText.Writer.Write8(0x0A); mText.Writer.Write8(0x0A);
} }
public override void WriteDIV() { public override void WriteDIV() {
#if DEBUG
TraceInstruction("div"); TraceInstruction("div");
#endif
mText.Writer.Write8(0x0B); mText.Writer.Write8(0x0B);
} }
public override void WriteMOD() { public override void WriteMOD() {
#if DEBUG
TraceInstruction("mod"); TraceInstruction("mod");
#endif
mText.Writer.Write8(0x0C); mText.Writer.Write8(0x0C);
} }
public override void WriteASS(int display, int index) { public override void WriteASS(int display, int index) {
#if DEBUG
TraceInstruction("ass {0} {1}", display, index); TraceInstruction("ass {0} {1}", display, index);
#endif
mText.Writer.Write8(0x0D); mText.Writer.Write8(0x0D);
mText.Writer.Write8(0x04); // unused (skipped over by TSpcInterp) mText.Writer.Write8(0x04); // unused (skipped over by TSpcInterp)
mText.Writer.WriteS32(display); mText.Writer.WriteS32(display);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
} }
public override void WriteEQ() { public override void WriteEQ() {
#if DEBUG
TraceInstruction("eq"); TraceInstruction("eq");
#endif
mText.Writer.Write8(0x0E); mText.Writer.Write8(0x0E);
} }
public override void WriteNE() { public override void WriteNE() {
#if DEBUG
TraceInstruction("ne"); TraceInstruction("ne");
#endif
mText.Writer.Write8(0x0F); mText.Writer.Write8(0x0F);
} }
public override void WriteGT() { public override void WriteGT() {
#if DEBUG
TraceInstruction("gt"); TraceInstruction("gt");
#endif
mText.Writer.Write8(0x10); mText.Writer.Write8(0x10);
} }
public override void WriteLT() { public override void WriteLT() {
#if DEBUG
TraceInstruction("lt"); TraceInstruction("lt");
#endif
mText.Writer.Write8(0x11); mText.Writer.Write8(0x11);
} }
public override void WriteGE() { public override void WriteGE() {
#if DEBUG
TraceInstruction("ge"); TraceInstruction("ge");
#endif
mText.Writer.Write8(0x12); mText.Writer.Write8(0x12);
} }
public override void WriteLE() { public override void WriteLE() {
#if DEBUG
TraceInstruction("le"); TraceInstruction("le");
#endif
mText.Writer.Write8(0x13); mText.Writer.Write8(0x13);
} }
public override void WriteNEG() { public override void WriteNEG() {
#if DEBUG
TraceInstruction("neg"); TraceInstruction("neg");
#endif
mText.Writer.Write8(0x14); mText.Writer.Write8(0x14);
} }
public override void WriteNOT() { public override void WriteNOT() {
#if DEBUG
TraceInstruction("not"); TraceInstruction("not");
#endif
mText.Writer.Write8(0x15); mText.Writer.Write8(0x15);
} }
public override void WriteAND() { public override void WriteAND() {
#if DEBUG
TraceInstruction("and"); TraceInstruction("and");
#endif
mText.Writer.Write8(0x16); mText.Writer.Write8(0x16);
} }
public override void WriteOR() { public override void WriteOR() {
#if DEBUG
TraceInstruction("or"); TraceInstruction("or");
#endif
mText.Writer.Write8(0x17); mText.Writer.Write8(0x17);
} }
public override void WriteBAND() { public override void WriteBAND() {
#if DEBUG
TraceInstruction("band"); TraceInstruction("band");
#endif
mText.Writer.Write8(0x18); mText.Writer.Write8(0x18);
} }
public override void WriteBOR() { public override void WriteBOR() {
#if DEBUG
TraceInstruction("bor"); TraceInstruction("bor");
#endif
mText.Writer.Write8(0x19); mText.Writer.Write8(0x19);
} }
public override void WriteSHL() { public override void WriteSHL() {
#if DEBUG
TraceInstruction("shl"); TraceInstruction("shl");
#endif
mText.Writer.Write8(0x1A); mText.Writer.Write8(0x1A);
} }
public override void WriteSHR() { public override void WriteSHR() {
#if DEBUG
TraceInstruction("shr"); TraceInstruction("shr");
#endif
mText.Writer.Write8(0x1B); mText.Writer.Write8(0x1B);
} }
public override void WriteCALL(uint offset, int count) { public override void WriteCALL(uint offset, int count) {
#if DEBUG
TraceInstruction("call ${0:X8} {1}", offset, count); TraceInstruction("call ${0:X8} {1}", offset, count);
#endif
mText.Writer.Write8(0x1C); mText.Writer.Write8(0x1C);
mText.Writer.Write32(offset); mText.Writer.Write32(offset);
mText.Writer.WriteS32(count); mText.Writer.WriteS32(count);
} }
public override void WriteFUNC(int index, int count) { public override void WriteFUNC(int index, int count) {
#if DEBUG
TraceInstruction("func {0} {1}", index, count); TraceInstruction("func {0} {1}", index, count);
#endif
mText.Writer.Write8(0x1D); mText.Writer.Write8(0x1D);
mText.Writer.WriteS32(index); mText.Writer.WriteS32(index);
mText.Writer.WriteS32(count); mText.Writer.WriteS32(count);
@ -342,69 +282,50 @@ namespace arookas {
mText.Writer.WriteS32(count); mText.Writer.WriteS32(count);
} }
public override void WriteMKDS(int display) { public override void WriteMKDS(int display) {
#if DEBUG
TraceInstruction("mkds {0}", display); TraceInstruction("mkds {0}", display);
#endif
mText.Writer.Write8(0x1F); mText.Writer.Write8(0x1F);
mText.Writer.WriteS32(display); mText.Writer.WriteS32(display);
} }
public override void WriteRET() { public override void WriteRET() {
#if DEBUG
TraceInstruction("ret"); TraceInstruction("ret");
#endif
mText.Writer.Write8(0x20); mText.Writer.Write8(0x20);
} }
public override void WriteRET0() { public override void WriteRET0() {
#if DEBUG
TraceInstruction("ret0"); TraceInstruction("ret0");
#endif
mText.Writer.Write8(0x21); mText.Writer.Write8(0x21);
} }
public override void WriteJNE(uint offset) { public override void WriteJNE(uint offset) {
#if DEBUG
TraceInstruction("jne ${0:X8}", offset); TraceInstruction("jne ${0:X8}", offset);
#endif
mText.Writer.Write8(0x22); mText.Writer.Write8(0x22);
mText.Writer.Write32(offset); mText.Writer.Write32(offset);
} }
public override void WriteJMP(uint offset) { public override void WriteJMP(uint offset) {
#if DEBUG
TraceInstruction("jmp ${0:X8}", offset); TraceInstruction("jmp ${0:X8}", offset);
#endif
mText.Writer.Write8(0x23); mText.Writer.Write8(0x23);
mText.Writer.Write32(offset); mText.Writer.Write32(offset);
} }
public override void WritePOP() { public override void WritePOP() {
#if DEBUG
TraceInstruction("pop"); TraceInstruction("pop");
#endif
mText.Writer.Write8(0x24); mText.Writer.Write8(0x24);
} }
public override void WriteINT0() { public override void WriteINT0() {
#if DEBUG
TraceInstruction("int0"); TraceInstruction("int0");
#endif
mText.Writer.Write8(0x25); mText.Writer.Write8(0x25);
} }
public override void WriteINT1() { public override void WriteINT1() {
#if DEBUG
TraceInstruction("int1"); TraceInstruction("int1");
#endif
mText.Writer.Write8(0x26); mText.Writer.Write8(0x26);
} }
public override void WriteEND() { public override void WriteEND() {
#if DEBUG
TraceInstruction("end"); TraceInstruction("end");
#endif
mText.Writer.Write8(0x27); mText.Writer.Write8(0x27);
} }
#if DEBUG [Conditional("DEBUG")]
void TraceInstruction(string format, params object[] args) { void TraceInstruction(string format, params object[] args) {
var instruction = String.Format(format, args); var instruction = String.Format(format, args);
Debug.WriteLine("{0:X8} {1}", mText.Size, instruction); Debug.WriteLine("{0:X8} {1}", mText.Size, instruction);
} }
#endif
// data // data
public override void WriteData(string data) { public override void WriteData(string data) {