00001 #ifndef _PGEN_NODE_BUILDER_H_ 00002 #define _PGEN_NODE_BUILDER_H_ 00014 #include "common/lstring.h" 00015 #include "basicnodes/basic.h" 00016 #include "suifnodes/suif.h" 00017 #include "cfenodes/cfe.h" 00018 00019 00020 00021 class NodeBuilder { 00022 private: 00023 SymbolTable* _symtab; 00024 SuifEnv* _suif_env; 00025 TypeBuilder* _type_builder; 00026 00027 protected: 00028 Expression* get_field_offset_exp(FieldSymbol* f); 00029 bool is_same_type(Type*, Type*); 00030 void trash(SuifObject* ); 00031 MultiValueBlock* new_cstr_value_block(String s); 00032 VariableDefinition* add_variable_definition(ProcedureDefinition* p, 00033 VariableSymbol* v, 00034 ValueBlock* b); 00035 00036 public: 00037 00038 NodeBuilder(SymbolTable*); 00039 NodeBuilder(ScopedObject*); 00040 00041 SuifEnv *get_suif_env() const; 00042 ParameterSymbol* new_param(LString name, QualifiedType* type); 00043 00044 VariableSymbol* new_int_var(LString name, bool addr_taken = false); 00045 VariableSymbol* new_var(LString name, DataType* type, 00046 bool addr_taken = false); 00047 VariableSymbol* new_var(LString name, QualifiedType* type, 00048 bool addr_taken = false); 00049 VariableSymbol* lookup_var(LString name, bool local_only = false); 00050 00051 Type* lookup_type(LString, bool local_only = false); 00052 StructType* new_struct_type(LString); 00053 void add_struct_field(StructType*, 00054 LString fname, 00055 QualifiedType* ftype); 00056 IntegerType* get_int_type(void); 00057 BooleanType* get_bool_type(void); 00058 FloatingPointType* get_float_type(void); 00059 IntegerType* get_char_type(void); 00060 VoidType* get_void_type(void); 00061 00062 QualifiedType* get_qualified_type(DataType*); 00063 00067 Type* get_unqualified_type(Type* t); 00068 00072 Type* get_pointed_to_type(Type* t); 00073 00074 PointerType* get_pointer_type(Type* t); 00075 00076 StoreVariableStatement* store_var(VariableSymbol*, Expression*); 00077 StoreStatement* store(Expression* target_addr, Expression*); 00078 StoreStatement* store_field(Expression* group_addr, 00079 LString field_name, 00080 Expression* value); 00081 EvalStatement* eval(Expression*); 00082 StatementList* new_statement_list(void); 00083 IfStatement* new_if(Expression*, Statement*, Statement*); 00084 00085 LoadExpression* load(Expression* addr); // LoadExpression 00086 LoadVariableExpression* load_var(VariableSymbol*); // LoadVarExpression 00087 LoadVariableExpression* load_var(LString); // LoadVarExpression 00088 00089 SymbolAddressExpression* sym_addr(Symbol*); // SymbolAddressExpression 00090 Expression* load_field(Expression* group_addr, 00091 LString field_name); 00092 00093 FieldAccessExpression* field_addr(Expression* grp_addr, 00094 LString field_name); 00095 00096 IntConstant* int_const(IInteger); 00097 IntConstant* int_const(int); 00098 IntConstant* bool_const(bool); 00099 FloatConstant* float_const(float); 00100 00103 Expression* cstr_const(const char*, ProcedureDefinition*); 00104 IntConstant* char_const(char); 00105 00106 BinaryExpression* binary_exp(LString op, DataType* result_type, 00107 Expression* arg1, Expression* arg2); 00108 BinaryExpression* and_exp(Expression*, Expression*); 00109 BinaryExpression* multiply_exp(Expression*, Expression*); 00110 BinaryExpression* add_exp(Expression*, Expression*); 00111 BinaryExpression* subtract_exp(Expression*, Expression*); 00112 BinaryExpression* is_less_than_or_equal_to_exp(Expression*, Expression*); 00113 BinaryExpression* divfloor_exp(Expression*, Expression*); 00114 BinaryExpression* max_exp(Expression*, Expression*); 00115 BinaryExpression* min_exp(Expression*, Expression*); 00116 00117 UnaryExpression* convert_exp(Expression*, DataType*); 00118 00119 ProcedureSymbol* lookup_proc(LString name, bool local_only = false); 00120 ProcedureDefinition* new_proc_defn1(LString name, 00121 DataType* return_type, 00122 ParameterSymbol* arg); 00123 00127 VariableSymbol* get_cstr_const_var(String s, ProcedureDefinition* p); 00128 00129 void replace(Statement* old_stmt, Statement* new_stmt); 00130 void replace(Expression* old_exp, Expression* new_exp); 00131 00132 00133 }; 00134 00135 00136 00137 00145 template<class T> T* to_ref_type(NodeBuilder* nb, Type* t) { 00146 Type* ut = nb->get_unqualified_type(t); 00147 if (!is_kind_of<PointerType>(ut)) return 0; 00148 Type* reftype = 00149 nb->get_unqualified_type(to<PointerType>(t)->get_reference_type()); 00150 if (!is_kind_of<T>(reftype)) return 0; 00151 return to<T>(reftype); 00152 }; 00153 00154 #endif // _PGEN_NODE_BUILDER_H_