annotate leo-obj/tool/hints.c @ 378:82fb5a70c9fd

compal/audio: results of simple experiments
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Oct 2021 23:20:00 +0000
parents 81fc8da9a29c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Parsing of the disassembly hints file
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "intstruct.h"
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "globals.h"
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 static char *filename_for_err;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 static int lineno;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 static struct internal_scnhdr *section;
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
17 static struct hint *lasthint;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 static void
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 set_section(name)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 char *name;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 unsigned n;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 struct internal_scnhdr *sec = 0;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 for (n = 0; n < nsections; n++)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 if (!strcmp(sections[n].name, name)) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 sec = sections + n;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 break;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (!sec) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 fprintf(stderr, "%s line %d: no section named \"%s\" in %s\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 filename_for_err, lineno, name, objfilename);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
36 if (sec->hints) {
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 fprintf(stderr, "%s line %d: [%s] given more than once\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 filename_for_err, lineno, name);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 section = sec;
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
42 lasthint = 0;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 static void
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 set_mode(arg)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 char *arg;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 char *cp;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 if (!section) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 fprintf(stderr,
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 "%s line %d: error: mode line outside of section\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 filename_for_err, lineno);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 while (isspace(*arg))
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 arg++;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (!*arg) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 fprintf(stderr, "%s line %d: mode line: missing argument\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 filename_for_err, lineno);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 for (cp = arg; *cp && !isspace(*cp); cp++)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 ;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (*cp)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 *cp++ = '\0';
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (!strcmp(arg, "code"))
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
69 section->disasm_mode = DISASM_MODE_CODE;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 else if (!strcmp(arg, "data"))
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
71 section->disasm_mode = DISASM_MODE_DATA;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 else if (!strcmp(arg, "bss"))
127
a314d6aa9bf1 tiobjd: section disasm mode hinting rethought
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
73 section->disasm_mode = DISASM_MODE_BSS;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 else {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 fprintf(stderr, "%s line %d: unknown mode \"%s\"\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 filename_for_err, lineno, arg);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 static void
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 regular_hint(arg1, arg2)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 char *arg1, *arg2;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 {
134
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
85 struct hint *hint;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
86 char *cp, *np;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
87
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
88 if (!section) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
89 fprintf(stderr,
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
90 "%s line %d: error: hint line outside of section\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
91 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
92 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
93 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
94 hint = malloc(sizeof(struct hint));
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
95 if (!hint) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
96 perror("malloc");
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
97 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
98 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
99 hint->pos = strtoul(arg1, &cp, 16);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
100 if (*cp == '-') {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
101 cp++;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
102 hint->endpos = strtoul(cp, &cp, 16);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
103 } else
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
104 hint->endpos = hint->pos;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
105 if (*cp) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
106 fprintf(stderr, "%s line %d: invalid hint position syntax\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
107 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
108 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
109 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
110 if (hint->endpos < hint->pos) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
111 fprintf(stderr, "%s line %d: range going backward\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
112 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
113 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
114 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
115 if (lasthint && hint->pos <= lasthint->endpos) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
116 fprintf(stderr, "%s line %d: hint pos <= previous\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
117 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
118 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
119 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
120 hint->type = 0;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
121 hint->linebrk = 0;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
122 hint->next = 0;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
123 for (cp = arg2; isspace(*cp); cp++)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
124 ;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
125 if (!*cp) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
126 fprintf(stderr, "%s line %d: no keyword after hint pos\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
127 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
128 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
129 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
130 for (np = cp; *cp && !isspace(*cp); cp++)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
131 ;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
132 if (*cp)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
133 *cp++ = '\0';
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
134 if (!strcmp(np, "linebrk") || !strcmp(np, "linebreak")) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
135 hint->linebrk = 1;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
136 while (isspace(*cp))
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
137 cp++;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
138 if (!*cp || *cp == '#') {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
139 if (hint->endpos != hint->pos) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
140 fprintf(stderr,
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
141 "%s line %d: no range allowed for linebrk hints\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
142 filename_for_err, lineno);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
143 exit(1);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
144 }
134
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
145 goto out;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
146 }
134
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
147 for (np = cp; *cp && !isspace(*cp); cp++)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
148 ;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
149 if (*cp)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
150 *cp++ = '\0';
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
151 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
152 if (!strcmp(np, "d8"))
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
153 hint->type = HINT_D8;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
154 else if (!strcmp(np, "d16"))
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
155 hint->type = HINT_D16;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
156 else if (!strcmp(np, "d32"))
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
157 hint->type = HINT_D32;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
158 else if (!strcmp(np, "asciz"))
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
159 hint->type = HINT_ASCIZ;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
160 else {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
161 fprintf(stderr, "%s line %d: unknown hint keyword \"%s\"\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
162 filename_for_err, lineno, np);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
163 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
164 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
165 /* enforce alignment and range restrictions */
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
166 switch (hint->type) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
167 case HINT_D16:
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
168 if (hint->pos & 1 || hint->endpos & 1) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
169 fprintf(stderr, "%s line %d: d16 hint misaligned\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
170 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
171 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
172 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
173 break;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
174 case HINT_D32:
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
175 if (hint->pos & 3 || hint->endpos & 3) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
176 fprintf(stderr, "%s line %d: d32 hint misaligned\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
177 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
178 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
179 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
180 break;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
181 case HINT_ASCIZ:
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
182 if (hint->endpos != hint->pos) {
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
183 fprintf(stderr,
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
184 "%s line %d: no range allowed for asciz hints\n",
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
185 filename_for_err, lineno);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
186 exit(1);
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
187 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
188 break;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
189 }
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
190 out: if (lasthint)
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
191 lasthint->next = hint;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
192 else
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
193 section->hints = hint;
c131238c56bf tiobjd: implemented parsing of the hint input files
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
194 lasthint = hint;
126
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 read_hints_file(filename)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 char *filename;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 FILE *f;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 char linebuf[128], *cp, *np;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 f = fopen(filename, "r");
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 if (!f) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 perror(filename);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 filename_for_err = filename;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 for (cp = linebuf; isspace(*cp); cp++)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 ;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 if (!*cp || *cp == '#')
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 continue;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 if (*cp == '[') {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 np = ++cp;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 cp = index(cp, ']');
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 if (!cp) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 fprintf(stderr,
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 "%s line %d: invalid section syntax\n",
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 filename, lineno);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 exit(1);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 *cp = '\0';
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 set_section(np);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 continue;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 for (np = cp; *cp && !isspace(*cp); cp++)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 ;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 if (*cp)
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 *cp++ = '\0';
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 if (!strcmp(np, "mode")) {
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 set_mode(cp);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 continue;
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 regular_hint(np, cp);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 }
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 fclose(f);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 return(0);
2c6b1319383b tiobjd: first preparations for adding disasm hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 }