src/compiler.c
// Emit assembly code compatible with the FASM assembler
Emit assembly code compatible with the FASM assembler
Emit assembly code compatible with the FASM assembler
void EmitFasm(char* filename, struct tree_node* root, char* org)
{
	fp = fopen(filename, "w+");
	if (!streq(org, ""))
	{
		fprintf(fp, "org %s\n", org);
	}
	function* f = LookupFunction(fTable, "main");	
	if (f->frameSize - f->paramSize > 0)
		fprintf(fp, "sub sp, %d\n", f->frameSize - f->paramSize);	
	fprintf(fp, "call _main\n");
	if (f->frameSize > 0)
		fprintf(fp, "add sp, %d\n", f->frameSize);	
	fprintf(fp, "ret\n");
	EmitHelper(root);
	fprintf(fp, "\n");
	AppendStringLiterals();
	fclose(fp);
}
void EmitFasm ( char * filename , struct tree_node * root , char * org ) { fp = fopen ( filename , " " ) ; if ( ! streq ( org , " " ) ) { fprintf ( fp , " \n " , org ) ; } function * f = LookupFunction ( fTable , " " ) ; if ( f -> frameSize - f -> paramSize > 0 ) fprintf ( fp , " \n " , f -> frameSize - f -> paramSize ) ; fprintf ( fp , " \n " ) ; if ( f -> frameSize > 0 ) fprintf ( fp , " \n " , f -> frameSize ) ; fprintf ( fp , " \n " ) ; EmitHelper ( root ) ; fprintf ( fp , " \n " ) ; AppendStringLiterals ( ) ; fclose ( fp ) ; }
Emit assembly code compatible with the FASM assembler
Emit assembly code compatible with the FASM assembler
// Open file // Add org statement if memory placement specified // Call main // function struct // Call function // reserve local variable stack space // restore stack memory // Write the rest of the program code // Add string literal code // Close file