fprintf(ulaserr, __VA_ARGS__); \
exit(-1); \
}
+#define ULASWARNLEVEL(level) ulascfg.warn_level & (level)
// format macros
#define ULAS_FMT(f, fmt) \
struct ulas_expr;
struct ulas_tok;
+enum ulas_warm { ULAS_WARN_OVERFLOW = 1, ULAS_WARN_ALL = 0x7FFFFFFF };
+
struct ulas_config {
// argv represents file names
char **argv;
// all include search paths
char **incpaths;
int incpathslen;
+
+ enum ulas_warm warn_level;
};
/**
#define ULAS_OPTS "hvVp"
// args with value
-#define ULAS_OPTS_ARG "o:l:s:i:"
+#define ULAS_OPTS_ARG "o:l:s:i:w:"
#define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc);
ULAS_HELP("l=path", "Listing file");
ULAS_HELP("s=path", "Symbols file");
ULAS_HELP("i=path", "Add include search path");
+ ULAS_HELP("w=warning", "Toggle warnings: a=all, o=overflow");
}
void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); }
void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) {
+ int warnings[255];
+ memset(warnings, 0, 255 * sizeof(int));
+ warnings['a'] = ULAS_WARN_ALL;
+ warnings['o'] = ULAS_WARN_OVERFLOW;
+
int c = 0;
while ((c = getopt(argc, argv, ULAS_OPTS ULAS_OPTS_ARG)) != -1) {
switch (c) {
case 'i':
assert(incpathslen < ULAS_INCPATHSMAX);
incpaths[incpathslen++] = strndup(optarg, ULAS_PATHMAX);
+ case 'w':
+ cfg->warn_level ^= warnings[(int)optarg[0]];
+ break;
case '?':
break;
default:
struct ulas_config cfg;
memset(&cfg, 0, sizeof(cfg));
+ cfg.warn_level = ULAS_WARN_OVERFLOW;
+
return cfg;
}
} else if (tok[i] == ULAS_E8 || tok[i] == ULAS_E16) {
assert(expridx < ULAS_INSTRDATMAX);
int rc = 0;
- exprres[expridx++] = ulas_intexpr(line, n, &rc);
+ int res = ulas_intexpr(line, n, &rc);
+ exprres[expridx++] = res;
if (rc == -1) {
return -1;
}
+
+ if (ULASWARNLEVEL(ULAS_WARN_OVERFLOW) &&
+ (unsigned int)res > 0xFF && tok[i] == ULAS_E8) {
+ ULASWARN("Warning: 0x%X overflows the maximum allowed value of 0xFF\n", res);
+ } else if (ULASWARNLEVEL(ULAS_WARN_OVERFLOW) &&
+ (unsigned int)res > 0xFFFF && tok[i] == ULAS_E16) {
+ ULASWARN("Warning: 0x%X overflows the maximum allowed value of 0xFFFF\n", res);
+ }
} else {
if (ulas_tok(&ulas.tok, line, n) == -1) {
goto skip;
}
union ulas_val val = {0};
- val.intv = ulas.enumv;
-
+ val.intv = ulas.enumv;
+
int rc = 0;
ULAS_EVALEXPRS(ulas.enumv += ulas_intexpr(line, n, &rc));
if (rc == -1) {