Commit f04a373d authored by Richard Gobeille's avatar Richard Gobeille
Browse files

Duke3d: change VM_IFELSE_MAGIC to just steal one bit from the translated...

Duke3d: change VM_IFELSE_MAGIC to just steal one bit from the translated bytecode instead of the whole range used for the encoded line numbers used for debugging

This has the side effect of making branches show up w/ correct line numbers in VM instruction debug dumps. Needs testing!
parent 16eb78da
......@@ -1341,7 +1341,7 @@ static int C_GetNextKeyword(void) //Returns its code #
if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0))
{
if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP)
scriptWriteValue(i | (VM_IFELSE_MAGIC<<12));
scriptWriteValue(i | LINE_NUMBER | VM_IFELSE_MAGIC_BIT);
else scriptWriteValue(i | LINE_NUMBER);
textptr += l;
......@@ -1951,7 +1951,7 @@ static bool C_CheckEmptyBranch(int tw, intptr_t lastScriptPtr)
return false;
}
if ((*(g_scriptPtr) & VM_INSTMASK) != CON_NULLOP || *(g_scriptPtr)>>12 != VM_IFELSE_MAGIC)
if ((*(g_scriptPtr) & VM_INSTMASK) != CON_NULLOP || (*(g_scriptPtr) & VM_IFELSE_MAGIC_BIT) == 0)
g_skipBranch = false;
if (EDUKE32_PREDICT_FALSE(g_skipBranch))
......@@ -1961,7 +1961,7 @@ static bool C_CheckEmptyBranch(int tw, intptr_t lastScriptPtr)
g_scriptPtr = lastScriptPtr + apScript;
LOG_F(WARNING, "%s:%d: empty '%s' branch",g_scriptFileName,g_lineNumber,
VM_GetKeywordForID(*(g_scriptPtr) & VM_INSTMASK));
scriptWriteAtOffset(CON_NULLOP | (VM_IFELSE_MAGIC<<12), g_scriptPtr);
scriptWriteAtOffset(CON_NULLOP | LINE_NUMBER | VM_IFELSE_MAGIC_BIT, g_scriptPtr);
return true;
}
......@@ -2602,7 +2602,7 @@ DO_DEFSTATE:
LOG_F(WARNING, "%s:%d: expected state, found %s.", g_scriptFileName, g_lineNumber, gl);
g_warningCnt++;
Xfree(gl);
scriptWriteAtOffset(CON_NULLOP, &g_scriptPtr[-1]); // get rid of the state, leaving a nullop to satisfy if conditions
scriptWriteAtOffset(CON_NULLOP|LINE_NUMBER, &g_scriptPtr[-1]); // get rid of the state, leaving a nullop to satisfy if conditions
continue; // valid label name, but wrong type
}
......@@ -5201,11 +5201,11 @@ repeatcase:
case CON_RIGHTBRACE:
g_numBraces--;
if ((g_scriptPtr[-2]>>12) == (VM_IFELSE_MAGIC) &&
if ((g_scriptPtr[-2] & VM_IFELSE_MAGIC_BIT) &&
((g_scriptPtr[-2] & VM_INSTMASK) == CON_LEFTBRACE)) // rewrite "{ }" into "nullop"
{
// initprintf("%s:%d: rewriting empty braces '{ }' as 'nullop' from right\n",g_szScriptFileName,g_lineNumber);
g_scriptPtr[-2] = CON_NULLOP | (VM_IFELSE_MAGIC<<12);
g_scriptPtr[-2] = CON_NULLOP | LINE_NUMBER | VM_IFELSE_MAGIC_BIT;
g_scriptPtr -= 2;
if (C_GetKeyword() != CON_ELSE && (g_scriptPtr[-2] & VM_INSTMASK) != CON_ELSE)
......
......@@ -59,12 +59,11 @@ enum
#define LABEL_READFUNC 64
#define LABEL_WRITEFUNC 128
// "magic" number for { and }, overrides line number in compiled code for later detection
#define VM_IFELSE_MAGIC 31337
#define VM_IFELSE_MAGIC_BIT (1<<31)
#define VM_INSTMASK 0xfff
#define VM_VSIZE_LINE_END -1
#define VM_DECODE_INST(xxx) ((int)((xxx) & VM_INSTMASK))
#define VM_DECODE_LINE_NUMBER(xxx) ((int)((xxx) >> 12))
#define VM_DECODE_LINE_NUMBER(xxx) ((int)((xxx&~VM_IFELSE_MAGIC_BIT) >> 12))
#define C_CUSTOMERROR(Text, ...) \
do \
{ \
......
......@@ -92,7 +92,7 @@ void VM_ScriptInfo(intptr_t const * const ptr, int const range)
int const lineNum = VM_DECODE_LINE_NUMBER(v);
int const vmInst = VM_DECODE_INST(v);
if (lineNum && lineNum != VM_IFELSE_MAGIC && lineNum >= lastLine && lineNum < g_totalLines && vmInst < CON_OPCODE_END)
if (lineNum && lineNum >= lastLine && lineNum < g_totalLines && (unsigned)vmInst < CON_OPCODE_END)
{
lastLine = lineNum;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment