changeset 132:4cf44ff89b08

Added DTS and DTB pseudo ops; initial attempt to allow ifdef SYM1|SYM2
author lost@l-w.ca
date Thu, 11 Aug 2011 23:50:16 -0600
parents f2f3a4b0a25e
children 3c1a80c2fb95
files lwasm/instab.c lwasm/pseudo.c
diffstat 2 files changed, 65 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/instab.c	Thu Aug 11 22:58:27 2011 -0600
+++ b/lwasm/instab.c	Thu Aug 11 23:50:16 2011 -0600
@@ -116,6 +116,14 @@
 #define pseudo_resolve_noop NULL
 #define pseudo_emit_noop NULL
 
+extern PARSEFUNC(pseudo_parse_dts);
+#define pseudo_resolve_dts NULL
+extern EMITFUNC(pseudo_emit_dts);
+
+extern PARSEFUNC(pseudo_parse_dtb);
+#define pseudo_resolve_dtb NULL
+extern EMITFUNC(pseudo_emit_dtb);
+
 extern PARSEFUNC(pseudo_parse_end);
 #define pseudo_resolve_end NULL
 extern EMITFUNC(pseudo_emit_end);
@@ -688,6 +696,10 @@
 	// for compatibility
 	{ ".end", 		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_end,		pseudo_resolve_end,				pseudo_emit_end,			lwasm_insn_normal},
 
+	// date and time stamps
+	{ "dts",		{	-1,		-1,		-1,		-1 },	pseudo_parse_dts,		pseudo_resolve_dts,				pseudo_emit_dts,			lwasm_insn_normal},
+	{ "dtb",		{	-1,		-1,		-1,		-1 },	pseudo_parse_dtb,		pseudo_resolve_dtb,				pseudo_emit_dtb,			lwasm_insn_normal},
+
 	// extra ops that are ignored because they are generally only for
 	// pretty printing the listing
 	{ "nam",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_noop,		pseudo_resolve_noop,			pseudo_emit_noop,			lwasm_insn_normal},
--- a/lwasm/pseudo.c	Thu Aug 11 22:58:27 2011 -0600
+++ b/lwasm/pseudo.c	Thu Aug 11 23:50:16 2011 -0600
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
+#include <time.h>
 
 #include <lw_alloc.h>
 
@@ -34,6 +35,49 @@
 
 extern void register_struct_entry(asmstate_t *as, line_t *l, int size, structtab_t *ss);
 
+// for "dts"
+PARSEFUNC(pseudo_parse_dts)
+{
+	skip_operand(p);
+}
+
+EMITFUNC(pseudo_emit_dts)
+{
+	time_t tp;
+	char *t;
+	
+	tp = time(NULL);
+	t = ctime(&tp);
+
+	while (*t)
+	{
+		lwasm_emit(l, *t);
+		t++;
+	}
+}
+
+// for "dtb"
+PARSEFUNC(pseudo_parse_dtb)
+{
+	skip_operand(p);
+}
+
+EMITFUNC(pseudo_emit_dtb)
+{
+	time_t tp;
+	struct tm *t;
+	
+	tp = time(NULL);
+	t = localtime(&tp);
+
+	lwasm_emit(l, t -> tm_year);
+	lwasm_emit(l, t -> tm_mon + 1);
+	lwasm_emit(l, t -> tm_mday);
+	lwasm_emit(l, t -> tm_hour);
+	lwasm_emit(l, t -> tm_min);
+	lwasm_emit(l, t -> tm_sec);
+}
+
 // for "end"
 PARSEFUNC(pseudo_parse_end)
 {
@@ -1031,7 +1075,8 @@
 		return;
 	}
 
-	for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
+again:
+	for (i = 0; (*p)[i] && !isspace((*p)[i]) && (*p)[i] != '|' && (*p)[i] != '&'; i++)
 		/* do nothing */ ;
 	
 	sym = lw_strndup(*p, i);
@@ -1041,11 +1086,15 @@
 	
 	lw_free(sym);
 	
-	if (!s)
+	if (!s && **p != '|')
 	{
 		as -> skipcond = 1;
 		as -> skipcount = 1;
+		skip_operand(p);
+		return;
 	}
+	(*p)++;
+	goto again;
 }
 
 PARSEFUNC(pseudo_parse_ifndef)
@@ -1062,8 +1111,7 @@
 		skip_operand(p);
 		return;
 	}
-
-	for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
+	for (i = 0; (*p)[i] && !isspace((*p)[i]) && (*p)[i] != '&' && (*p)[i] != '|'; i++)
 		/* do nothing */ ;
 	
 	sym = lw_strndup(*p, i);
@@ -1077,6 +1125,7 @@
 	{
 		as -> skipcond = 1;
 		as -> skipcount = 1;
+		return;
 	}
 }