Mercurial > hg > index.cgi
annotate lwasm/unicorns.c @ 225:823560a8c251
Prevent infinite loop due to warning directive
Warning directive failed to set the line length to 0 which caused assembly
to hang since warnings are not fatal.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Jul 2012 21:19:04 -0600 |
parents | 3864d96ee8c7 |
children | 7c2c2239ec9c |
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 |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
34 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
|
35 { |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
36 for ( ; *string; 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 if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *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 fprintf(stream, "%%%02X", *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 else |
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 fputc(*string, stream); |
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 } |
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 |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 void lwasm_do_unicorns(asmstate_t *as) |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 { |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
51 struct ifl *ifl; |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 macrotab_t *me; |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
53 structtab_t *se; |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
54 int i; |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
55 |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 /* output file list */ |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
57 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
|
58 { |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
59 fputs("RESOURCE: type=file,filename=", stdout); |
224
3864d96ee8c7
Make unicorns notice referenced files better
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
60 print_urlencoding(stdout, ifl -> fn); |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
61 fputc('\n', stdout); |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 } |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 /* output macro list */ |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 for (me = as -> macros; me; me = me -> next) |
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
66 { |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
67 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
|
68 print_urlencoding(stdout, me -> definedat -> linespec); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
69 fputs(",flags=", stdout); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
70 if (me -> flags & macro_noexpand) |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
71 fputs("noexpand", stdout); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
72 fputs(",def=", stdout); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
73 for (i = 0; i < me -> numlines; i++) |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
74 { |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
75 if (i) |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
76 fputc(';', stdout); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
77 print_urlencoding(stdout, me -> lines[i]); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
78 } |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
79 fputc('\n', stdout); |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
80 } |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
81 |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
82 /* output structure list */ |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
83 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
|
84 { |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
85 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
|
86 print_urlencoding(stdout, se -> definedat -> linespec); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
87 fputc('\n', stdout); |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
88 } |
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
222
diff
changeset
|
89 |
222
03f7192fcd20
Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
90 } |