Downgrade to C++03 due to OSX's GCC being **MASSIVELY** out of date (4.0)
This commit is contained in:
parent
faea6b5ebe
commit
b2e0b2b96e
@ -41,7 +41,10 @@ enum
|
||||
#define OPDESC_MASK_D1 OPDESC_MAKE(0xF, 0x1FF, 0, 0)
|
||||
#define OPDESC_MASK_1 OPDESC_MAKE(0, 0x1FF, 0, 0)
|
||||
|
||||
extern std::vector<u32> g_outputBuf;
|
||||
typedef std::vector<u32> outputBufType;
|
||||
typedef outputBufType::iterator outputBufIter;
|
||||
|
||||
extern outputBufType g_outputBuf;
|
||||
|
||||
enum
|
||||
{
|
||||
@ -105,8 +108,17 @@ extern int g_constantCount;
|
||||
|
||||
typedef std::pair<size_t, size_t> procedure; // position, size
|
||||
typedef std::pair<size_t, const char*> relocation;
|
||||
extern std::map<std::string, procedure> g_procTable;
|
||||
extern std::map<std::string, size_t> g_labels;
|
||||
extern std::map<std::string, int> g_aliases;
|
||||
|
||||
typedef std::map<std::string, procedure> procTableType;
|
||||
typedef std::map<std::string, size_t> labelTableType;
|
||||
typedef std::map<std::string, int> aliasTableType;
|
||||
|
||||
typedef procTableType::iterator procTableIter;
|
||||
typedef labelTableType::iterator labelTableIter;
|
||||
typedef aliasTableType::iterator aliasTableIter;
|
||||
|
||||
extern procTableType g_procTable;
|
||||
extern labelTableType g_labels;
|
||||
extern aliasTableType g_aliases;
|
||||
|
||||
int AssembleString(char* str, const char* initialFilename);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#define BUF g_outputBuf
|
||||
#define NO_MORE_STACK (g_stackPos==MAX_STACK)
|
||||
|
||||
static const char* curFile = nullptr;
|
||||
static const char* curFile = NULL;
|
||||
static int curLine = -1;
|
||||
|
||||
std::vector<u32> g_outputBuf;
|
||||
@ -34,10 +34,10 @@ static char* mystrtok_pos;
|
||||
static char* mystrtok(char* str, const char* delim)
|
||||
{
|
||||
if (!str) str = mystrtok_pos;
|
||||
if (!*str) return nullptr;
|
||||
if (!*str) return NULL;
|
||||
|
||||
size_t pos = strcspn(str, delim);
|
||||
auto ret = str;
|
||||
char* ret = str;
|
||||
str += pos;
|
||||
if (*str)
|
||||
*str++ = 0;
|
||||
@ -47,8 +47,8 @@ static char* mystrtok(char* str, const char* delim)
|
||||
|
||||
static char* mystrtok_spc(char* str)
|
||||
{
|
||||
auto ret = mystrtok(str, " \t");
|
||||
if (!ret) return nullptr;
|
||||
char* ret = mystrtok(str, " \t");
|
||||
if (!ret) return NULL;
|
||||
if (*mystrtok_pos)
|
||||
for (; *mystrtok_pos && isspace(*mystrtok_pos); mystrtok_pos++);
|
||||
return ret;
|
||||
@ -64,7 +64,7 @@ static char* remove_comment(char* buf)
|
||||
static char* trim_whitespace(char* buf)
|
||||
{
|
||||
if (!buf)
|
||||
return nullptr;
|
||||
return NULL;
|
||||
|
||||
// Remove trailing whitespace
|
||||
int pos;
|
||||
@ -104,7 +104,7 @@ static int throwError(const char* msg, ...)
|
||||
|
||||
static int parseInt(char* pos, int& out, long long min, long long max)
|
||||
{
|
||||
char* endptr = nullptr;
|
||||
char* endptr = NULL;
|
||||
long long res = strtoll(pos, &endptr, 0);
|
||||
if (pos == endptr)
|
||||
return throwError("Invalid value: %s\n", pos);
|
||||
@ -128,18 +128,18 @@ int AssembleString(char* str, const char* initialFilename)
|
||||
curLine = 1;
|
||||
|
||||
int nextLineIncr = 0;
|
||||
char* nextStr = nullptr;
|
||||
char* nextStr = NULL;
|
||||
for (; str; str = nextStr, curLine += nextLineIncr)
|
||||
{
|
||||
size_t len = strcspn(str, "\n");
|
||||
int linedelim = str[len];
|
||||
str[len] = 0;
|
||||
nextStr = linedelim ? (str + len + 1) : nullptr;
|
||||
nextStr = linedelim ? (str + len + 1) : NULL;
|
||||
nextLineIncr = linedelim == '\n' ? 1 : 0;
|
||||
|
||||
char* line = trim_whitespace(remove_comment(str));
|
||||
|
||||
char* colonPos = nullptr;
|
||||
char* colonPos = NULL;
|
||||
for (;;)
|
||||
{
|
||||
colonPos = strchr(line, ':');
|
||||
@ -152,7 +152,7 @@ int AssembleString(char* str, const char* initialFilename)
|
||||
if (!validateIdentifier(labelName))
|
||||
return throwError("invalid label name: %s\n", labelName);
|
||||
|
||||
auto ret = g_labels.insert( std::pair<std::string,size_t>(labelName, BUF.size()) );
|
||||
std::pair<labelTableIter,bool> ret = g_labels.insert( std::pair<std::string,size_t>(labelName, BUF.size()) );
|
||||
if (!ret.second)
|
||||
return throwError("duplicate label: %s\n", labelName);
|
||||
|
||||
@ -197,17 +197,17 @@ int AssembleString(char* str, const char* initialFilename)
|
||||
|
||||
static char* nextArg()
|
||||
{
|
||||
return trim_whitespace(mystrtok(nullptr, ","));
|
||||
return trim_whitespace(mystrtok(NULL, ","));
|
||||
}
|
||||
|
||||
static char* nextArgCParen()
|
||||
{
|
||||
return trim_whitespace(mystrtok(nullptr, "("));
|
||||
return trim_whitespace(mystrtok(NULL, "("));
|
||||
}
|
||||
|
||||
static char* nextArgSpc()
|
||||
{
|
||||
return trim_whitespace(mystrtok_spc(nullptr));
|
||||
return trim_whitespace(mystrtok_spc(NULL));
|
||||
}
|
||||
|
||||
static int missingParam()
|
||||
@ -401,7 +401,7 @@ static inline int convertIdxRegName(const char* reg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = nullptr)
|
||||
static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = NULL)
|
||||
{
|
||||
outReg = 0;
|
||||
outSw = DEFAULT_OPSRC;
|
||||
@ -411,7 +411,7 @@ static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = nullptr)
|
||||
pos++;
|
||||
outSw |= 1; // negation bit
|
||||
}
|
||||
auto dotPos = strchr(pos, '.');
|
||||
char* dotPos = strchr(pos, '.');
|
||||
if (dotPos)
|
||||
{
|
||||
*dotPos++ = 0;
|
||||
@ -420,10 +420,10 @@ static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = nullptr)
|
||||
return throwError("invalid swizzling mask: %s\n", dotPos);
|
||||
}
|
||||
int regOffset = 0;
|
||||
auto offPos = strchr(pos, '[');
|
||||
char* offPos = strchr(pos, '[');
|
||||
if (offPos)
|
||||
{
|
||||
auto closePos = strchr(offPos, ']');
|
||||
char* closePos = strchr(offPos, ']');
|
||||
if (!closePos)
|
||||
return throwError("missing closing bracket: %s\n", pos);
|
||||
*closePos = 0;
|
||||
@ -439,13 +439,13 @@ static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = nullptr)
|
||||
*idxType = temp;
|
||||
} else do
|
||||
{
|
||||
auto plusPos = strchr(offPos, '+');
|
||||
char* plusPos = strchr(offPos, '+');
|
||||
if (!plusPos)
|
||||
break;
|
||||
if (!idxType)
|
||||
return throwError("index register not allowed here: %s\n", offPos);
|
||||
*plusPos++ = 0;
|
||||
auto idxRegName = trim_whitespace(offPos);
|
||||
char* idxRegName = trim_whitespace(offPos);
|
||||
offPos = trim_whitespace(plusPos);
|
||||
*idxType = convertIdxRegName(idxRegName);
|
||||
if (*idxType < 0)
|
||||
@ -456,7 +456,7 @@ static int parseReg(char* pos, int& outReg, int& outSw, int* idxType = nullptr)
|
||||
if (regOffset < 0)
|
||||
return throwError("invalid register offset: %s\n", offPos);
|
||||
}
|
||||
auto it = g_aliases.find(pos);
|
||||
aliasTableIter it = g_aliases.find(pos);
|
||||
if (it != g_aliases.end())
|
||||
{
|
||||
int x = it->second;
|
||||
@ -623,7 +623,7 @@ static const cmdTableType cmdTable[] =
|
||||
DEC_COMMAND(LRP, format5),
|
||||
DEC_COMMAND(MAD, format5),
|
||||
|
||||
{ nullptr, nullptr },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@ -638,7 +638,7 @@ DEF_DIRECTIVE(proc)
|
||||
if (NO_MORE_STACK)
|
||||
return throwError("too many nested blocks\n");
|
||||
|
||||
auto& elem = g_stack[g_stackPos++];
|
||||
StackEntry& elem = g_stack[g_stackPos++];
|
||||
elem.type = SE_PROC;
|
||||
elem.pos = BUF.size();
|
||||
elem.strExtra = procName;
|
||||
@ -658,7 +658,7 @@ DEF_DIRECTIVE(end)
|
||||
if (!g_stackPos)
|
||||
return throwError(".end with unmatched block\n");
|
||||
|
||||
auto& elem = g_stack[--g_stackPos];
|
||||
StackEntry& elem = g_stack[--g_stackPos];
|
||||
u32 curPos = BUF.size();
|
||||
u32 size = curPos - elem.pos;
|
||||
|
||||
@ -726,7 +726,7 @@ DEF_DIRECTIVE(uniform)
|
||||
if (g_aliases.find(argText) != g_aliases.end())
|
||||
return duplicateIdentifier(argText);
|
||||
|
||||
auto& uniform = g_uniformTable[g_uniformCount++];
|
||||
Uniform& uniform = g_uniformTable[g_uniformCount++];
|
||||
uniform.name = argText;
|
||||
uniform.pos = uniformPos;
|
||||
uniform.size = uSize;
|
||||
@ -746,9 +746,9 @@ DEF_DIRECTIVE(const)
|
||||
NEXT_ARG(arg0Text);
|
||||
NEXT_ARG(arg1Text);
|
||||
NEXT_ARG(arg2Text);
|
||||
auto arg3Text = mystrtok_pos;
|
||||
char* arg3Text = mystrtok_pos;
|
||||
if (!mystrtok_pos) return missingParam();
|
||||
auto parenPos = strchr(arg3Text, ')');
|
||||
char* parenPos = strchr(arg3Text, ')');
|
||||
if (!parenPos) return throwError("invalid syntax\n");
|
||||
*parenPos = 0;
|
||||
arg3Text = trim_whitespace(arg3Text);
|
||||
@ -759,7 +759,7 @@ DEF_DIRECTIVE(const)
|
||||
if (g_aliases.find(constName) != g_aliases.end())
|
||||
return duplicateIdentifier(constName);
|
||||
|
||||
auto& ct = g_constantTable[g_constantCount++];
|
||||
Constant& ct = g_constantTable[g_constantCount++];
|
||||
ct.regId = uniformPos++;
|
||||
ct.param[0] = atof(arg0Text);
|
||||
ct.param[1] = atof(arg1Text);
|
||||
@ -799,7 +799,7 @@ DEF_DIRECTIVE(out)
|
||||
return throwError("invalid identifier: %s\n", outName);
|
||||
|
||||
int sw = DEFAULT_OPSRC;
|
||||
auto dotPos = strchr(outType, '.');
|
||||
char* dotPos = strchr(outType, '.');
|
||||
if (dotPos)
|
||||
{
|
||||
*dotPos++ = 0;
|
||||
@ -837,7 +837,7 @@ static const cmdTableType dirTable[] =
|
||||
DEC_DIRECTIVE(uniform),
|
||||
DEC_DIRECTIVE(const),
|
||||
DEC_DIRECTIVE(out),
|
||||
{ nullptr, nullptr },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
int ProcessCommand(const char* cmd)
|
||||
|
@ -64,18 +64,13 @@ int main(int argc, char* argv[])
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
auto mainIt = g_procTable.find("main");
|
||||
procTableIter mainIt = g_procTable.find("main");
|
||||
if (mainIt == g_procTable.end())
|
||||
{
|
||||
fprintf(stderr, "Error: main proc not defined\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_constantCount > 9)
|
||||
fprintf(stderr, "WARNING: ctrulib currently has a bug when using more than 1 constant\n");
|
||||
if (g_opdescCount > 9)
|
||||
fprintf(stderr, "WARNING: ctrulib currently has a bug when using more than 9 opdescs\n");
|
||||
|
||||
FileClass f(shbinFile, "wb");
|
||||
|
||||
if (f.openerror())
|
||||
@ -131,8 +126,9 @@ int main(int argc, char* argv[])
|
||||
f.WriteWord(0); // size of symbol table
|
||||
|
||||
// Write program
|
||||
for (u32 p : g_outputBuf)
|
||||
f.WriteWord(p);
|
||||
//for (u32 p : g_outputBuf)
|
||||
for (outputBufIter it = g_outputBuf.begin(); it != g_outputBuf.end(); ++it)
|
||||
f.WriteWord(*it);
|
||||
|
||||
// Write opdescs
|
||||
for (int i = 0; i < g_opdescCount; i ++)
|
||||
@ -144,7 +140,7 @@ int main(int argc, char* argv[])
|
||||
// Write constants
|
||||
for (int i = 0; i < g_constantCount; i ++)
|
||||
{
|
||||
auto& ct = g_constantTable[i];
|
||||
Constant& ct = g_constantTable[i];
|
||||
f.WriteHword(0);
|
||||
f.WriteByte(ct.regId-0x20);
|
||||
f.WriteByte(0);
|
||||
@ -160,7 +156,7 @@ int main(int argc, char* argv[])
|
||||
size_t sp = 0;
|
||||
for (int i = 0; i < g_uniformCount; i ++)
|
||||
{
|
||||
auto& u = g_uniformTable[i];
|
||||
Uniform& u = g_uniformTable[i];
|
||||
size_t l = strlen(u.name)+1;
|
||||
f.WriteWord(sp); sp += l;
|
||||
f.WriteHword(u.pos-0x20);
|
||||
@ -176,14 +172,14 @@ int main(int argc, char* argv[])
|
||||
// Write symbols
|
||||
for (int i = 0; i < g_uniformCount; i ++)
|
||||
{
|
||||
auto u = g_uniformTable[i].name;
|
||||
const char* u = g_uniformTable[i].name;
|
||||
size_t l = strlen(u)+1;
|
||||
f.WriteRaw(u, l);
|
||||
}
|
||||
|
||||
if (hFile)
|
||||
{
|
||||
auto f2 = fopen(hFile, "w");
|
||||
FILE* f2 = fopen(hFile, "w");
|
||||
if (!f2)
|
||||
{
|
||||
fprintf(stderr, "Can't open header file!\n");
|
||||
@ -194,7 +190,7 @@ int main(int argc, char* argv[])
|
||||
fprintf(f2, "#pragma once\n");
|
||||
for (int i = 0; i < g_uniformCount; i ++)
|
||||
{
|
||||
auto& u = g_uniformTable[i];
|
||||
Uniform& u = g_uniformTable[i];
|
||||
fprintf(f2, "#define SHADER_UREG_%s 0x%02X\n", u.name, u.pos-0x20);
|
||||
fprintf(f2, "#define SHADER_ULEN_%s %d\n", u.name, u.size);
|
||||
}
|
||||
|
@ -16,6 +16,27 @@ typedef uint8_t u8;
|
||||
|
||||
#define BIT(n) (1U << (n))
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
||||
static inline uint16_t __builtin_bswap16(uint16_t x)
|
||||
{
|
||||
return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);
|
||||
}
|
||||
|
||||
static inline uint32_t __builtin_bswap32(uint32_t x)
|
||||
{
|
||||
return ((x << 24) & 0xff000000) |
|
||||
((x << 8) & 0x00ff0000) |
|
||||
((x >> 8) & 0x0000ff00) |
|
||||
((x >> 24) & 0x000000ff);
|
||||
}
|
||||
|
||||
static inline uint64_t __builtin_bswap64(uint64_t x)
|
||||
{
|
||||
return (uint64_t)__builtin_bswap32(x>>32) |
|
||||
((uint64_t)__builtin_bswap32(x&0xFFFFFFFF) << 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define be_dword(a) __builtin_bswap64(a)
|
||||
#define be_word(a) __builtin_bswap32(a)
|
||||
|
Loading…
Reference in New Issue
Block a user