1 #ifndef __EXEC_TRAIL_HPP__
2 #define __EXEC_TRAIL_HPP__
3 
4 /* "Species" - a CoreWars evolver.  Copyright (C) 2004 'Varfar'
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 1, or (at your option) any later
9  * version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #include "exhaust.hpp"
22 
23 #include <string>
24 
25 class COpcodeMap {
26 	public:
27 		COpcodeMap();
28 		unsigned opmap(field_t field) const;
segments() const29 		unsigned segments() const { return 10; } // arb
optypes() const30 		unsigned optypes() const { return MAX_OPTYPES; }
segsize() const31 		unsigned segsize() const { return 80000/segments(); }
32 	private:
33 		enum OPTYPE {
34 			SPLIT,
35 			MOVI,
36 			MATH,
37 			BRANCH,
38 			OTHER,
39 			MAX_OPTYPES
40 		} _opmap[MAX_OPCODES];
41 		void mapop(OPCODE op,OPTYPE type);
42 		void mapop(OPCODE op,MODIFIER mod,OPTYPE type);
43 		void makeopmap();
44 };
45 
46 class CExecTrail {
47 	public:
48 		typedef unsigned long long dist_t;
49 		CExecTrail(COpcodeMap *map);
50 		~CExecTrail();
51 		void clear();
52 		bool load_from_file(const char *filename); // returns success
filename() const53 		std::string filename() const { return _filename; }
54 		void set(unsigned const segment,dist_t table[MAX_OPCODES]); // table[SEGMENTS][MAX_OPCODES]
55 		dist_t distance_squared(CExecTrail const *other) const;
56 		dist_t max_distance_from() const;
57 	private:
58 		std::string _filename;
59 		static const dist_t ZERO = 0ull;
60 		static const dist_t BLOODY_MASSIVE = 0xFFFFFFFFFFFFFFFFull;
61 		COpcodeMap *_map;
62 		dist_t **_exec_count;
63 };
64 
65 #endif // __EXEC_TRAIL_HPP__
66