332
|
1 /*
|
|
2 pass1.c
|
|
3
|
|
4 Copyright © 2010 William Astle
|
|
5
|
|
6 This file is part of LWTOOLS.
|
|
7
|
|
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
|
|
9 terms of the GNU General Public License as published by the Free Software
|
|
10 Foundation, either version 3 of the License, or (at your option) any later
|
|
11 version.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
16 more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License along with
|
|
19 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 */
|
|
21
|
|
22 #include <config.h>
|
|
23
|
|
24 #include <stdio.h>
|
|
25
|
|
26 #include <lw_alloc.h>
|
|
27
|
|
28 #include "lwasm.h"
|
|
29 #include "input.h"
|
|
30
|
337
|
31 /*
|
|
32 pass 1: parse the lines
|
|
33 */
|
332
|
34 void do_pass1(asmstate_t *as)
|
|
35 {
|
|
36 char *line;
|
337
|
37 line_t *cl;
|
|
38
|
332
|
39 for (;;)
|
|
40 {
|
|
41 line = input_readline(as);
|
|
42 if (!line)
|
|
43 break;
|
|
44 printf("%s\n", line);
|
337
|
45
|
|
46 cl = lw_alloc(sizeof(line_t));
|
|
47 cl -> next = NULL;
|
|
48 cl -> prev = as -> line_tail;
|
|
49 cl -> len = -1;
|
|
50 cl -> insn = -1;
|
|
51 if (!as -> line_tail)
|
|
52 {
|
|
53 as -> line_head = cl;
|
|
54 cl -> addr = lw_expr_build(lw_expr_type_int, 0);
|
|
55 }
|
|
56 else
|
|
57 {
|
|
58 lw_expr_t te;
|
|
59 as -> line_tail -> next = cl;
|
|
60 te = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, cl -> prev);
|
|
61 cl -> addr = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, cl -> prev -> addr, te);
|
|
62 lw_expr_destroy(te);
|
|
63 lw_expr_simplify(cl -> addr);
|
|
64 }
|
|
65 as -> line_tail = cl;
|
|
66
|
|
67 lw_expr_print(cl -> addr);
|
|
68 printf("\n");
|
|
69 // now parse the line
|
|
70
|
332
|
71 lw_free(line);
|
|
72 }
|
|
73 }
|