diff options
author | Tom Stellard <tstellar@gmail.com> | 2010-12-07 23:26:52 -0800 |
---|---|---|
committer | Tom Stellard <tstellar@gmail.com> | 2010-12-07 23:26:52 -0800 |
commit | 107f4e5aa5def40ad42db49c0f5b46a7d64700a0 (patch) | |
tree | aafbee377e918137faa3abbee1ebfa054057c2a5 |
Initial commit
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | emulator.h | 12 | ||||
-rw-r--r-- | evaluator.h | 12 | ||||
-rw-r--r-- | inst_loader.cpp | 9 | ||||
-rw-r--r-- | inst_loader.h | 12 | ||||
-rw-r--r-- | instruction.cpp | 22 | ||||
-rw-r--r-- | instruction.h | 38 | ||||
-rw-r--r-- | reg.cpp | 14 | ||||
-rw-r--r-- | reg.h | 46 | ||||
-rw-r--r-- | test_loader.cpp | 54 | ||||
-rw-r--r-- | test_loader.h | 20 | ||||
-rw-r--r-- | value.h | 21 |
13 files changed, 273 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d81386e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.d +*.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4c65015 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +DEPS := $(OBJS:.o=.d) + +-include $(DEPS) + +debugger: instruction.o reg.o test_loader.o + g++ -o $@ $^ + +%.o: %.cpp + $(CXX) -MM -MF $(patsubst %.o,%.d,$@) $< + $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/emulator.h b/emulator.h new file mode 100644 index 0000000..c47d4f5 --- /dev/null +++ b/emulator.h @@ -0,0 +1,12 @@ + +#ifndef EMULATOR_H_ +#define EMULATOR_H_ + +class emulator { +private: + inst_loader loader; + vector<reg> temp_regs; + vector<reg> out_regs; +}; + +#endif //EMULATOR_H_ diff --git a/evaluator.h b/evaluator.h new file mode 100644 index 0000000..f3bbe41 --- /dev/null +++ b/evaluator.h @@ -0,0 +1,12 @@ + +#ifndef EVALUATOR_H_ +#define EVALUATOR_H_ + +class value; + +class evaluator { +public: + virtual void evaluate(value l, value r); +}; + +#endif //EVALUATOR_H_ diff --git a/inst_loader.cpp b/inst_loader.cpp new file mode 100644 index 0000000..928d3f3 --- /dev/null +++ b/inst_loader.cpp @@ -0,0 +1,9 @@ + + +#include "inst_loader.h" + +vector<instruction> inst_loader::load() +{ + vector<instruction> * instructions = new vector<instruction>(); + instructions->push_back( +} diff --git a/inst_loader.h b/inst_loader.h new file mode 100644 index 0000000..67976f5 --- /dev/null +++ b/inst_loader.h @@ -0,0 +1,12 @@ + +#ifndef INST_LOADER_H_ +#define INST_LOADER_H_ + +#include "instruction.h" + +class inst_loader { +public: + virtual std::vector<instruction> * load() = 0; +}; + +#endif //INST_LOADER_H_ diff --git a/instruction.cpp b/instruction.cpp new file mode 100644 index 0000000..bd754d7 --- /dev/null +++ b/instruction.cpp @@ -0,0 +1,22 @@ + +#include "instruction.h" + +instruction::instruction( + const char * name, + evaluator * evaluator, + std::vector<reg::address> dst) : + m_name(name), + m_evaluator(evaluator), + m_dst(dst) + { } + + +add_instruction::add_instruction( + std::vector<reg::address> dst, + std::vector<reg::address> src0, + std::vector<reg::address> src1) + : + instruction("ADD", new evaluator(), dst), + m_src0(src0), + m_src1(src1) + { } diff --git a/instruction.h b/instruction.h new file mode 100644 index 0000000..09d6594 --- /dev/null +++ b/instruction.h @@ -0,0 +1,38 @@ + +#ifndef INSTRUCTION_H_ +#define INSTRUCTION_H_ + +#include <vector> + +#include "evaluator.h" +#include "reg.h" + +class instruction { + +public: + instruction(const char * name, evaluator * evaluator, std::vector<reg::address> dst); + +protected: + const char * m_name; + evaluator * m_evaluator; + std::vector<reg::address> m_dst; +}; + +class add_instruction : public instruction{ +public: + add_instruction(std::vector<reg::address> dst, std::vector<reg::address>, + std::vector<reg::address> src1); + +private: + std::vector<reg::address> m_src0; + std::vector<reg::address> m_src1; +}; + +class mov_instruction { +public: + mov_instruction(reg dst[4], reg src0[4]); +private: + reg src0[4]; +}; + +#endif //INSTRUCTION_H_ @@ -0,0 +1,14 @@ + +#include "reg.h" + +reg::address::address( + reg_type type, + unsigned int index, + enum swizzle swizzle) + : + m_type(type), + m_index(index), + m_swizzle(swizzle) + { } + +reg::~reg() { } @@ -0,0 +1,46 @@ + +#ifndef REG_H_ +#define REG_H_ + +#include "value.h" + +enum reg_type { + REG_TYPE_TEMP, + REG_TYPE_CONST, + REG_TYPE_IN, + REG_TYPE_OUT +}; + +enum swizzle { + SWIZZLE_EMPTY, + SWIZZLE_X, + SWIZZLE_Y, + SWIZZLE_Z, + SWIZZLE,W +}; + +class reg { +public: + + class address { + public : + address( + reg_type type, + unsigned int index, + enum swizzle swizzle); + + reg_type m_type; + unsigned int m_index; + enum swizzle m_swizzle; + }; + +public: + reg(reg_type type, unsigned int index, enum swizzle swizzle); + ~reg(); + +private: + address m_address; + value m_value; +}; + +#endif //REG_H_ diff --git a/test_loader.cpp b/test_loader.cpp new file mode 100644 index 0000000..abdc2b6 --- /dev/null +++ b/test_loader.cpp @@ -0,0 +1,54 @@ + +#include <vector> + +#include "test_loader.h" + +std::vector<enum swizzle> +test_loader::XYZ() +{ + std::vector<enum swizzle> XYZ; + XYZ.push_back(SWIZZLE_X); + XYZ.push_back(SWIZZLE_Y); + XYZ.push_back(SWIZZLE_Z); + return XYZ; +} + +std::vector<reg::address> +test_loader::make_register( + reg_type type, + unsigned int index, + std::vector<enum swizzle> swizzles) +{ + std::vector<reg::address> new_register; + std::vector<enum swizzle>::iterator it; + for(it = swizzles.begin(); it < swizzles.end(); ++it) { + new_register.push_back(reg::address(type, index, *it)); + } +} + +std::vector<instruction> * +test_loader::load() +{ + reg_type type_scr0; + unsigned int index_src0; + std::vector<instruction> * instructions = new std::vector<instruction>(); + + instructions->push_back(add_instruction( + make_register(REG_TYPE_TEMP, 0, XYZ()), + make_register(REG_TYPE_CONST, 0, XYZ()), + make_register(REG_TYPE_CONST, 0, XYZ()))); + + instructions->push_back(add_instruction( + make_register(REG_TYPE_TEMP, 0, XYZ()), + make_register(REG_TYPE_TEMP, 0, XYZ()), + make_register(REG_TYPE_CONST, 0, XYZ()))); + + instructions->push_back(add_instruction( + make_register(REG_TYPE_OUT, 0, XYZ()), + make_register(REG_TYPE_TEMP, 0, XYZ()), + make_register(REG_TYPE_TEMP, 0, XYZ()))); + + return instructions; +} + + diff --git a/test_loader.h b/test_loader.h new file mode 100644 index 0000000..930e091 --- /dev/null +++ b/test_loader.h @@ -0,0 +1,20 @@ + +#ifndef TEST_LOADER_H_ +#define TEST_LOADER_H_ + +#include <vector> + +#include "inst_loader.h" + +class test_loader : public inst_loader { +public: + std::vector<instruction> * load(); +private: + std::vector<enum swizzle> XYZ(); + std::vector<reg::address> make_register( + reg_type type, + unsigned int index, + std::vector<enum swizzle> swizzles); +}; + +#endif //TEST_LOADER_H_ @@ -0,0 +1,21 @@ + +#ifndef VALUE_H_ +#define VALUE_H_ + +class evaluator; +class reg; + +class value { + +protected: + evaluator * m_evaluator; + value & m_lchild; + value & m_rchild; +}; + +class const_value : public value { +private: + reg * const_reg; +}; + +#endif //VALUE_H_ |