annotate lwasm/insn_logicmem.c @ 384:38b50ce6967a

Made --list and --depend work
author lost@starbug
date Sat, 15 May 2010 20:46:04 -0600
parents eacdae8a1575
children b8549694b4c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 insn_logicmem.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20 Contains code for handling logic/mem instructions
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
28 #include <lw_expr.h>
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
29
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
33 extern void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **optr);
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 362
diff changeset
34 extern void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen);
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
35 extern void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 // for aim, oim, eim, tim
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
38 PARSEFUNC(insn_parse_logicmem)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 const char *p2;
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
41 lw_expr_t *s;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
46 s = lwasm_parse_expr(as, p);
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
47 if (!s)
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
48 {
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
49 lwasm_register_error(as, l, "Bad operand");
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
50 return;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
51 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
53 lwasm_save_expr(l, 100, p);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 if (**p != ',' && **p != ';')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 {
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
56 lwasm_register_error(as, l, "Bad operand");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 // now we have a general addressing mode - call for it
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
63 insn_parse_gen_aux(as, l, p);
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
64 }
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
65
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
66 RESOLVEFUNC(insn_resolve_logicmem)
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
67 {
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
68 if (l -> len != -1)
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
69 return;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
70
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 362
diff changeset
71 insn_resolve_gen_aux(as, l, force, 1);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 }
362
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
73
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
74 EMITFUNC(insn_emit_logicmem)
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
75 {
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
76 lw_expr_t e;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
77 int v;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
78
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
79 e = lwasm_fetch_expr(l, 100);
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
80 if (!lw_expr_istype(e, lw_expr_type_int))
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
81 {
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
82 lwasm_register_error(as, l, "Immediate byte must be fully resolved");
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
83 return;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
84 }
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
85
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
86 v = lw_expr_intval(e);
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
87 if (v < -128 || v > 255)
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
88 {
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
89 lwasm_register_error(as, l, "Byte overflow");
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
90 return;
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
91 }
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
92
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
93 insn_emit_gen_aux(as, l, v);
4867f18c872f Added logic memory operands
lost@starbug
parents: 339
diff changeset
94 }