/* * Processor.h * */ #ifndef GC_PROCESSOR_H_ #define GC_PROCESSOR_H_ #include using namespace std; #include "GC/Clear.h" #include "GC/Machine.h" #include "Math/Integer.h" #include "Processor/ProcessorBase.h" namespace GC { template class Program; class ExecutionStats : public map { public: ExecutionStats& operator+=(const ExecutionStats& other) { for (auto it : other) (*this)[it.first] += it.second; return *this; } }; template class Processor : public ::ProcessorBase { public: static int check_args(const vector& args, int n); static void check_input(long long in, int n_bits); Machine& machine; unsigned int PC; unsigned int time; // rough measure for the memory usage size_t complexity; Memory S; Memory C; Memory I; ExecutionStats stats; Processor(Machine& machine); ~Processor(); void reset(const Program& program, int arg); void reset(const Program& program); long long get_input(int n_bits, bool interactive = false); void bitcoms(T& x, const vector& regs) { x.bitcom(S, regs); } void bitdecs(const vector& regs, const T& x) { x.bitdec(S, regs); } void bitdecc(const vector& regs, const Clear& x); void bitdecint(const vector& regs, const Integer& x); void random_bit(T &x) { x.random_bit(); } void load_dynamic_direct(const vector& args); void store_dynamic_direct(const vector& args); void load_dynamic_indirect(const vector& args); void store_dynamic_indirect(const vector& args); void store_clear_in_dynamic(const vector& args); void xors(const vector& args); void and_(const vector& args, bool repeat); void andrs(const vector& args) { and_(args, true); } void ands(const vector& args) { and_(args, false); } void input(const vector& args); void print_reg(int reg, int n); void print_reg_plain(Clear& value); void print_reg_signed(unsigned n_bits, Clear& value); void print_chr(int n); void print_str(int n); void print_float(const vector& args); }; template inline int GC::Processor::check_args(const vector& args, int n) { if (args.size() % n != 0) throw runtime_error("invalid number of arguments"); int total = 0; for (size_t i = 0; i < args.size(); i += n) { total += args[i]; } return total; } } /* namespace GC */ #endif /* GC_PROCESSOR_H_ */