00001 #ifndef ROSE_BINARY_CALLCONV_H
00002 #define ROSE_BINARY_CALLCONV_H
00003
00004 #include <cassert>
00005 #include <vector>
00006
00007 class BinaryCallingConvention {
00008
00009
00010
00011
00012
00013 public:
00014
00016 class Convention {
00017 public:
00020 Convention(size_t wordsize, const std::string &name)
00021 : wordsize(wordsize), name(name),
00022 param_order(ORDER_UNKNOWN), this_location(THIS_UNKNOWN), retval_location(RETVAL_UNKNOWN), stack_alignment(0) {
00023 assert(wordsize>0);
00024 assert(!name.empty());
00025 }
00026
00030 public:
00031 size_t get_wordsize() const { return wordsize; }
00032 void set_wordsize(size_t wordsize) { this->wordsize = wordsize; }
00034 private:
00035 size_t wordsize;
00036
00041 public:
00042 const std::string& get_name() const { return name; }
00043 void set_name(const std::string &name) { this->name = name; }
00045 private:
00046 std::string name;
00047
00051 public:
00052 const std::string &get_comment() const { return comment; }
00053 void set_comment(const std::string &comment) { this->comment = comment; }
00055 private:
00056 std::string comment;
00057
00064 public:
00065 const std::vector<const RegisterDescriptor*>& get_reg_params() const { return reg_params; }
00066 void add_reg_param(const RegisterDescriptor *reg);
00068 private:
00069 std::vector<const RegisterDescriptor*> reg_params;
00070
00075 public:
00076 enum ParameterOrder {
00077 ORDER_LTR,
00078 ORDER_RTL,
00079 ORDER_UNKNOWN,
00080 };
00081 ParameterOrder get_param_order() const { return param_order; }
00082 void set_param_order(ParameterOrder order) { param_order = order; }
00084 private:
00085 ParameterOrder param_order;
00086
00090 public:
00091 enum ThisPointerLocation {
00092 THIS_FIRST_PARAM,
00093 THIS_REGISTER,
00094 THIS_NOT_APPLICABLE,
00095 THIS_UNKNOWN,
00096 };
00097 ThisPointerLocation get_this_location() const { return this_location; }
00098 void set_this_location(ThisPointerLocation loc) { this_location = loc; }
00100 private:
00101 ThisPointerLocation this_location;
00102
00108 public:
00109 const RegisterDescriptor* get_this_register() const { return THIS_REGISTER==this_location ? this_reg : NULL; }
00110 void set_this_register(const RegisterDescriptor *reg) {
00111 this_location = THIS_REGISTER;
00112 this_reg = reg;
00113 }
00115 private:
00116 const RegisterDescriptor *this_reg;
00117
00120 public:
00121 enum ReturnValueLocation {
00122 RETVAL_STACK,
00123 RETVAL_REGISTER,
00124 RETVAL_NOT_APPLICABLE,
00125 RETVAL_UNKNOWN,
00126 };
00127 ReturnValueLocation get_retval_location() const { return retval_location; }
00128 void set_retval_location(ReturnValueLocation loc) { retval_location = loc; }
00130 private:
00131 ReturnValueLocation retval_location;
00132
00133
00139 public:
00140 const RegisterDescriptor* get_retval_register() const { return RETVAL_REGISTER==retval_location ? retval_reg : NULL; }
00141 void set_retval_register(const RegisterDescriptor *reg) {
00142 retval_location = RETVAL_REGISTER;
00143 retval_reg = reg;
00144 }
00146 private:
00147 const RegisterDescriptor *retval_reg;
00148
00151 public:
00152 enum StackCleanup {
00153 CLEANUP_CALLER,
00154 CLEANUP_CALLEE,
00155 CLEANUP_NOT_APPLICABLE,
00156 CLEANUP_UNKNOWN,
00157 };
00158 StackCleanup get_stack_cleanup() const { return stack_cleanup; }
00159 void set_stack_cleanup(StackCleanup cleanup) { stack_cleanup = cleanup; }
00161 private:
00162 StackCleanup stack_cleanup;
00163
00168 public:
00169 size_t get_stack_alignment() const { return stack_alignment; }
00170 void set_stack_alignment(size_t alignment) { stack_alignment = alignment; }
00172 private:
00173 size_t stack_alignment;
00174 };
00175
00176
00177
00178
00179 private:
00180 std::vector<const Convention*> cconvs;
00181
00182 public:
00185 void append(const Convention *cconv) { cconvs.push_back(cconv); }
00186
00192 const Convention *find(size_t wordsize, const std::string &name, size_t *start_at=NULL);
00193
00196 void erase(const Convention *conv);
00197 void erase(size_t index);
00201 void clear() { cconvs.clear(); }
00202
00205 size_t size() { return cconvs.size(); }
00206
00207
00208
00209
00210 public:
00211 BinaryCallingConvention::Convention *analyze_callee(SgAsmFunction*);
00212
00213 };
00214
00215
00216
00217 #endif
00218
00219
00220