*** empty log message ***
This commit is contained in:
		
							parent
							
								
									79457dabd1
								
							
						
					
					
						commit
						8202444413
					
				
					 3 changed files with 43 additions and 16 deletions
				
			
		| 
						 | 
					@ -3,13 +3,38 @@
 | 
				
			||||||
#include "as.h"
 | 
					#include "as.h"
 | 
				
			||||||
#include "const.h"
 | 
					#include "const.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* This file contains the routine assemble(). Assemble() cuts an
 | 
				
			||||||
 | 
					 * assembly instruction in a label, a mnemonic and several operands.
 | 
				
			||||||
 | 
					 * For a label and operands it calls table writer defined routines, 
 | 
				
			||||||
 | 
					 * process_label() and process_operand(), to give the table writer 
 | 
				
			||||||
 | 
					 * the oppurtunity to do something special. At the end assemble() calls
 | 
				
			||||||
 | 
					 * the routine belonging to the mnemonic with the supplied operands.
 | 
				
			||||||
 | 
					 *     If the table writer has other expectations of assemble() he should
 | 
				
			||||||
 | 
					 * write his own version.
 | 
				
			||||||
 | 
					 * 	Assemble parser the following instructions :
 | 
				
			||||||
 | 
					 * INSTR ::= [ STRING ':']? [ STRING [ OPERAND ( ',' OPERAND)*]? ]?
 | 
				
			||||||
 | 
					 * OPERAND ::= STRING [ '{' char* '}' |
 | 
				
			||||||
 | 
					 * 			'(' char* ')' | 
 | 
				
			||||||
 | 
					 * 			'[' char* ']'     ]?
 | 
				
			||||||
 | 
					 * note : nested brackets are not recognized.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The following global varaibles are defined in the EM_parser.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern char *mnemonic[];
 | 
					extern char *mnemonic[];
 | 
				
			||||||
extern int (*instruction[])(), n_mnems;
 | 
					extern int (*instruction[])(), n_mnems;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The struct t_operand must be defined by the table writer in "as.h".
 | 
				
			||||||
 | 
					 * The constant MAX_OPERANDS is defined in "const.h"
 | 
				
			||||||
 | 
					 * To change MAX_OPERANDS effectively, the last statement in 
 | 
				
			||||||
 | 
					 * execute_mnem() must be changed.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct t_operand operand[ MAX_OPERANDS];
 | 
					struct t_operand operand[ MAX_OPERANDS];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* To change MAX_OPERANDS, the last statement in execute_mnem() must
 | 
					 | 
				
			||||||
 * be changed.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *skip_space(), *parse_label(), *parse_mnemonic(), *parse_operand(),
 | 
					char *skip_space(), *parse_label(), *parse_mnemonic(), *parse_operand(),
 | 
				
			||||||
| 
						 | 
					@ -19,12 +44,7 @@ int  label();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
assemble( instr)
 | 
					assemble( instr)
 | 
				
			||||||
	char *instr;
 | 
						char *instr;
 | 
				
			||||||
 | 
					/* Break an assembly instruction down in a LABEL, MNEMONIC and OPERANDS.
 | 
				
			||||||
/* INSTR ::= [ STRING ':']? [ STRING [ OPERAND ( ',' OPERAND)*]? ]?
 | 
					 | 
				
			||||||
 * OPERAND ::= STRING [ '{' char* '}' |
 | 
					 | 
				
			||||||
 * 			'(' char* ')' | 
 | 
					 | 
				
			||||||
 * 			'[' char* ']'     ]?
 | 
					 | 
				
			||||||
 * Break an assembly instruction down in a LABEL, MNEMONIC and OPERANDS.
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char *ptr, *copy, *mnem;
 | 
						char *ptr, *copy, *mnem;
 | 
				
			||||||
| 
						 | 
					@ -33,19 +53,19 @@ assemble( instr)
 | 
				
			||||||
	copy = ptr = Salloc( instr, strlen( instr)+1);
 | 
						copy = ptr = Salloc( instr, strlen( instr)+1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ptr = skip_space( ptr);
 | 
						ptr = skip_space( ptr);
 | 
				
			||||||
	if  ( label( ptr))  {
 | 
						if  ( label( ptr))  {     /* Look for a label */
 | 
				
			||||||
		ptr = parse_label( ptr);
 | 
							ptr = parse_label( ptr);
 | 
				
			||||||
		if  ( *ptr == '\0')  return;
 | 
							if  ( *ptr == '\0')  return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ptr = parse_mnemonic( ptr, &mnem);
 | 
						ptr = parse_mnemonic( ptr, &mnem);
 | 
				
			||||||
	while  ( *ptr != '\0')  {
 | 
						while  ( *ptr != '\0')  {  /* parse operans */
 | 
				
			||||||
		if ( n_ops++ == MAX_OPERANDS) 
 | 
							if ( n_ops++ == MAX_OPERANDS) 
 | 
				
			||||||
			error( "to many operands\n");
 | 
								error( "to many operands\n");
 | 
				
			||||||
		ptr = parse_operand( ptr, n_ops, instr);
 | 
							ptr = parse_operand( ptr, n_ops, instr);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	execute_mnemonic( mnem);
 | 
						execute_mnemonic( mnem);   /* Execute the assembler instruction */
 | 
				
			||||||
	free( copy);
 | 
						free( copy);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,7 +184,7 @@ char *ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/****************************************************************************/
 | 
					/*** Execution **************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
execute_mnemonic( mnem)
 | 
					execute_mnemonic( mnem)
 | 
				
			||||||
| 
						 | 
					@ -198,13 +218,15 @@ char *mnem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*** Error ****************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error( fmt, argv)
 | 
					error( fmt, argv)
 | 
				
			||||||
char *fmt;
 | 
					char *fmt;
 | 
				
			||||||
int argv;
 | 
					int argv;
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	extern int yylineno;
 | 
						extern int yylineno;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fprint( STDERR, "!! ERROR in line %d :	", yylineno);
 | 
						fprint( STDERR, "ERROR in line %d :	", yylineno);
 | 
				
			||||||
	doprnt( STDERR, fmt, &argv);
 | 
						doprnt( STDERR, fmt, &argv);
 | 
				
			||||||
	fprint( STDERR, "	!!\n");
 | 
						fprint( STDERR, "\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,10 @@
 | 
				
			||||||
block_assemble( instructions, nr, first, last)
 | 
					block_assemble( instructions, nr, first, last)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Assembles a block of assembly instructions. If the table writer wants 
 | 
				
			||||||
 | 
					 * to combine a block of instructions (e.g., push/pop optimization) he
 | 
				
			||||||
 | 
					 * should changes this routine to his own needs.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char **instructions;
 | 
					char **instructions;
 | 
				
			||||||
int nr, first, last;
 | 
					int nr, first, last;
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,3 @@
 | 
				
			||||||
 | 
					 | 
				
			||||||
#define Bool	int
 | 
					#define Bool	int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define TRUE		1
 | 
					#define TRUE		1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue