mapConformance.hpp

Go to the documentation of this file.
00001 /* Copyright 1996 LongView Technologies L.L.C. $Revision: 1.1 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 // Compiler/New Backend/Value Conformance
00025 //
00026 // Used by the new backed to make mappings conform before merging code pieces. 
00027 //
00028 // Usage:
00029 //   MapConformance mp(1);
00030 //   mp.append_mapping(...);
00031 //   mp.generate();
00032 //
00033 
00034 // Variable is an abstraction describing a register or stack location
00035 // Format as requested by Robert 9/6/96
00036 // 30 bits signed offset
00037 // 2  bits describes type
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   // Generators
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   // Testing
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   // Accessors
00078   int register_number() const { return offset(); }
00079   int stack_offset()    const { return offset(); }
00080    
00081   void set_unused() { _value = 0; }
00082 
00083   // Prints the variable.
00084   void print();
00085 
00086   // Comparison
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   // Constructor
00113   MapConformance();
00114 
00115   // Appends mapping
00116   void append_mapping(Variable src_register, Variable src_stack, Variable dst_register, Variable dst_stack);
00117 
00118   // Generates the move operations. free_register is a register that can be used during code generation.
00119   void generate(Variable free_register1, Variable free_register2);
00120 
00121   // Callback for the generated move operations. Default behavior will print a line per move.
00122   virtual void move(Variable src, Variable dst);
00123   virtual void push(Variable src);
00124   virtual void pop(Variable dst);
00125 
00126   // Print the status of the conformance
00127   void print();
00128 };
00129 
00130 #endif

Generated on Mon Oct 9 13:37:14 2006 for Strongtalk VM by  doxygen 1.4.7