示例#1
0
bool SuifValidater::is_valid_SymbolTable(SymbolTable* symtab)
{
  if (symtab == NULL)
    SUIF_THROW(SuifException(String("Cannot validate a NULL SymbolTable.")));
  bool ok_stat = true;
  {for (Iter<SymbolTable::lookup_table_pair> it =
	 symtab->get_lookup_table_iterator();
       it.is_valid();
       it.next()) {
    if (!symtab->has_symbol_table_object_member(it.current().second)) {
      ok_stat = false;
      add_error(to_id_string(symtab) + " has a lookup pair <" +
		it.current().first + ", " + to_id_string(it.current().second) +
		"> with dangling object.");
    }
  }}

  {for (Iter<SymbolTableObject*> it =
	 symtab->get_symbol_table_object_iterator();
       it.is_valid();
       it.next()) {
    SymbolTableObject *sobj = it.current();
    if ((sobj->get_name().length() > 0) &&
	!is_in_lookup_list(it.current(), symtab)) {
      ok_stat = false;
      add_error(to_id_string(symtab) + " has " +
		to_id_string(it.current()) + " not in lookup list.");
    }
  }}
  return ok_stat;
}
示例#2
0
void SuifValidater::validate( SuifObject* obj)
{
  SuifValidater val;
  if (!val.is_valid(obj)) {
    SUIF_THROW(SuifException(String("Validation of ") + to_id_string(obj) + 
			     " failed because\n" + val.get_error()));
  }
}
示例#3
0
void SimpleModule::check_arg_count(suif_vector<LString>* args,
				   unsigned cnt)
{
  if (args->size() != cnt) {
    SUIF_THROW(SuifException(get_module_name() + " expects exactly " +
			     String((long)cnt) + " arguments"));
  }
}
示例#4
0
LoadVariableExpression* NodeBuilder::load_var(VariableSymbol* var)
{
  Type* rtype = get_unqualified_type(var->get_type());
  if (!is_kind_of<DataType>(rtype)) {
    trash(var);
    SUIF_THROW(SuifException(String("Cannot make a LoadVariableExpression out of ") +
			     to_id_string(var) + " whose type " +
			     to_id_string(rtype) + " is not a data type."));
  }
  return create_load_variable_expression(_suif_env, to<DataType>(rtype), var);
}
示例#5
0
LoadExpression* NodeBuilder::load(Expression* addr)
{
  Type* ptype = get_unqualified_type(addr->get_result_type());
  if (!is_kind_of<PointerType>(ptype)) {
    trash(addr);
    SUIF_THROW(SuifException(String("Cannot make a LoadExpression out of ") +
			     to_id_string(addr) + " whose type " +
			     to_id_string(ptype) + " is not a pointer type."));
  }
  Type* btype =
    get_unqualified_type(to<PointerType>(ptype)->get_reference_type());
  if (!is_kind_of<DataType>(btype)) {
    trash(addr);
    SUIF_THROW(SuifException(String("Cannot make a LoadExpression out of ") +
			     to_id_string(addr) + " whose type " +
			     to_id_string(ptype) + " is not a pointer to a DataType."));
  }
  DataType *dtype = to<DataType>(btype);
  return create_load_expression(_suif_env, dtype, addr);
}
示例#6
0
/** Create an expression for byte offset of a group field.
  *
  */
