#include "gmqcc.h"
+/*
+ * Initially this was handled with a table in the gmqcc.h header, but
+ * much to my surprise the contents of the table was duplicated for
+ * each translation unit, causing all these strings to be duplicated
+ * for every .c file it was included into. This method culls back on
+ * it. This is a 'utility' function because the executor also depends
+ * on this for dissasembled bytecode.
+ */
+const char *util_instr_str[VINSTR_END] = {
+ "DONE", "MUL_F", "MUL_V", "MUL_FV",
+ "MUL_VF", "DIV_F", "ADD_F", "ADD_V",
+ "SUB_F", "SUB_V", "EQ_F", "EQ_V",
+ "EQ_S", "EQ_E", "EQ_FNC", "NE_F",
+ "NE_V", "NE_S", "NE_E", "NE_FNC",
+ "LE", "GE", "LT", "GT",
+ "LOAD_F", "LOAD_V", "LOAD_S", "LOAD_ENT",
+ "LOAD_FLD", "LOAD_FNC", "ADDRESS", "STORE_F",
+ "STORE_V", "STORE_S", "STORE_ENT", "STORE_FLD",
+ "STORE_FNC", "STOREP_F", "STOREP_V", "STOREP_S",
+ "STOREP_ENT", "STOREP_FLD", "STOREP_FNC", "RETURN",
+ "NOT_F", "NOT_V", "NOT_S", "NOT_ENT",
+ "NOT_FNC", "IF", "IFNOT", "CALL0",
+ "CALL1", "CALL2", "CALL3", "CALL4",
+ "CALL5", "CALL6", "CALL7", "CALL8",
+ "STATE", "GOTO", "AND", "OR",
+ "BITAND", "BITOR"
+};
+
void util_debug(const char *area, const char *ms, ...) {
va_list va;
if (!OPTS_OPTION_BOOL(OPTION_DEBUG))
}
#endif
-size_t util_strtocmd(const char *in, char *out, size_t outsz) {
+/*
+ * modifier is the match to make and the transpsition from it, while add is the upper-value that determines the
+ * transposion from uppercase to lower case.
+ */
+static GMQCC_INLINE size_t util_strtransform(const char *in, char *out, size_t outsz, const char *mod, int add) {
size_t sz = 1;
- for (; *in && sz < outsz; ++in, ++out, ++sz)
- *out = (*in == '-') ? '_' : (util_isalpha(*in) && !util_isupper(*in)) ? *in + 'A' - 'a': *in;
+ for (; *in && sz < outsz; ++in, ++out, ++sz) {
+ *out = (*in == mod[0])
+ ? mod[1]
+ : (util_isalpha(*in) && util_isupper(*in + add))
+ ? *in + add
+ : *in;
+ }
*out = 0;
return sz-1;
}
+size_t util_strtocmd(const char *in, char *out, size_t outsz) {
+ return util_strtransform(in, out, outsz, "-_", 'A'-'a');
+}
size_t util_strtononcmd(const char *in, char *out, size_t outsz) {
- size_t sz = 1;
- for (; *in && sz < outsz; ++in, ++out, ++sz)
- *out = (*in == '_') ? '-' : (util_isalpha(*in) && util_isupper(*in)) ? *in + 'a' - 'A' : *in;
- *out = 0;
- return sz-1;
+ return util_strtransform(in, out, outsz, "_-", 'a'-'A');
+}
+size_t util_optimizationtostr(const char *in, char *out, size_t outsz) {
+ return util_strtransform(in, out, outsz, "_ ", 'a'-'A');
}
/*
* = 2*2*3*3*11])
*/
i = MT_SPACE;
- while (i < MT_SIZE - 1) {
+ while (i < MT_SIZE-2) {
/*
* We expand this 11 times .. manually, no macros are required
* here. This all fits in the CPU cache.