Beispiel #1
0
void string_constantt::set_long(bool is_long)
{
  set(ID_long, is_long);
  type().subtype()=is_long?wchar_t_type():char_type();
}
Beispiel #2
0
bool c_preprocess_gcc_clang(
  const std::string &file,
  std::ostream &outstream,
  message_handlert &message_handler,
  configt::ansi_ct::preprocessort preprocessor)
{
  // check extension
  if(is_dot_i_file(file))
    return c_preprocess_none(file, outstream, message_handler);

  // preprocessing
  message_streamt message_stream(message_handler);

  std::string stderr_file=get_temporary_file("tmp.stderr", "");

  std::string command;
  
  if(preprocessor==configt::ansi_ct::PP_CLANG)
    command="clang";
  else
    command="gcc";
  
  command +=" -E -undef -D__CPROVER__";

  command+=" -D__null=0";
  command+=" -D__WORDSIZE="+i2string(config.ansi_c.pointer_width);
  
  command+=" -D__DBL_MIN_EXP__=\"(-1021)\"";
  command+=" -D__FLT_MIN__=1.17549435e-38F";
  command+=" -D__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD";
  command+=" -D__CHAR_BIT__=8";
  command+=" -D__DBL_DENORM_MIN__=4.9406564584124654e-324";
  command+=" -D__FLT_EVAL_METHOD__=0";
  command+=" -D__DBL_MIN_10_EXP__=\"(-307)\"";
  command+=" -D__FINITE_MATH_ONLY__=0";
  command+=" -D__DEC64_MAX_EXP__=384";
  command+=" -D__SHRT_MAX__=32767";
  command+=" -D__LDBL_MAX__=1.18973149535723176502e+4932L";
  command+=" -D__DEC32_EPSILON__=1E-6DF";
  command+=" -D__SCHAR_MAX__=127";
  command+=" -D__USER_LABEL_PREFIX__=_";
  command+=" -D__DEC64_MIN_EXP__=\"(-383)\"";
  command+=" -D__DBL_DIG__=15";
  command+=" -D__FLT_EPSILON__=1.19209290e-7F";
  command+=" -D__LDBL_MIN__=3.36210314311209350626e-4932L";
  command+=" -D__DEC32_MAX__=9.999999E96DF";
  command+=" -D__DECIMAL_DIG__=21";
  command+=" -D__LDBL_HAS_QUIET_NAN__=1";
  command+=" -D__DYNAMIC__=1";
  command+=" -D__GNUC__=4";
  command+=" -D__FLT_HAS_DENORM__=1";
  command+=" -D__DBL_MAX__=1.7976931348623157e+308";
  command+=" -D__DBL_HAS_INFINITY__=1";
  command+=" -D__DEC32_MIN_EXP__=\"(-95)\"";
  command+=" -D__LDBL_HAS_DENORM__=1";
  command+=" -D__DEC32_MIN__=1E-95DF";
  command+=" -D__DBL_MAX_EXP__=1024";
  command+=" -D__DEC128_EPSILON__=1E-33DL";
  command+=" -D__SSE2_MATH__=1";
  command+=" -D__GXX_ABI_VERSION=1002";
  command+=" -D__FLT_MIN_EXP__=\"(-125)\"";
  command+=" -D__DBL_MIN__=2.2250738585072014e-308";
  command+=" -D__DBL_HAS_QUIET_NAN__=1";
  command+=" -D__DEC128_MIN__=1E-6143DL";
  command+=" -D__REGISTER_PREFIX__=";
  command+=" -D__DBL_HAS_DENORM__=1";
  command+=" -D__DEC_EVAL_METHOD__=2";
  command+=" -D__DEC128_MAX__=9.999999999999999999999999999999999E6144DL";
  command+=" -D__FLT_MANT_DIG__=24";
  command+=" -D__DEC64_EPSILON__=1E-15DD";
  command+=" -D__DEC128_MIN_EXP__=\"(-6143)\"";
  command+=" -D__DEC32_SUBNORMAL_MIN__=0.000001E-95DF";
  command+=" -D__FLT_RADIX__=2";
  command+=" -D__LDBL_EPSILON__=1.08420217248550443401e-19L";
  command+=" -D__k8=1";
  command+=" -D__LDBL_DIG__=18";
  command+=" -D__FLT_HAS_QUIET_NAN__=1";
  command+=" -D__FLT_MAX_10_EXP__=38";
  command+=" -D__FLT_HAS_INFINITY__=1";
  command+=" -D__DEC64_MAX__=9.999999999999999E384DD";
  command+=" -D__DEC64_MANT_DIG__=16";
  command+=" -D__DEC32_MAX_EXP__=96";
  command+=" -D__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL";
  command+=" -D__LDBL_MANT_DIG__=64";
  command+=" -D__CONSTANT_CFSTRINGS__=1";
  command+=" -D__DEC32_MANT_DIG__=7";
  command+=" -D__k8__=1";
  command+=" -D__pic__=2";
  command+=" -D__FLT_DIG__=6";
  command+=" -D__FLT_MAX_EXP__=128";
  //command+=" -D__BLOCKS__=1";
  command+=" -D__DBL_MANT_DIG__=53";
  command+=" -D__DEC64_MIN__=1E-383DD";
  command+=" -D__LDBL_MIN_EXP__=\"(-16381)\"";
  command+=" -D__LDBL_MAX_EXP__=16384";
  command+=" -D__LDBL_MAX_10_EXP__=4932";
  command+=" -D__DBL_EPSILON__=2.2204460492503131e-16";
  command+=" -D__GNUC_PATCHLEVEL__=1";
  command+=" -D__LDBL_HAS_INFINITY__=1";
  command+=" -D__INTMAX_MAX__=9223372036854775807L";
  command+=" -D__FLT_DENORM_MIN__=1.40129846e-45F";
  command+=" -D__PIC__=2";
  command+=" -D__FLT_MAX__=3.40282347e+38F";
  command+=" -D__FLT_MIN_10_EXP__=\"(-37)\"";
  command+=" -D__DEC128_MAX_EXP__=6144";
  command+=" -D__GNUC_MINOR__=2";
  command+=" -D__DBL_MAX_10_EXP__=308";
  command+=" -D__LDBL_DENORM_MIN__=3.64519953188247460253e-4951L";
  command+=" -D__DEC128_MANT_DIG__=34";
  command+=" -D__LDBL_MIN_10_EXP__=\"(-4931)\"";

  if(config.ansi_c.int_width==16)
    command+=GCC_DEFINES_16;
  else if(config.ansi_c.int_width==32)
  {
    if(config.ansi_c.pointer_width==64)
    {
      if(config.ansi_c.long_int_width==32)
        command+=GCC_DEFINES_LLP64; // Windows, for instance
      else
        command+=GCC_DEFINES_LP64;
    }
    else
      command+=GCC_DEFINES_32;
  }
  
  // The width of wchar_t depends on the OS!
  {
    command+=" -D__WCHAR_MAX__="+type_max(wchar_t_type());

    std::string sig=config.ansi_c.wchar_t_is_unsigned?"unsigned":"signed";
    
    if(config.ansi_c.wchar_t_width==config.ansi_c.short_int_width)
      command+=" -D__WCHAR_TYPE__=\""+sig+" short int\"";
    else if(config.ansi_c.wchar_t_width==config.ansi_c.int_width)
      command+=" -D__WCHAR_TYPE__=\""+sig+" int\"";
    else if(config.ansi_c.wchar_t_width==config.ansi_c.long_int_width)
      command+=" -D__WCHAR_TYPE__=\""+sig+" long int\"";
    else
      assert(false);
  }

  if(config.ansi_c.char_is_unsigned)
    command+=" -D __CHAR_UNSIGNED__"; // gcc

  switch(config.ansi_c.os)
  {
  case configt::ansi_ct::OS_LINUX:
    command+=" -Dlinux -D__linux -D__linux__ -D__gnu_linux__";
    command+=" -Dunix -D__unix -D__unix__";
    command+=" -D__USE_UNIX98";
    break;

  case configt::ansi_ct::OS_MACOS:
    command+=" -D__APPLE__ -D__MACH__";
    // needs to be __APPLE_CPP__ for C++
    command+=" -D__APPLE_CC__";
    break;

  case configt::ansi_ct::OS_WIN:
    command+=" -D _WIN32";

    if(config.ansi_c.mode!=configt::ansi_ct::MODE_VISUAL_STUDIO_C_CPP)
      command+=" -D _M_IX86=Blend";

    if(config.ansi_c.arch==configt::ansi_ct::ARCH_X86_64)
      command+=" -D _WIN64"; // yes, both _WIN32 and _WIN64 get defined

    if(config.ansi_c.char_is_unsigned)
      command+=" -D _CHAR_UNSIGNED"; // This is Visual Studio
    break;

  case configt::ansi_ct::NO_OS:
    command+=" -nostdinc"; // make sure we don't mess with the system library
    break;
    
  default:
    assert(false);
  }
  
  // Standard Defines, ANSI9899 6.10.8
  command += " -D __STDC_VERSION__=199901L";
  command += " -D __STDC_IEC_559__=1";
  command += " -D __STDC_IEC_559_COMPLEX__=1";
  command += " -D __STDC_ISO_10646__=1";
  
  for(std::list<std::string>::const_iterator
      it=config.ansi_c.defines.begin();
      it!=config.ansi_c.defines.end();
      it++)
    command+=" -D"+shell_quote(*it);

  for(std::list<std::string>::const_iterator
      it=config.ansi_c.include_paths.begin();
      it!=config.ansi_c.include_paths.end();
      it++)
    command+=" -I"+shell_quote(*it);

  for(std::list<std::string>::const_iterator
      it=config.ansi_c.include_files.begin();
      it!=config.ansi_c.include_files.end();
      it++)
    command+=" -include "+shell_quote(*it);

  for(std::list<std::string>::const_iterator
      it=config.ansi_c.preprocessor_options.begin();
      it!=config.ansi_c.preprocessor_options.end();
      it++)
    command+=" "+*it;
    
  int result;
  
  // the following forces the mode
  switch(config.ansi_c.mode)
  {
  case configt::ansi_ct::MODE_GCC_C: command+=" -x c"; break;
  case configt::ansi_ct::MODE_GCC_CPP: command+=" -x c++"; break;
  default:;
  }

  #ifdef _WIN32
  std::string tmpi=get_temporary_file("tmp.gcc", "");
  command+=" \""+file+"\"";
  command+=" -o \""+tmpi+"\"";
  command+=" 2> \""+stderr_file+"\"";

  // _popen isn't very reliable on WIN32
  // that's why we use system() and a temporary file
  result=system(command.c_str());

  FILE *stream=fopen(tmpi.c_str(), "r");

  // errors/warnings
  {
    std::ifstream stderr_stream(stderr_file.c_str());
    char ch;
    while(stderr_stream.read(&ch, 1))
      message_stream.str << ch;
  }

  unlink(stderr_file.c_str());

  if(stream!=NULL)
  {
    int ch;
    while((ch=fgetc(stream))!=EOF)
      outstream << (unsigned char)ch;

    fclose(stream);
    unlink(tmpi.c_str());
  }
  else
  {
    unlink(tmpi.c_str());
    message_stream.str << "GCC preprocessing failed (fopen failed)" << std::endl;
    result=1;
  }
  #else
  command+=" \""+file+"\"";
  command+=" 2> \""+stderr_file+"\"";

  FILE *stream=popen(command.c_str(), "r");

  if(stream!=NULL)
  {
    int ch;
    while((ch=fgetc(stream))!=EOF)
      outstream << (unsigned char)ch;

    result=pclose(stream);
  }
  else
  {
    message_stream.str << "GCC preprocessing failed (popen failed)" << std::endl;
    result=1;
  }

  // errors/warnings
  {
    std::ifstream stderr_stream(stderr_file.c_str());
    if(stderr_stream)
      message_stream.str << stderr_stream.rdbuf();
  }

  unlink(stderr_file.c_str());

  #endif

  if(result!=0)
  {
    message_stream.error_parse(1);
    message_stream.error("GCC preprocessing failed");
    return true;
  }
  else
    message_stream.error_parse(2);

  return false;
}
Beispiel #3
0
typet get_type(const format_tokent &token)
{
  switch(token.type)
  {
  case format_tokent::INT:
    switch(token.length_modifier)
    {
    case format_tokent::LEN_h:
      if(token.representation==format_tokent::SIGNED_DEC)
        return signed_char_type();
      else
        return unsigned_char_type();

    case format_tokent::LEN_hh:
      if(token.representation==format_tokent::SIGNED_DEC)
        return signed_short_int_type();
      else
        return unsigned_short_int_type();

    case format_tokent::LEN_l:
      if(token.representation==format_tokent::SIGNED_DEC)
        return signed_long_int_type();
      else
        return unsigned_long_int_type();

    case format_tokent::LEN_ll:
      if(token.representation==format_tokent::SIGNED_DEC)
        return signed_long_long_int_type();
      else
        return unsigned_long_long_int_type();

    default:
      if(token.representation==format_tokent::SIGNED_DEC)
        return signed_int_type();
      else
        return unsigned_int_type();
    }

  case format_tokent::FLOAT:
    switch(token.length_modifier)
    {
    case format_tokent::LEN_l: return double_type();
    case format_tokent::LEN_L: return long_double_type();
    default: return float_type();
    }

  case format_tokent::CHAR:
    switch(token.length_modifier)
    {
    case format_tokent::LEN_l: return wchar_t_type();
    default: return char_type();
    }

  case format_tokent::POINTER:
    return pointer_type(void_type());

  case format_tokent::STRING:
    switch(token.length_modifier)
    {
    case format_tokent::LEN_l: return array_typet(wchar_t_type(), nil_exprt());
    default: return array_typet(char_type(), nil_exprt());
    }

  default:
    return nil_typet();
  }
}