mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All 
................................................ contributions are welcome. 
....Copyright(C).1995.Melvin.Smith.............. Enjoy. 
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@hom.net
MUD++ development mailing list    mudpp@van.ml.org
------------------------------------------------------------------------------
asmparser.h
*/

#ifndef _ASMPARSER_H
#define _ASMPARSER_H

#include "string.h"
#include "io.h"
#include "llist.h"
#include "array.h"
#include "asmobjfile.h"

class AsmParser;

struct _parser_table
{
	char * name;
	u8 opcode;
	bool (AsmParser::*mnem2code) (memorycell);
	int (AsmParser::*code2mnem) (const memorycell*, String & str);
	// in-memory debugging stuff to be added
};

typedef struct
{
	String name;
	u16 adress;
	Array< int >	to_resolve;
} label;

class AsmParser
{
	protected:

		StaticInput * inf;
		Output * outf;
		AsmObjFile * obj;
		LList< label > labels;
		Array< String > locals;
		Array< int > shortjumps;
		int args_count;
		int vars_count;
		int funstart;
		char funname[256];
		bool infun;


		u16 getLabel(char * name, int adress);
		void setLabel(char * name, int adress);

		int readConstant();
		void readVariable();
		int lookupLocal( const char * txt );
		u8 parseConditions(const char *);
		void setAbsoluteJump( int point, int to );
		void clearLabels();

		bool read_jump(memorycell cell);
		bool read_cond_jump(memorycell cell);
		bool read_cond_local_var_jump(memorycell cell);
		bool read_local_var(memorycell cell);
		bool read_local_var_int(memorycell cell);
		bool read_local_var_float(memorycell cell);
		bool read_local_var_constant(memorycell cell);
		bool read_fun_call(memorycell cell);
		bool read_interface_call(memorycell cell);
		bool read_unknown_call(memorycell cell);
		bool read_const(memorycell cell);
		bool read_static(memorycell cell);
		bool read_u8(memorycell cell);
		bool read_u16(memorycell cell);
		bool read_s16(memorycell cell);
		bool read_s32(memorycell cell);
		bool read_float(memorycell cell);
		bool read_ilookupswitch( memorycell cell );
		bool read_slookupswitch( memorycell cell );
		bool read_itableswitch( memorycell cell );
		bool read_field( memorycell cell );
		bool read_classname( memorycell cell );
		bool paramless(memorycell cell);
		

	public:
		AsmParser()  :
			inf(0), outf(0), obj(0), funstart(0), infun(false)
		{}

		int parse(StaticInput & inf, Output & outf);
		static struct _parser_table parser_table[];
		
};

const char * lookupOpcodeName( u8 opc );

#endif