Include file iff_bhav.h
#ifndef __SIMS_iff_bhav_h
#define __SIMS_iff_bhav_h
#include <iosfwd>
class simIFF_BHAV
{
typedef unsigned char uc_t;
uc_t *m_instructions; // array of instructions
int m_fld2; unsigned short m_fld1; // unknowns
unsigned short m_sig; // signature
uc_t m_hdr; // length of header
uc_t m_count; // number of instructions
uc_t m_locals; // number of stack locals
uc_t m_params; // number of parameters
simIFF_BHAV(const simIFF_BHAV&); // no copy
void operator=(const simIFF_BHAV&); // no assign
public:
static inline int w(const unsigned char *byte) { // DEBUG
return (byte[1]<<8) | byte[0];
}
simIFF_BHAV(std::istream *in, unsigned char *h = 0);
simIFF_BHAV(uc_t *i, int c, int p, int l, int f1 = 0, int f2 = 0)
: m_instructions(i), m_fld2(f2), m_fld1(f1), m_sig(0x8002),
m_hdr(12), m_count(c), m_locals(l), m_params(p) {}
~simIFF_BHAV(void);
bool err(void) const { return m_instructions == 0; }
// decoded header information
int sig(void) { return m_sig; }
int hdr(void) { return m_hdr; }
int count(void) { return m_count; }
int locals(void) { return m_locals; }
int params(void) { return m_params; }
int fld1(void) { return m_fld1; }
int fld2(void) { return m_fld2; }
// instructions
const unsigned char *inst(int i) const { return m_instructions + 12*i; }
int op(int i) { return w(&m_instructions[i*12]); }
int br1(int i) { return m_instructions[i*12 + 2]; }
int br2(int i) { return m_instructions[i*12 + 3]; }
int oper(int i, int j) { return w(&m_instructions[i*12 + j*2 + 2]); }
};
class simIFF;
class simIFF_BHAV_analyze
{
typedef unsigned char Ref;
public:
struct Block {
Ref m_flow; // next reordered instruction
Ref m_loc; // location after resequencing
//Ref m_reloc; // real index after resequencing
Ref m_type; // flow type
Ref m_pop; // how much to outdent
};
private:
simIFF_BHAV &m_bhav; // instructions being analyzed
Block *m_blocks; // one for each instruction
simIFF *m_myfile; // IFF file in which BHAV occurs
simIFF *m_semiglobal; // related semi-global IFF file
simIFF_BHAV_analyze(const simIFF_BHAV_analyze&); // no copy
void operator=(const simIFF_BHAV_analyze&); // no assign
public: // flow types assigned to instructions
enum flows {
flow_unknown, // not yet analyzed
flow_orphan, // unused instruction
flow_normal, // both branches expressed
flow_then, // suppress false, next is "then"
flow_else, // suppress true, next is "then"
flow_else_t, // suppress true, next is "else"
flow_else_f, // suppress false, next is "else"
flow_else_x, // suppress neither, next is "else"
};
simIFF_BHAV_analyze(simIFF_BHAV &bhav);
~simIFF_BHAV_analyze(void);
void set_file(simIFF *f); // set local context
void set_semiglobal(simIFF *f); // set semiglobal context
void show(int ix); // print raw instruction
static void show(const unsigned char *inst,
int dest1 = -1, int dest2 = -1);
void decode(int ix); // decode and print one instruction
void display(void); // pretty-print all instructions
void analyze(void); // untangle sequencing
void resequence(void); // renumber after analyzing
const Block &operator[](int ix) { return m_blocks[ix]; }
};
#endif // __SIMS_iff_bhav_h
Copyright ©
2001-2008 Dave Baum and Greg Noel. All rights reserved.
The Sims™ is a trademark of Maxis and Electronic Arts.
This page was last modified Monday, 03-May-2004 06:44:32 UTC.
The Sims™ is a trademark of Maxis and Electronic Arts.
This page was last modified Monday, 03-May-2004 06:44:32 UTC.
