#include <string.h>
#include <assert.h>
#include <sys/time.h>
+#include <stdarg.h>
#include "uldas.h"
FILE *ulasin = NULL;
ulas_preprocfree(&ulas.pp);
}
+
+int ulas_dbg(const char *fmt, ...) {
+ int res = 0;
+ va_list args;
+
+ if (!ulascfg.verbose) {
+ return 0;
+ }
+
+ ULASINFO();
+ va_start(args, fmt);
+ res = vfprintf(ulaserr, fmt, args);
+ va_end(args);
+
+ return res;
+}
+
+int ulas_err(const char *fmt, ...) {
+ int res = 0;
+ va_list args;
+
+ ULASINFO();
+
+ va_start(args, fmt);
+ res = vfprintf(ulaserr, fmt, args);
+ va_end(args);
+
+ return res;
+}
+
+int ulas_warn(const char *fmt, ...) {
+ int res = 0;
+ va_list args;
+
+ ULASINFO();
+ va_start(args, fmt);
+ res = vfprintf(ulaserr, fmt, args);
+ va_end(args);
+
+ return res;
+}
+
+int ulas_panic(const char *fmt, ...) {
+ int res = 0;
+ va_list args;
+
+ ULASINFO();
+
+ va_start(args, fmt);
+ res = vfprintf(ulaserr, fmt, args);
+ va_end(args);
+
+ exit(-1);
+
+ return res;
+}
+
char *ulas_strdup(const char *s) {
int len = strlen(s);
return ulas_strndup(s, len);
tok.val.intv = ulas.enumv;
rc = 0;
- ULAS_EVALEXPRS(ulas.enumv += ulas_intexpr(line, n, &rc));
+
+ ULAS_EVALEXPRS_BEGIN
+ ulas.enumv += ulas_intexpr(line, n, &rc);
+ ULAS_EVALEXPRS_END
+
if (rc == -1) {
goto fail;
}
}
count = 0;
- ULAS_EVALEXPRS(count = ulas_intexpr(line, n, rc));
+ ULAS_EVALEXPRS_BEGIN
+ count = ulas_intexpr(line, n, rc);
+ ULAS_EVALEXPRS_END
+
if (count < 0) {
ULASERR("Count must be positive\n");
return 0;
}
int ulas_asmdiradv(FILE *dst, const char **line, unsigned long n, int *rc) {
- ULAS_EVALEXPRS(ulas.address += ulas_intexpr(line, ulas_strnlen(*line, n), rc));
+ ULAS_EVALEXPRS_BEGIN
+ ulas.address += ulas_intexpr(line, ulas_strnlen(*line, n), rc);
+ ULAS_EVALEXPRS_END
+
return 0;
}
int ulas_asmdirsetenum(FILE *dst, const char **line, unsigned long n, int *rc) {
- ULAS_EVALEXPRS(ulas.enumv = ulas_intexpr(line, ulas_strnlen(*line, n), rc));
+ ULAS_EVALEXPRS_BEGIN
+ ulas.enumv = ulas_intexpr(line, ulas_strnlen(*line, n), rc);
+ ULAS_EVALEXPRS_END
+
return 0;
}
int charcode = 0;
int setto = 0;
struct ulas_tok t;
- ULAS_EVALEXPRS(charcode = ulas_intexpr(line, n, &rc));
+ ULAS_EVALEXPRS_BEGIN
+ charcode = ulas_intexpr(line, n, &rc);
+ ULAS_EVALEXPRS_END
+
charcode = charcode & 0xFF;
ulas_tok(&ulas.tok, line, n);
return 0;
}
- ULAS_EVALEXPRS(setto = ulas_intexpr(line, n, &rc));
+ ULAS_EVALEXPRS_BEGIN
+ setto = ulas_intexpr(line, n, &rc);
+ ULAS_EVALEXPRS_END
+
setto = setto & 0xFF;
ulas.charcodemap[charcode] = (char)setto;
repval = 0;
rc = 0;
- ULAS_EVALEXPRS(repval = ulas_intexpr(line, n, &rc));
+ ULAS_EVALEXPRS_BEGIN
+ repval = ulas_intexpr(line, n, &rc);
+ ULAS_EVALEXPRS_END
+
ulas_tok(&ulas.tok, line, n);
t =
ulas_totok(ulas.tok.buf, ulas_strnlen(ulas.tok.buf, ulas.tok.maxlen), &rc);
}
step = 0;
- ULAS_EVALEXPRS(step = ulas_intexpr(line, n, &rc));
+ ULAS_EVALEXPRS_BEGIN
+ step = ulas_intexpr(line, n, &rc);
+ ULAS_EVALEXPRS_END
+
ulas_tok(&ulas.tok, line, n);
t = ulas_totok(ulas.tok.buf, ulas_strnlen(ulas.tok.buf, ulas.tok.maxlen), &rc);
if (rc == -1 || t.type != ',') {
int ulas_asmdirbank(FILE *dst, FILE *src, const char **line, unsigned long n,
int *rc) {
- ULAS_EVALEXPRS(ulas.bank = ulas_intexpr(line, ulas_strnlen(*line, n), rc));
+ ULAS_EVALEXPRS_BEGIN
+ ulas.bank = ulas_intexpr(line, ulas_strnlen(*line, n), rc);
+ ULAS_EVALEXPRS_END
+
return *rc;
}
switch (dir) {
case ULAS_ASMDIR_ORG: {
- ULAS_EVALEXPRS(ulas.address =
- ulas_intexpr(&line, ulas_strnlen(start, n), &rc));
+ ULAS_EVALEXPRS_BEGIN
+ ulas.address =
+ ulas_intexpr(&line, ulas_strnlen(start, n), &rc);
+ ULAS_EVALEXPRS_END
+
break;
}
case ULAS_ASMDIR_DEF:
#define ULAS_TOK_SCOPED_SYMBOL_BEGIN '@'
#define ULAS_TOK_CURRENT_ADDR '$'
+#define ULAS_UNUSED(x) (void)(x)
+
#define ULASINFO() fprintf(ulaserr, "%s:%ld ", ulas.filename, ulas.line);
-#define ULASDBG(...) \
- if (ulascfg.verbose) { \
- fprintf(ulaserr, __VA_ARGS__); \
- }
-#define ULASERR(...) ULASINFO() fprintf(ulaserr, __VA_ARGS__);
-#define ULASWARN(...) ULASINFO() fprintf(ulaserr, __VA_ARGS__);
-#define ULASPANIC(...) \
- { \
- ULASINFO(); \
- fprintf(ulaserr, __VA_ARGS__); \
- exit(-1); \
- }
+
+/* deprecaated legacy log macros */
+#define ULASDBG ulas_dbg
+#define ULASERR ulas_err
+#define ULASWARN ulas_warn
+#define ULASPANIC ulas_panic
+
#define ULASWARNLEVEL(level) (ulascfg.warn_level & (level))
/* format macros */
* only be uesd to evalulate an expression that needs to be evaled during
* all passes and nothing else!
*/
-#define ULAS_EVALEXPRS(...) \
+#define ULAS_EVALEXPRS_BEGIN \
{ \
int pass = ulas.pass; \
- ulas.pass = ULAS_PASS_FINAL; \
- __VA_ARGS__; \
- ulas.pass = pass; \
- }
+ ulas.pass = ULAS_PASS_FINAL;
+#define ULAS_EVALEXPRS_END \
+ ulas.pass = pass; \
+ }
/**
* Output target files
unsigned int ulas_strlcat(char *dst, const char *src, unsigned int max);
+/* ulas log functions */
+int ulas_dbg(const char *fmt, ...);
+int ulas_err(const char *fmt, ...);
+int ulas_warn(const char *fmt, ...);
+int ulas_panic(const char *fmt, ...);
+
void ulas_help(void);
void ulas_version(void);