2 * Motorola to AT&T/GNU ASsembler syntax convertor
5 static char rcsid[] = "$Id$";
8 static char helptext[] =
9 "Motorola to AT&T/GNU ASsembler syntax convertor\n"
11 "Written in 1999 by Jan Kratochvil for Princip, a.s.\n"
12 " - released under GPL version 2 license, see http://www.gnu.org for details\n"
14 "for compilation of foo.s use the following command:\n"
15 "./mot2as <foo.s|as --bitwise-or --register-prefix-optional -o foo.o\n"
26 typedef unsigned char muchar;
28 enum fatality { WARN,ERR,FATAL };
31 #define LINE_MAX 16384
38 static void log(enum fatality fat,const char *fmt,...) __attribute__((format(printf,2,3)));
39 static void log(enum fatality fat,const char *fmt,...)
43 fprintf(stderr,"mot2as: %u: ",lino);
45 case WARN : fputs("Warning: ",stderr); break;
46 case ERR : fputs("Error : ",stderr); waserror=1; break;
47 case FATAL: fputs("Fatal : ",stderr); break;
50 vfprintf(stderr,fmt,ap);
53 if (fat==FATAL) exit(EXIT_FAILURE);
56 int main(int argc,char **argv)
62 fprintf(stderr,helptext,rcsid);
65 while (lino++,fgets(buf,sizeof(buf),stdin)) {
66 if (!(s=strchr(buf,'\n')))
67 log(ERR,"Line too long (>%u), cut",sizeof(buf)-2);
74 if (buf[0]=='l' && buf[1]=='b') buf[0]='L';
75 else if (buf[0]=='L') buf[0]='l';
83 while (s[1]==' ' || s[1]=='\t') s++;
85 if (fld==1 && !strncasecmp(s+1,"equ",3) && (s[1+3]==' ' || s[1+3]=='\t')) {
86 fputs("\t.equ\t",stdout);
87 fputs(buf,stdout); putchar(',');
92 if (fld==1) fputs(buf,stdout);
93 if (s2>buf && fld==1) putchar(':'); //label
94 if (!eq) putchar('\t');
95 defbyte|=(fld==1 && !strncasecmp(s+1,"dc.b",4) && (s[1+4]==' ' || s[1+4]=='\t'));
96 if (fld==1 && !strncasecmp(s+1,"opt",3) && (s[1+3]==' ' || s[1+3]=='\t')) putchar('|');
99 #ifdef PASS_THRU_COMMENTS
102 #endif PASS_THRU_COMMENTS
108 if (s[0]=='\\' && s[1]) putchar(*s++);
110 } while (*s && *s!='"');
113 case '\'': { //string
115 for (str=d=++s;*s;*d++=*s++) {
122 log(ERR,"String ('...) not terminated on this line");
126 if (d-str!=1 && d-str!=2 && d-str!=4)
127 log(ERR,"String ('...') in NOT-defbyte instruction is not of length 1, 2 or 4");
130 while (str<d) printf("%02X",(muchar)*str++);
135 printf("%u",(muchar)*str++);
136 if (str<d) putchar(',');
146 if (s>buf && !isalnum(s[-1]) && s[-1]!='_' && s[1]=='b' && s[2]!='_') *s='L';
149 if (s>buf && !isalnum(s[-1]) && s[-1]!='_') *s='l';
156 if (fld) putchar(*s);
158 if (!fld && *buf) { fputs(buf,stdout); putchar(':'); }