/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "Instruction.h"
#include <iostream>

//#define FUZZ_BYTE_0
//#define FUZZ_BYTE_1
//#define FUZZ_BYTE_2
//#define FUZZ_BYTE_3

int main(int argc, char *argv[]) {

	(void)argc;
	(void)argv;
	
	uint8_t buf[] =  { 0xe6, 0x71 };


	srand(time(0));
	//buf[0] = (uint8_t)rand();

#ifdef FUZZ_BYTE_0
	for(int i0 = 0; i0 < 0x100; ++i0) {
	buf[0] = i0;
#endif
#ifdef FUZZ_BYTE_1
	for(int i1 = 0; i1 < 0x100; ++i1) {
	buf[1] = i1;
#endif
#ifdef FUZZ_BYTE_2
	for(int i2 = 0; i2 < 0x100; ++i2) {
	buf[2] = i2;
#endif
#ifdef FUZZ_BYTE_3
	for(int i3 = 0; i3 < 0x100; ++i3) {
	buf[3] = i3;
#endif		
		for(unsigned int j = 0; j < sizeof(buf); ++j) {
			printf("%02x", buf[j]);
			if(j != sizeof(buf) - 1) {
				printf(" ");
			} else {
				printf(": ");
			}
		}

		try {
			Instruction instruction(buf, sizeof(buf), 0x8006c2b2);
			printf("%s\n", instruction.format().c_str());
		} catch(const instruction_too_big &e) {
			std::cout << "not enough bytes available: " << e.size() << std::endl;
		} catch(const invalid_operand &e) {
			std::cout << "invalid operand: " << e.size() << std::endl;
		} catch(const invalid_instruction &e) {
			std::cout << "invalid instruction: " << e.size() << std::endl;
		}
#ifdef FUZZ_BYTE_0
	}
#endif
#ifdef FUZZ_BYTE_1
	}
#endif
#ifdef FUZZ_BYTE_2
	}
#endif
#ifdef FUZZ_BYTE_3
	}
#endif

	return 0;
}
