annotate lwasm/pass1.c @ 337:04c80c51b16a

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