annotate lwasm/unicorns.c @ 333:507f442dc71e

Add support for 6800 compatibility instructions. The occasional program uses the 6800 compatibility instructions since they are actually specified by Motorola in at least some documentation. They advertised the 6809 as source compatible with the 6800. This mode is not enabled by default, however. It is my belief that receiving an error when using a non-6809 instruction is more useful since it is unlikely that much 6800 source code is being assembled for the 6809 these days. Nevertheless, the --6809compat option is present for just those purposes so one does not have to resort to using macros (which would work equally well in most cases).
author William Astle <lost@l-w.ca>
date Tue, 15 Apr 2014 10:57:34 -0600
parents 164487152dd9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
2 unicorns.c
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
3
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2012 William Astle
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
5
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
7
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
12
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
17
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
21
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
22 /*
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
23 This adds output to lwasm that is suitable for IDEs and other tools
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
24 that are interesting in the doings of the assembler.
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
25 */
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
26
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
27 #include <stdio.h>
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
28 #include <string.h>
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
29
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 223
diff changeset
30 #include "input.h"
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
31 #include "lwasm.h"
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
32 #include "lw_alloc.h"
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
33
228
042c7b74faf0 Make unicorns not suppress assembly listings.
William Astle <lost@l-w.ca>
parents: 226
diff changeset
34 void do_list(asmstate_t *as);
042c7b74faf0 Make unicorns not suppress assembly listings.
William Astle <lost@l-w.ca>
parents: 226
diff changeset
35
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
36 static void print_urlencoding(FILE *stream, const char *string)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
37 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
38 for ( ; *string; string++)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
39 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
40 if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *string))
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
41 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
42 fprintf(stream, "%%%02X", *string);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
43 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
44 else
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
45 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
46 fputc(*string, stream);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
47 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
48 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
49 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
50
226
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
51 static void show_unicorn_error(FILE *fp, line_t *l, lwasm_error_t *ee, const char *tag)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
52 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
53 fprintf(fp, "%s: lineno=%d,filename=", tag, l -> lineno);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
54 print_urlencoding(fp, l -> linespec);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
55 fputs(",message=", fp);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
56 print_urlencoding(fp, ee -> mess);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
57 if (ee -> charpos > 0)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
58 fprintf(fp, ",col=%d", ee -> charpos);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
59 fputc('\n', fp);
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
60 }
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
61
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
62 void lwasm_do_unicorns(asmstate_t *as)
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
63 {
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 223
diff changeset
64 struct ifl *ifl;
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
65 macrotab_t *me;
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
66 structtab_t *se;
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
67 int i;
226
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
68 line_t *l;
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
69 lwasm_error_t *ee;
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
70
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
71 /* output file list */
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 223
diff changeset
72 for (ifl = ifl_head; ifl; ifl = ifl -> next)
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
73 {
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
74 fputs("RESOURCE: type=file,filename=", stdout);
224
3864d96ee8c7 Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents: 223
diff changeset
75 print_urlencoding(stdout, ifl -> fn);
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
76 fputc('\n', stdout);
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
77 }
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
78
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
79 /* output macro list */
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
80 for (me = as -> macros; me; me = me -> next)
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
81 {
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
82 fprintf(stdout, "RESOURCE: type=macro,name=%s,lineno=%d,filename=", me -> name, me -> definedat -> lineno);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
83 print_urlencoding(stdout, me -> definedat -> linespec);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
84 fputs(",flags=", stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
85 if (me -> flags & macro_noexpand)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
86 fputs("noexpand", stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
87 fputs(",def=", stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
88 for (i = 0; i < me -> numlines; i++)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
89 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
90 if (i)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
91 fputc(';', stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
92 print_urlencoding(stdout, me -> lines[i]);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
93 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
94 fputc('\n', stdout);
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
95 }
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
96
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
97 /* output structure list */
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
98 for (se = as -> structs; se; se = se -> next)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
99 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
100 fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
101 print_urlencoding(stdout, se -> definedat -> linespec);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
102 fputc('\n', stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
103 }
226
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
104
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
105 /* output error and warning lists */
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
106 for (l = as -> line_head; l; l = l -> next)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
107 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
108 if (l -> err)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
109 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
110 for (ee = l -> err; ee; ee = ee -> next)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
111 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
112 show_unicorn_error(stdout, l, ee, "ERROR");
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
113 }
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
114 }
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
115
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
116 if (l -> warn)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
117 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
118 for (ee = l -> warn; ee; ee = ee -> next)
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
119 {
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
120 show_unicorn_error(stdout, l, ee, "WARNING");
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
121 }
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
122 }
7c2c2239ec9c Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents: 224
diff changeset
123 }
228
042c7b74faf0 Make unicorns not suppress assembly listings.
William Astle <lost@l-w.ca>
parents: 226
diff changeset
124
229
164487152dd9 Add flag to output stream for end of unicorns
William Astle <lost@l-w.ca>
parents: 228
diff changeset
125 fprintf(stdout, "UNICORNSAWAY:\n");
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
126 }