comparison lwasm/input.c @ 108:9960e05cbe3a

Added *pragmapush and *pragmapop; still seems to be nonfunctional
author lost@l-w.ca
date Sun, 07 Aug 2011 00:58:00 -0600
parents 5bf9edabd661
children 38c1537857ce
comparison
equal deleted inserted replaced
107:b3557f8325f7 108:9960e05cbe3a
33 #include <lw_stringlist.h> 33 #include <lw_stringlist.h>
34 #include <lw_string.h> 34 #include <lw_string.h>
35 #include <lw_error.h> 35 #include <lw_error.h>
36 36
37 #include "lwasm.h" 37 #include "lwasm.h"
38 #include "input.h"
38 39
39 /* 40 /*
40 Data type for storing input buffers 41 Data type for storing input buffers
41 */ 42 */
42 43
47 input_type_file, // regular file, no search path 48 input_type_file, // regular file, no search path
48 input_type_include, // include path, start from "local" 49 input_type_include, // include path, start from "local"
49 input_type_string, // input from a string 50 input_type_string, // input from a string
50 51
51 input_type_error // invalid input type 52 input_type_error // invalid input type
53 };
54
55 struct input_stack_node
56 {
57 input_stack_entry *entry;
58 struct input_stack_node *next;
52 }; 59 };
53 60
54 struct input_stack 61 struct input_stack
55 { 62 {
56 struct input_stack *next; 63 struct input_stack *next;
57 int type; 64 int type;
58 void *data; 65 void *data;
59 int data2; 66 int data2;
60 char *filespec; 67 char *filespec;
68 struct input_stack_node *stack;
61 }; 69 };
62 70
63 static char *make_filename(char *p, char *f) 71 static char *make_filename(char *p, char *f)
64 { 72 {
65 int l; 73 int l;
133 141
134 t -> type = input_type_string; 142 t -> type = input_type_string;
135 t -> data = lw_strdup(str); 143 t -> data = lw_strdup(str);
136 t -> data2 = 0; 144 t -> data2 = 0;
137 t -> next = IS; 145 t -> next = IS;
146 t -> stack = NULL;
138 as -> input_data = t; 147 as -> input_data = t;
139 // t -> filespec = lw_strdup(s); 148 // t -> filespec = lw_strdup(s);
140 } 149 }
141 150
142 void input_open(asmstate_t *as, char *s) 151 void input_open(asmstate_t *as, char *s)
168 t -> type = input_type_error; 177 t -> type = input_type_error;
169 178
170 lw_free(ts); 179 lw_free(ts);
171 } 180 }
172 t -> next = as -> input_data; 181 t -> next = as -> input_data;
182 t -> stack = NULL;
173 as -> input_data = t; 183 as -> input_data = t;
174 184
175 switch (IS -> type) 185 switch (IS -> type)
176 { 186 {
177 case input_type_include: 187 case input_type_include:
432 { 442 {
433 if (IS) 443 if (IS)
434 return IS -> filespec; 444 return IS -> filespec;
435 return NULL; 445 return NULL;
436 } 446 }
447
448 void input_stack_push(asmstate_t *as, input_stack_entry *e)
449 {
450 struct input_stack_node *n;
451
452 n = lw_alloc(sizeof(struct input_stack_node));
453 n -> next = IS -> stack;
454 n -> entry = e;
455 }
456
457 input_stack_entry *input_stack_pop(asmstate_t *as, int magic, int (*fn)(input_stack_entry *e, void *data), void *data)
458 {
459 struct input_stack_node *n, *n2;
460 input_stack_entry *e2;
461
462 n2 = NULL;
463 for (n = IS -> stack; n; n = n -> next)
464 {
465 if (n -> entry -> magic == magic)
466 {
467 if ((*fn)(n -> entry, data))
468 {
469 /* we have a match */
470 e2 = n -> entry;
471 if (n2)
472 n2 -> next = n -> next;
473 else
474 IS -> stack = n -> next;
475 lw_free(n);
476 return e2;
477 }
478 }
479 n2 = n;
480 }
481 return NULL;
482 }