Mercurial > hg > index.cgi
comparison lwasm/pseudo.c @ 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 | 707eda49ad60 |
children | 3c1a80c2fb95 |
comparison
equal
deleted
inserted
replaced
131:f2f3a4b0a25e | 132:4cf44ff89b08 |
---|---|
21 | 21 |
22 #include <stdio.h> | 22 #include <stdio.h> |
23 #include <ctype.h> | 23 #include <ctype.h> |
24 #include <string.h> | 24 #include <string.h> |
25 #include <stdlib.h> | 25 #include <stdlib.h> |
26 #include <time.h> | |
26 | 27 |
27 #include <lw_alloc.h> | 28 #include <lw_alloc.h> |
28 | 29 |
29 #include "lwasm.h" | 30 #include "lwasm.h" |
30 #include "instab.h" | 31 #include "instab.h" |
31 #include "input.h" | 32 #include "input.h" |
32 | 33 |
33 #include "lw_string.h" | 34 #include "lw_string.h" |
34 | 35 |
35 extern void register_struct_entry(asmstate_t *as, line_t *l, int size, structtab_t *ss); | 36 extern void register_struct_entry(asmstate_t *as, line_t *l, int size, structtab_t *ss); |
37 | |
38 // for "dts" | |
39 PARSEFUNC(pseudo_parse_dts) | |
40 { | |
41 skip_operand(p); | |
42 } | |
43 | |
44 EMITFUNC(pseudo_emit_dts) | |
45 { | |
46 time_t tp; | |
47 char *t; | |
48 | |
49 tp = time(NULL); | |
50 t = ctime(&tp); | |
51 | |
52 while (*t) | |
53 { | |
54 lwasm_emit(l, *t); | |
55 t++; | |
56 } | |
57 } | |
58 | |
59 // for "dtb" | |
60 PARSEFUNC(pseudo_parse_dtb) | |
61 { | |
62 skip_operand(p); | |
63 } | |
64 | |
65 EMITFUNC(pseudo_emit_dtb) | |
66 { | |
67 time_t tp; | |
68 struct tm *t; | |
69 | |
70 tp = time(NULL); | |
71 t = localtime(&tp); | |
72 | |
73 lwasm_emit(l, t -> tm_year); | |
74 lwasm_emit(l, t -> tm_mon + 1); | |
75 lwasm_emit(l, t -> tm_mday); | |
76 lwasm_emit(l, t -> tm_hour); | |
77 lwasm_emit(l, t -> tm_min); | |
78 lwasm_emit(l, t -> tm_sec); | |
79 } | |
36 | 80 |
37 // for "end" | 81 // for "end" |
38 PARSEFUNC(pseudo_parse_end) | 82 PARSEFUNC(pseudo_parse_end) |
39 { | 83 { |
40 lw_expr_t addr; | 84 lw_expr_t addr; |
1029 as -> skipcount++; | 1073 as -> skipcount++; |
1030 skip_operand(p); | 1074 skip_operand(p); |
1031 return; | 1075 return; |
1032 } | 1076 } |
1033 | 1077 |
1034 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++) | 1078 again: |
1079 for (i = 0; (*p)[i] && !isspace((*p)[i]) && (*p)[i] != '|' && (*p)[i] != '&'; i++) | |
1035 /* do nothing */ ; | 1080 /* do nothing */ ; |
1036 | 1081 |
1037 sym = lw_strndup(*p, i); | 1082 sym = lw_strndup(*p, i); |
1038 (*p) += i; | 1083 (*p) += i; |
1039 | 1084 |
1040 s = lookup_symbol(as, l, sym); | 1085 s = lookup_symbol(as, l, sym); |
1041 | 1086 |
1042 lw_free(sym); | 1087 lw_free(sym); |
1043 | 1088 |
1044 if (!s) | 1089 if (!s && **p != '|') |
1045 { | 1090 { |
1046 as -> skipcond = 1; | 1091 as -> skipcond = 1; |
1047 as -> skipcount = 1; | 1092 as -> skipcount = 1; |
1048 } | 1093 skip_operand(p); |
1094 return; | |
1095 } | |
1096 (*p)++; | |
1097 goto again; | |
1049 } | 1098 } |
1050 | 1099 |
1051 PARSEFUNC(pseudo_parse_ifndef) | 1100 PARSEFUNC(pseudo_parse_ifndef) |
1052 { | 1101 { |
1053 char *sym; | 1102 char *sym; |
1060 { | 1109 { |
1061 as -> skipcount++; | 1110 as -> skipcount++; |
1062 skip_operand(p); | 1111 skip_operand(p); |
1063 return; | 1112 return; |
1064 } | 1113 } |
1065 | 1114 for (i = 0; (*p)[i] && !isspace((*p)[i]) && (*p)[i] != '&' && (*p)[i] != '|'; i++) |
1066 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++) | |
1067 /* do nothing */ ; | 1115 /* do nothing */ ; |
1068 | 1116 |
1069 sym = lw_strndup(*p, i); | 1117 sym = lw_strndup(*p, i); |
1070 (*p) += i; | 1118 (*p) += i; |
1071 | 1119 |
1075 | 1123 |
1076 if (s) | 1124 if (s) |
1077 { | 1125 { |
1078 as -> skipcond = 1; | 1126 as -> skipcond = 1; |
1079 as -> skipcount = 1; | 1127 as -> skipcount = 1; |
1128 return; | |
1080 } | 1129 } |
1081 } | 1130 } |
1082 | 1131 |
1083 PARSEFUNC(pseudo_parse_error) | 1132 PARSEFUNC(pseudo_parse_error) |
1084 { | 1133 { |