ack/util/ceg/assemble/as_assemble/assemble.c

64 lines
1.3 KiB
C
Raw Normal View History

1987-11-20 11:12:07 +00:00
#include <ctype.h>
#include <system.h>
#include "em_decl.h"
1987-11-26 12:14:32 +00:00
/* This file contains the assemble routine that generates assembly code.
* As 'str' is in assembly format this is a easy job. Only operands
* with "$n" in it need some special treatment.
* Note : a '$' is qouted by prefixing it with a '$'.
*/
1987-11-20 11:12:07 +00:00
assemble( str)
char *str;
1987-11-26 12:14:32 +00:00
/* Output assembly instruction. Substitute for '$n' the name of the
* the n-th argument of the current EM-instruction.
*/
1987-11-20 11:12:07 +00:00
{
char buf[512] , *b_ptr, *arg_format();
int nr;
b_ptr = buf;
out( "fprint( codefile,\"");
while ( *str) {
switch ( *str) {
case '$' : if ( *(str+1) == '$') {
*b_ptr++ = '$';
str = str + 2;
}
1987-11-26 12:14:32 +00:00
else {
1987-11-20 11:12:07 +00:00
nr = atoi( str+1) - 1;
*b_ptr = '\0';
1989-01-26 15:20:56 +00:00
out( "%s%s\", %s%s);", buf,
1987-11-20 11:12:07 +00:00
arg_format( nr),
1989-01-26 15:20:56 +00:00
C_instr_info->arg_type[nr] == ARITH ? "(long)" : "",
1987-11-20 11:12:07 +00:00
C_instr_info->arg_conv[nr]);
out( "fprint( codefile,\"");
b_ptr = buf;
str = str + 2;
}
break;
1990-03-07 16:24:06 +00:00
case '%': *b_ptr++ = *str;
/* fall through */
1987-11-20 11:12:07 +00:00
default : *b_ptr++ = *str++;
}
}
*b_ptr = '\0';
out( "%s\\n\");\n", buf);
}
char *arg_format( nr)
int nr;
{
switch ( C_instr_info->arg_type[nr]) {
1989-01-26 15:20:56 +00:00
case ARITH : return( "%ld");
1987-11-20 11:12:07 +00:00
case STRING: return( "%s");
1989-01-26 15:20:56 +00:00
case INT : return( "%d");
1987-11-20 11:12:07 +00:00
}
1989-01-26 15:20:56 +00:00
/*NOTREACHED*/
1987-11-20 11:12:07 +00:00
}