27 if(src.find(
' ')==std::string::npos &&
28 src.find(
'"')==std::string::npos &&
29 src.find(
'&')==std::string::npos &&
30 src.find(
'|')==std::string::npos &&
31 src.find(
'(')==std::string::npos &&
32 src.find(
')')==std::string::npos &&
33 src.find(
'<')==std::string::npos &&
34 src.find(
'>')==std::string::npos &&
35 src.find(
'^')==std::string::npos)
45 for(
const char ch : src)
60 if(src.find(
' ')==std::string::npos &&
61 src.find(
'"')==std::string::npos &&
62 src.find(
'*')==std::string::npos &&
63 src.find(
'$')==std::string::npos &&
64 src.find(
'\\')==std::string::npos &&
65 src.find(
'?')==std::string::npos &&
66 src.find(
'&')==std::string::npos &&
67 src.find(
'|')==std::string::npos &&
68 src.find(
'>')==std::string::npos &&
69 src.find(
'<')==std::string::npos &&
70 src.find(
'^')==std::string::npos &&
71 src.find(
'\'')==std::string::npos)
82 for(
const char ch : src)
96 const std::string &line,
100 std::string error_msg=line;
105 const char *tptr=line.c_str();
107 std::string
file, line_no, column, _error_msg,
function;
121 else if(
has_prefix(tptr,
" column ") && state != 4)
127 else if(
has_prefix(tptr,
" function ") && state != 4)
133 else if(*tptr==
':' && state!=4)
135 if(tptr[1]==
' ' && previous!=
':')
139 while(*tptr==
' ') tptr++;
164 saved_error_location.
set_line(line_no);
166 error_msg=_error_msg;
169 else if(
has_prefix(line,
"In file included from "))
174 const char *tptr=line.c_str();
176 std::string
file, line_no;
191 else if(isdigit(*tptr))
204 saved_error_location.
set_line(line_no);
216 std::istream &errors,
222 while(std::getline(errors, line))
228 std::istream &instream,
229 std::ostream &outstream,
234 std::ofstream tmp(tmp_file());
243 tmp << instream.rdbuf();
247 bool result=
c_preprocess(tmp_file(), outstream, message_handler);
274 const std::string &path,
275 std::ostream &outstream,
309 const std::string &
file,
310 std::ostream &outstream,
325 std::ofstream command_file(command_file_name());
329 command_file << char(0xef) << char(0xbb) << char(0xbf);
331 command_file <<
"/nologo" <<
'\n';
332 command_file <<
"/E" <<
'\n';
337 command_file <<
"/source-charset:utf-8" <<
'\n';
339 command_file <<
"/D__CPROVER__" <<
"\n";
344 command_file <<
"\"/D__PTRDIFF_TYPE__=long long int\"" <<
"\n";
346 command_file <<
"/D_WIN64" <<
"\n";
353 "Pointer difference expected to be long int typed");
354 command_file <<
"/D__PTRDIFF_TYPE__=long" <<
'\n';
360 "Pointer difference expected to be int typed");
361 command_file <<
"/D__PTRDIFF_TYPE__=int" <<
"\n";
365 command_file <<
"/J" <<
"\n";
368 command_file <<
"/D" <<
shell_quote(define) <<
"\n";
371 command_file <<
"/I" <<
shell_quote(include_path) <<
"\n";
374 command_file <<
"/FI" <<
shell_quote(include_file) <<
"\n";
383 std::string command =
"CL @\"" + command_file_name() +
"\"";
384 command +=
" 2> \"" + stderr_file() +
"\"";
389 run(
"cl", {
"cl",
"@" + command_file_name()},
"", outstream, stderr_file());
392 std::ifstream stderr_stream(stderr_file());
406 std::istream &instream,
407 std::ostream &outstream)
423 std::getline(instream, line);
426 line[0]==
'#' && (line[1]==
'#' || line[1]==
' ' || line[1]==
'\t'))
430 else if(line.size()>=3 &&
431 line[0]==
'/' && line[1]==
'*' && line[2]==
' ')
433 outstream << line.c_str()+3 <<
"\n";
436 outstream << line <<
"\n";
442 const std::string &
file,
443 std::ostream &outstream,
455 std::vector<std::string> command = {
456 "mwcceppc",
"-E",
"-P",
"-D__CPROVER__",
"-ppopt",
"line",
"-ppopt full"};
459 command.push_back(
" -D" + define);
462 command.push_back(
" -I" + include_path);
466 command.push_back(
" -include");
467 command.push_back(include_file);
471 command.push_back(opt);
474 command.push_back(
file);
475 command.push_back(
"-o");
476 command.push_back(tmpi());
478 int result =
run(command[0], command,
"",
"", stderr_file());
480 std::ifstream stream_i(tmpi());
490 message.error() <<
"Preprocessing failed (fopen failed)"
496 std::ifstream stderr_stream(stderr_file());
510 const std::string &
file,
511 std::ostream &outstream,
524 std::vector<std::string> argv;
527 argv.push_back(
"clang");
529 argv.push_back(
"gcc");
531 argv.push_back(
"-E");
532 argv.push_back(
"-D__CPROVER__");
538 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
539 argv.push_back(
"-m16");
541 argv.push_back(
"-mips16");
545 if(arch ==
"i386" || arch ==
"x86_64")
546 argv.push_back(
"-m32");
547 else if(arch ==
"x32")
548 argv.push_back(
"-mx32");
550 argv.push_back(
"-mabi=32");
551 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
552 argv.push_back(
"-m32");
553 else if(arch ==
"s390" || arch ==
"s390x")
554 argv.push_back(
"-m31");
555 else if(arch ==
"sparc" || arch ==
"sparc64")
556 argv.push_back(
"-m32");
560 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
561 argv.push_back(
"-m64");
563 argv.push_back(
"-mabi=64");
564 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
565 argv.push_back(
"-m64");
566 else if(arch ==
"s390" || arch ==
"s390x")
567 argv.push_back(
"-m64");
568 else if(arch ==
"sparc" || arch ==
"sparc64")
569 argv.push_back(
"-m64");
574 argv.push_back(
"-fshort-wchar");
577 argv.push_back(
"-funsigned-char");
580 argv.push_back(
"-nostdinc");
595 #if defined(__OpenBSD__)
597 argv.push_back(
"-std=c++98");
600 argv.push_back(
"-std=gnu++98");
604 #if defined(__OpenBSD__)
606 argv.push_back(
"-std=c++03");
609 argv.push_back(
"-std=gnu++03");
613 #if defined(__OpenBSD__)
615 argv.push_back(
"-std=c++11");
618 argv.push_back(
"-std=gnu++11");
622 #if defined(__OpenBSD__)
624 argv.push_back(
"-std=c++14");
627 argv.push_back(
"-std=gnu++14");
636 #if defined(__OpenBSD__)
638 argv.push_back(
"-std=c89");
641 argv.push_back(
"-std=gnu89");
645 #if defined(__OpenBSD__)
647 argv.push_back(
"-std=c99");
650 argv.push_back(
"-std=gnu99");
654 #if defined(__OpenBSD__)
656 argv.push_back(
"-std=c11");
659 argv.push_back(
"-std=gnu11");
665 argv.push_back(
"-D" + define);
668 argv.push_back(
"-I" + include_path);
672 argv.push_back(
"-include");
673 argv.push_back(include_file);
685 case configt::ansi_ct::flavourt::GCC_C: command+=
" -x c";
break;
686 case configt::ansi_ct::flavourt::GCC_CPP: command+=
" -x c++";
break;
694 argv.push_back(
file);
697 result =
run(argv[0], argv,
"", outstream, stderr_file());
700 std::ifstream stderr_stream(stderr_file());
714 const std::string &
file,
715 std::ostream &outstream,
727 std::vector<std::string> argv;
729 argv.push_back(
"armcc");
730 argv.push_back(
"-E");
731 argv.push_back(
"-D__CPROVER__");
734 argv.push_back(
"--bigend");
736 argv.push_back(
"--littleend");
739 argv.push_back(
"--unsigned_chars");
741 argv.push_back(
"--signed_chars");
747 argv.push_back(
"--c90");
752 argv.push_back(
"--c99");
757 argv.push_back(
"-D" + define);
760 argv.push_back(
"-I" + include_path);
763 argv.push_back(
file);
768 result =
run(argv[0], argv,
"", outstream, stderr_file());
771 std::ifstream stderr_stream(stderr_file());
785 const std::string &
file,
786 std::ostream &outstream,
792 std::ifstream infile(
file);
811 while(infile.read(&ch, 1))
820 "#include <stdlib.h>\n"
826 std::ostringstream out;