00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 #ifdef DELTA_COMPILER
00040 
00041 class Variable : ValueObj {
00042  private:
00043   int _value;
00044 
00045   enum {
00046    special_type = 0,
00047    reg_type     = 1,
00048    stack_type   = 2
00049   };
00050 
00051   int type()   const { return _value & 0x3; }
00052   int offset() const { return _value >> 2;  }
00053   int value()  const { return _value; }
00054 
00055   static Variable new_variable(int type, int offset) {
00056     Variable result;
00057     result._value = (offset << 2) | type;
00058     return result;
00059   }
00060 
00061  public:
00062   Variable() { _value = 0; }
00063 
00064   
00065   static Variable new_register(int offset) { return new_variable(reg_type,     offset); }
00066   static Variable new_stack(int offset)    { return new_variable(stack_type,   offset); }
00067   static Variable unused()                 { return new_variable(special_type, 0);      }
00068   static Variable top_of_stack()           { return new_variable(special_type, 1);      }
00069 
00070   
00071   bool in_register() const { return type() == reg_type;    }
00072   bool on_stack()    const { return type() == stack_type;  }
00073 
00074   bool is_unused()       const { return type() == special_type && offset() == 0; }
00075   bool is_top_of_stack() const { return type() == special_type && offset() == 1; }
00076 
00077   
00078   int register_number() const { return offset(); }
00079   int stack_offset()    const { return offset(); }
00080    
00081   void set_unused() { _value = 0; }
00082 
00083   
00084   void print();
00085 
00086   
00087   friend bool operator == (Variable x, Variable y) { return x.value() == y.value(); }
00088   friend bool operator != (Variable x, Variable y) { return x.value() != y.value(); }
00089 };
00090 
00091 
00092 class MappingTask;
00093 
00094 class MapConformance : public ResourceObj {
00095  private:
00096   Variable                     _free_register;
00097   GrowableArray<MappingTask*>* mappings;
00098   Variable*                    used_variables;
00099   int                          number_of_used_variables;
00100 
00101   bool reduce_noop_task(MappingTask* task);
00102   void simplify();
00103   void process_tasks();
00104 
00105   Variable pop_temporary();
00106   void push_temporary(Variable var);
00107 
00108   void push(Variable src, int n);
00109 
00110   friend class MappingTask;
00111  public:
00112   
00113   MapConformance();
00114 
00115   
00116   void append_mapping(Variable src_register, Variable src_stack, Variable dst_register, Variable dst_stack);
00117 
00118   
00119   void generate(Variable free_register1, Variable free_register2);
00120 
00121   
00122   virtual void move(Variable src, Variable dst);
00123   virtual void push(Variable src);
00124   virtual void pop(Variable dst);
00125 
00126   
00127   void print();
00128 };
00129 
00130 #endif