Expression* NodeBuilder::get_field_offset_exp(FieldSymbol* fsym)
{
  Expression *boffset = fsym->get_bit_offset();
  if (!is_kind_of<IntConstant>(boffset)) {
    trash(fsym);
    SUIF_THROW(SuifException(String("Field offset not in IntConstant ") +
			     to_id_string(fsym)));
  }
  IInteger v = to<IntConstant>(boffset)->get_value();
  return int_const(v.div(IInteger(BITSPERBYTE)));
}
示例#7
0
StoreStatement* NodeBuilder::store(Expression* dst_addr, Expression* src_addr)
{
  if (!is_same_type(get_pointed_to_type(dst_addr->get_result_type()),
		    src_addr->get_result_type())) {
    trash(dst_addr);
    trash(src_addr);
    SUIF_THROW(SuifException(String("Type error in StoreStatement from ") +
			     to_id_string(src_addr) + " to " +
			     to_id_string(dst_addr)));
  }
  return create_store_statement(_suif_env, src_addr, dst_addr);
}
示例#8
0
StoreVariableStatement* NodeBuilder::store_var(VariableSymbol* dst,
					       Expression* src)
{
  if (!is_same_type(dst->get_type(), src->get_result_type())) {
    trash(dst);
    trash(src);
    SUIF_THROW(SuifException(String("Type mismatch in StoreVariableStatement for ")
			     + to_id_string(dst) + " from expression " +
			     to_id_string(src)));
  }
  return create_store_variable_statement(_suif_env, dst, src);
}
示例#9
0
IfStatement* NodeBuilder::new_if(Expression* pred,
				 Statement* then_part,
				 Statement* else_part)
{
  if (!(is_kind_of<IntegerType>(pred->get_result_type()) ||
	is_kind_of<BooleanType>(pred->get_result_type()))) {
    trash(then_part);
    trash(else_part);
    SUIF_THROW(SuifException(String("Expection a boolean or integer expression ")
			     + to_id_string(pred)));
  }
  return create_if_statement(_suif_env, pred, then_part, else_part);
}
示例#10
0
FieldAccessExpression* NodeBuilder::field_addr(Expression* grp_addr,
					       LString field_name)
{
  GroupType* gtype = to_ref_type<GroupType>(this, grp_addr->get_result_type());
  if (gtype == 0) {
    trash(grp_addr);
    SUIF_THROW(SuifException(String("Type error: expecting an addr to a group ")
				    + to_id_string(grp_addr)));
  }
  FieldSymbol *f = find_field(to<GroupType>(gtype), field_name);
  if (f == 0) {
    trash(grp_addr);
    SUIF_THROW(SuifException(String("Cannot find field <") + field_name +
				    "> in group type " +
				    to_id_string(gtype)));
  }
  FieldAccessExpression *res =
    create_field_access_expression(_suif_env,
				   // to<DataType>(fieldtype),
				   get_pointer_type(f->get_type()),
				   grp_addr,
				   f);
  return res;
}
示例#11
0
bool SuifValidater::is_valid( SuifObject* root)
{
  if (root == NULL)
    SUIF_THROW(SuifException("Cannot validate NULL."));
  bool ok_stat = is_valid_ownership(root);
  RefChecker rcheck(root->get_suif_env(), this);
  root->walk(rcheck);
  ok_stat &= rcheck.is_ok();

  for (Iter<SymbolTable> it = object_iterator<SymbolTable>(root);
       it.is_valid();
       it.next()) {
    ok_stat &= is_valid_SymbolTable(&(it.current()));
  }
  return ok_stat;
}
示例#12
0
CallExpression* CfeNodeBuilder::call(Expression* callee_addr,
				  suif_vector<Expression*>* args)
{
  CProcedureType* ctype =
    to_ref_type<CProcedureType>(this, callee_addr->get_result_type());
  if (ctype == 0) {
    trash(callee_addr);
    for (unsigned i = 0; i<args->length(); i++) {
      trash(args->at(i));
    }
    SUIF_THROW(SuifException(String("Type error in CallExpression ") + 
			     to_id_string(callee_addr)));
  }
  DataType* rtype = to<CProcedureType>(ctype)->get_result_type();
  CallExpression* exp = create_call_expression(get_suif_env(), rtype, callee_addr);
  for (unsigned i = 0; i<args->length(); i++) {
    exp->append_argument(args->at(i));
  }
  return exp;
}
示例#13
0
void DLLSubSystem::load_and_initialize_DLL( const LString& libraryName ) {
  String fileName;
  String initName;

  if (!is_DLL_loaded(libraryName))
    _loaded->push_back(libraryName);

  void (*initFunction)( SuifEnv* );

#ifdef UNIX_DLL_INTERFACE
  // code partially copied from dynasty.cc (Chris Wilson)
    /*
     *  In this case we assume that there is a <dlfcn.h> header file
     *  and that #include'ing <stdio.h> and <dlfcn.h> gives us the
     *  following two functions:
     *
     *      void *dlopen(char *filename, int mode);
     *      void *dlsym(void *handle, char *name);
     *
     *  and the RTLD_LAZY macro.  Acording to man pages on relatively
     *  current versions of Linux, Digital Unix 4.3, Solaris 2.5, and
     *  Irix 5.3 (all the UNIX systems I have available to me right
     *  now that support dynamic linking at all) at the time of this
     *  writing (January 1998), exactly this interface is provided on
     *  these four systems.  So it seems to be at least a de facto
     *  standard interface to program-controlled dynamic linking on
     *  UNIX systems.
     */

    fileName = String("lib") + libraryName + ".so";
    void* dlhandle = dlopen(fileName.c_str(), RTLD_LAZY);
    if (!dlhandle) {
      char *msg = dlerror();
      String erm;
      if (msg) {
	erm = msg;
      } else {
	erm = String("dlopen: ") + fileName + ": Could not open DLL";
      }
      SUIF_THROW(SuifException(erm));
    }
    initName = String("init_") + libraryName;
    initFunction =
            (void (*)(SuifEnv*))(dlsym(dlhandle, initName.c_str() ));

    if (!initFunction) {
      SUIF_THROW(SuifException(String("dlopen: '") + fileName +
			       "': Could not find function: '" +
			       initName + "'\n"));
    }

#elif defined( WIN32_DLL_INTERFACE )

    /*
     *  I found this interface described in two different third-party
     *  books on MS Visual C++.  Presumably it would work with an
     *  Win32 API compiler.
     */
    fileName = libraryName + ".DLL";
    HINSTANCE dlhandle = ::LoadLibrary( fileName.c_str() );
#ifdef MSVC
    if(!dlhandle){
        LPVOID lpMsgBuf;
        int err_num = GetLastError();

        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_SYSTEM | 
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            err_num,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
            (LPTSTR) &lpMsgBuf,
            0,
            NULL 
        );
        fprintf(stderr, (LPCTSTR)lpMsgBuf);
        kernel_assert_message(dlhandle, ("Can't load library %s, %d", fileName.c_str(), err_num));
        
        LocalFree( lpMsgBuf );
   }
#else 
    assert(dlhandle);
#endif

    initName =
     String("init_") + libraryName;

    initFunction =
            (void (*)(SuifEnv*))(::GetProcAddress(dlhandle,initName.c_str()));


#else

#error "SET ONE OF THE FOLLOWING MACROS: UNIX_DLL_INTERACE or WIN32_DLL_INTERFACE"

#endif
    assert( initFunction );
    dll_init_hook(initName.c_str());
    (*initFunction)( _suif_env );

}
示例#14
0
void SimpleModule::check_file_set_block(void)
{
  if (get_file_set_block() == NULL) {
    SUIF_THROW(SuifException(get_module_name() + " expects a file set block."));
  }
}