annotate lwasm/unicorns.c @ 223:211fc8038b8d

More unicorn stuff - structs and macros Settled on an output format for unicorn stuff and added structs and macros to that output. Format is: TYPE: <key>=<value>[,<key>=<value>]* Any <value> which has special characters will use urlencoding. Values with multiple values use a semicolon as a separator.
author William Astle <lost@l-w.ca>
date Sun, 15 Jul 2012 20:14:51 -0600
parents 03f7192fcd20
children 3864d96ee8c7
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
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
30 #include "lwasm.h"
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
31 #include "lw_alloc.h"
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
32
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
33 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
34 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
35 for ( ; *string; string++)
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
36 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
37 if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *string))
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
38 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
39 fprintf(stream, "%%%02X", *string);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
40 }
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
41 else
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
42 {
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
43 fputc(*string, stream);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
44 }
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
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
48 void lwasm_do_unicorns(asmstate_t *as)
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
49 {
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
50 char *n;
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
51 macrotab_t *me;
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
52 structtab_t *se;
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
53 int i;
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
54
222
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
55 /* output file list */
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
56 while ((n = lw_stack_pop(as -> includelist)))
03f7192fcd20 Add --unicorns option for IDE integration
William Astle <lost@l-w.ca>
parents:
diff changeset
57 {
223
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
58 fputs("RESOURCE: type=file,filename=", stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
59 print_urlencoding(stdout, n);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
60 fputc('\n', stdout);
211fc8038b8d More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents: 222
diff changeset
61 lw_free(n);
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 }