Changes in / [c2051e10:17bc05b]
- Files:
-
- 10 edited
-
Jenkinsfile (modified) (1 diff)
-
doc/bibliography/pl.bib (modified) (17 diffs)
-
driver/cc1.cc (modified) (16 diffs)
-
driver/cfa.cc (modified) (22 diffs)
-
src/ResolvExpr/Unify.cc (modified) (4 diffs)
-
src/SynTree/Expression.cc (modified) (2 diffs)
-
src/SynTree/Expression.h (modified) (2 diffs)
-
src/SynTree/Type.h (modified) (2 diffs)
-
src/main.cc (modified) (11 diffs)
-
tests/pybin/tools.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
Jenkinsfile
rc2051e10 r17bc05b 155 155 156 156 def test() { 157 try { 158 build_stage('Test: short', !Settings.RunAllTests) { 159 dir (BuildDir) { 160 //Run the tests from the tests directory 161 sh "make --no-print-directory -C tests archiveerrors=${BuildDir}/tests/crashes/short" 162 } 163 } 164 165 build_stage('Test: full', Settings.RunAllTests) { 166 dir (BuildDir) { 167 //Run the tests from the tests directory 168 sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=yes archiveerrors=${BuildDir}/tests/crashes/full-debug""" 169 sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=no archiveerrors=${BuildDir}/tests/crashes/full-nodebug""" 170 } 171 } 172 } 173 catch (Exception err) { 174 echo "Archiving core dumps" 175 dir (BuildDir) { 176 archiveArtifacts artifacts: "tests/crashes/**/*", fingerprint: true 177 } 178 throw err 157 build_stage('Test: short', !Settings.RunAllTests) { 158 dir (BuildDir) { 159 //Run the tests from the tests directory 160 sh 'make --no-print-directory -C tests' 161 } 162 } 163 164 build_stage('Test: full', Settings.RunAllTests) { 165 dir (BuildDir) { 166 //Run the tests from the tests directory 167 sh 'make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=yes' 168 sh 'make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=no ' 169 } 179 170 } 180 171 } -
doc/bibliography/pl.bib
rc2051e10 r17bc05b 943 943 } 944 944 945 @misc{Cforall, 946 contributer = {pabuhr@plg}, 947 key = {Cforall}, 948 author = {{\textsf{C}{$\mathbf{\forall}$} Features}}, 949 howpublished= {\href{https://plg.uwaterloo.ca/~cforall/features}{https://\-plg.uwaterloo.ca/\-$\sim$cforall/\-features}}, 950 } 951 952 @misc{CforallBenchMarks, 953 contributer = {pabuhr@plg}, 954 key = {Cforall Benchmarks}, 955 author = {{\textsf{C}{$\mathbf{\forall}$} Benchmarks}}, 956 howpublished= {\href{https://plg.uwaterloo.ca/~cforall/benchmark.tar}{https://\-plg.uwaterloo.ca/\-$\sim$cforall/\-benchmark.tar}}, 957 } 958 959 @mastersthesis{Esteves04, 960 keywords = {Cforall, parametric polymorphism, overloading}, 961 contributer = {pabuhr@plg}, 962 author = {Rodolfo Gabriel Esteves}, 963 title = {\textsf{C}$\mathbf{\forall}$, a Study in Evolutionary Design in Programming Languages}, 964 school = {School of Computer Science, University of Waterloo}, 965 year = 2004, 966 address = {Waterloo, Ontario, Canada, N2L 3G1}, 967 note = {\href{http://plg.uwaterloo.ca/theses/EstevesThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-EstevesThesis.pdf}}, 968 } 969 970 @misc{CFAStackEvaluation, 971 contributer = {a3moss@plg}, 972 author = {Aaron Moss}, 973 title = {\textsf{C}$\mathbf{\forall}$ Stack Evaluation Programs}, 974 year = 2018, 975 howpublished= {\href{https://cforall.uwaterloo.ca/CFAStackEvaluation.zip}{https://cforall.uwaterloo.ca/\-CFAStackEvaluation.zip}}, 976 } 977 945 978 @article{Moss18, 946 979 keywords = {type systems, polymorphism, tuples, Cforall}, … … 955 988 pages = {2111-2146}, 956 989 note = {\href{http://dx.doi.org/10.1002/spe.2624}{http://\-dx.doi.org/\-10.1002/\-spe.2624}}, 957 }958 959 @misc{CforallBenchMarks,960 contributer = {pabuhr@plg},961 key = {Cforall Benchmarks},962 author = {{\textsf{C}{$\mathbf{\forall}$} Benchmarks}},963 howpublished= {\href{https://plg.uwaterloo.ca/~cforall/benchmark.tar}{https://\-plg.uwaterloo.ca/\-$\sim$cforall/\-benchmark.tar}},964 }965 966 @misc{Cforall,967 contributer = {pabuhr@plg},968 key = {Cforall},969 author = {{\textsf{C}{$\mathbf{\forall}$} Features}},970 howpublished= {\href{https://plg.uwaterloo.ca/~cforall/features}{https://\-plg.uwaterloo.ca/\-$\sim$cforall/\-features}},971 }972 973 @misc{CFAStackEvaluation,974 contributer = {a3moss@plg},975 author = {Aaron Moss},976 title = {\textsf{C}$\mathbf{\forall}$ Stack Evaluation Programs},977 year = 2018,978 howpublished= {\href{https://cforall.uwaterloo.ca/CFAStackEvaluation.zip}{https://cforall.uwaterloo.ca/\-CFAStackEvaluation.zip}},979 }980 981 @mastersthesis{Esteves04,982 keywords = {Cforall, parametric polymorphism, overloading},983 contributer = {pabuhr@plg},984 author = {Rodolfo Gabriel Esteves},985 title = {\textsf{C}$\mathbf{\forall}$, a Study in Evolutionary Design in Programming Languages},986 school = {School of Computer Science, University of Waterloo},987 year = 2004,988 address = {Waterloo, Ontario, Canada, N2L 3G1},989 note = {\href{http://plg.uwaterloo.ca/theses/EstevesThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-EstevesThesis.pdf}},990 }991 992 @phdthesis{Moss19,993 keywords = {type system, generic type, resolution algorithm, type environment, Cforall},994 author = {Aaron Moss},995 title = {\textsf{C}$\mathbf{\forall}$ Type System Implementation},996 school = {School of Computer Science, University of Waterloo},997 year = 2019,998 optaddress = {Waterloo, Ontario, Canada, N2L 3G1},999 note = {\href{https://uwspace.uwaterloo.ca/handle/10012/14584}{https://\-uwspace.uwaterloo.ca/\-handle/\-10012/\-14584}},1000 990 } 1001 991 … … 1111 1101 1112 1102 @techreport{Prokopec11, 1113 keywords= {ctrie, concurrent map},1114 contributer = {a3moss@uwaterloo.ca},1115 title={Cache-aware lock-free concurrent hash tries},1116 author={Prokopec, Aleksandar and Bagwell, Phil and Odersky, Martin},1117 institution={EPFL},1118 year={2011}1103 keywords = {ctrie, concurrent map}, 1104 contributer = {a3moss@uwaterloo.ca}, 1105 title={Cache-aware lock-free concurrent hash tries}, 1106 author={Prokopec, Aleksandar and Bagwell, Phil and Odersky, Martin}, 1107 institution={EPFL}, 1108 year={2011} 1119 1109 } 1120 1110 … … 1168 1158 1169 1159 @phdthesis{Norrish98, 1170 title ={C formalised in HOL},1171 author ={Norrish, Michael},1172 year ={1998},1173 school ={University of Cambridge}1160 title={C formalised in HOL}, 1161 author={Norrish, Michael}, 1162 year={1998}, 1163 school={University of Cambridge} 1174 1164 } 1175 1165 … … 1180 1170 title = {Checked C: Making C Safe by Extension}, 1181 1171 booktitle = {2018 IEEE Cybersecurity Development (SecDev)}, 1172 year = {2018}, 1173 month = {September}, 1174 pages = {53-60}, 1182 1175 publisher = {IEEE}, 1183 year = {2018},1184 month = sep,1185 pages = {53-60},1186 1176 url = {https://www.microsoft.com/en-us/research/publication/checkedc-making-c-safe-by-extension/}, 1187 1177 } … … 1295 1285 1296 1286 @inproceedings{Odersky01, 1297 keywords= {Scala},1298 contributer= {a3moss@uwaterloo.ca},1299 author= {Odersky, Martin and Zenger, Christoph and Zenger, Matthias},1300 title= {Colored Local Type Inference},1301 booktitle= {Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages},1302 series= {POPL '01},1303 year= {2001},1304 isbn= {1-58113-336-7},1305 location= {London, United Kingdom},1306 pages= {41--53},1307 numpages= {13},1308 url= {http://doi.acm.org/10.1145/360204.360207},1309 doi= {10.1145/360204.360207},1310 acmid= {360207},1311 publisher= {ACM},1312 address= {New York, NY, USA},1287 keywords = {Scala}, 1288 contributer = {a3moss@uwaterloo.ca}, 1289 author = {Odersky, Martin and Zenger, Christoph and Zenger, Matthias}, 1290 title = {Colored Local Type Inference}, 1291 booktitle = {Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages}, 1292 series = {POPL '01}, 1293 year = {2001}, 1294 isbn = {1-58113-336-7}, 1295 location = {London, United Kingdom}, 1296 pages = {41--53}, 1297 numpages = {13}, 1298 url = {http://doi.acm.org/10.1145/360204.360207}, 1299 doi = {10.1145/360204.360207}, 1300 acmid = {360207}, 1301 publisher = {ACM}, 1302 address = {New York, NY, USA}, 1313 1303 } 1314 1304 … … 1703 1693 1704 1694 @inproceedings{Prokopec12, 1705 keywords ={ctrie, hash trie, concurrent map},1706 contributer ={a3moss@uwaterloo.ca},1707 title ={Concurrent tries with efficient non-blocking snapshots},1708 author ={Prokopec, Aleksandar and Bronson, Nathan Grasso and Bagwell, Phil and Odersky, Martin},1709 booktitle ={ACM SIGPLAN Notices},1710 volume ={47},1711 number ={8},1712 pages ={151--160},1713 year ={2012},1714 organization={ACM}1695 keywords={ctrie, hash trie, concurrent map}, 1696 contributer={a3moss@uwaterloo.ca}, 1697 title={Concurrent tries with efficient non-blocking snapshots}, 1698 author={Prokopec, Aleksandar and Bronson, Nathan Grasso and Bagwell, Phil and Odersky, Martin}, 1699 booktitle={ACM SIGPLAN Notices}, 1700 volume={47}, 1701 number={8}, 1702 pages={151--160}, 1703 year={2012}, 1704 organization={ACM} 1715 1705 } 1716 1706 … … 1739 1729 } 1740 1730 1741 @article{Delisle1 9,1731 @article{Delisle18b, 1742 1732 keywords = {concurrency, Cforall}, 1743 1733 contributer = {pabuhr@plg}, 1744 1734 author = {Thierry Delisle and Peter A. Buhr}, 1745 title = { Advanced Control-flow andConcurrency in \textsf{C}$\mathbf{\forall}$},1746 year = 201 9,1735 title = {Concurrency in \textsf{C}$\mathbf{\forall}$}, 1736 year = 2018, 1747 1737 journal = spe, 1748 pages = {1-3 3},1738 pages = {1-32}, 1749 1739 note = {submitted}, 1750 1740 } … … 2510 2500 2511 2501 @misc{Dotty-github, 2512 keywords = {dotty,scala},2513 contributer = {a3moss@uwaterloo.ca},2514 author = {Martin Odersky},2515 title = {Dotty},2516 howpublished = {\href{https://github.com/lampepfl/dotty}{https://\-github.com/\-lampepfl/\-dotty}},2517 note = {Acessed: 2019-02-22}2502 keywords = {dotty,scala}, 2503 contributer = {a3moss@uwaterloo.ca}, 2504 author = {Martin Odersky}, 2505 title = {Dotty}, 2506 howpublished = {\href{https://github.com/lampepfl/dotty}{https://\-github.com/\-lampepfl/\-dotty}}, 2507 note = {Acessed: 2019-02-22} 2518 2508 } 2519 2509 … … 2666 2656 volume = 10, 2667 2657 number = 3, 2668 pages = {120-123},2658 pages = {120-123}, 2669 2659 comment = { 2670 2660 The ``two-pass'' algorithm. An upward pass over a parse tree … … 3246 3236 3247 3237 @article{Leroy09, 3248 keywords= {C formalization},3249 contributer= {a3moss@uwaterloo.ca},3250 author= {Leroy, Xavier},3251 title= {Formal Verification of a Realistic Compiler},3252 journal= {Commun. ACM},3253 issue_date= {July 2009},3254 volume= {52},3255 number= {7},3256 month= jul,3257 year= {2009},3258 issn= {0001-0782},3259 pages= {107--115},3260 numpages= {9},3261 url= {http://doi.acm.org/10.1145/1538788.1538814},3262 doi= {10.1145/1538788.1538814},3263 acmid= {1538814},3264 publisher= {ACM},3265 address= {New York, NY, USA},3238 keywords = {C formalization}, 3239 contributer = {a3moss@uwaterloo.ca}, 3240 author = {Leroy, Xavier}, 3241 title = {Formal Verification of a Realistic Compiler}, 3242 journal = {Commun. ACM}, 3243 issue_date = {July 2009}, 3244 volume = {52}, 3245 number = {7}, 3246 month = jul, 3247 year = {2009}, 3248 issn = {0001-0782}, 3249 pages = {107--115}, 3250 numpages = {9}, 3251 url = {http://doi.acm.org/10.1145/1538788.1538814}, 3252 doi = {10.1145/1538788.1538814}, 3253 acmid = {1538814}, 3254 publisher = {ACM}, 3255 address = {New York, NY, USA}, 3266 3256 } 3267 3257 … … 4191 4181 4192 4182 @article{Morgado13, 4193 keywords= {expression resolution},4194 contributer= {a3moss@uwaterloo.ca},4195 title ={Iterative and core-guided {MaxSAT} solving: A survey and assessment},4196 author ={Morgado, Antonio and Heras, Federico and Liffiton, Mark and Planes, Jordi and Marques-Silva, Joao},4197 journal ={Constraints},4198 volume ={18},4199 number ={4},4200 pages ={478--534},4201 year ={2013},4202 publisher ={Springer}4183 keywords = {expression resolution}, 4184 contributer = {a3moss@uwaterloo.ca}, 4185 title={Iterative and core-guided {MaxSAT} solving: A survey and assessment}, 4186 author={Morgado, Antonio and Heras, Federico and Liffiton, Mark and Planes, Jordi and Marques-Silva, Joao}, 4187 journal={Constraints}, 4188 volume={18}, 4189 number={4}, 4190 pages={478--534}, 4191 year={2013}, 4192 publisher={Springer} 4203 4193 } 4204 4194 … … 4399 4389 } 4400 4390 4391 4401 4392 @article{Liskov86, 4402 4393 keywords = {synchronous communication, concurrency}, … … 4457 4448 4458 4449 @article{Pierce00, 4459 keywords= {Scala},4460 contributer= {a3moss@uwaterloo.ca},4461 author= {Pierce, Benjamin C. and Turner, David N.},4462 title= {Local Type Inference},4463 journal= {ACM Trans. Program. Lang. Syst.},4464 issue_date= {Jan. 2000},4465 volume= {22},4466 number= {1},4467 month= jan,4468 year= {2000},4469 issn= {0164-0925},4470 pages= {1--44},4471 numpages= {44},4472 url= {http://doi.acm.org/10.1145/345099.345100},4473 doi= {10.1145/345099.345100},4474 acmid= {345100},4475 publisher= {ACM},4476 address= {New York, NY, USA},4477 keywords= {polymorphism, subtyping, type inference},4450 keywords = {Scala}, 4451 contributer = {a3moss@uwaterloo.ca}, 4452 author = {Pierce, Benjamin C. and Turner, David N.}, 4453 title = {Local Type Inference}, 4454 journal = {ACM Trans. Program. Lang. Syst.}, 4455 issue_date = {Jan. 2000}, 4456 volume = {22}, 4457 number = {1}, 4458 month = jan, 4459 year = {2000}, 4460 issn = {0164-0925}, 4461 pages = {1--44}, 4462 numpages = {44}, 4463 url = {http://doi.acm.org/10.1145/345099.345100}, 4464 doi = {10.1145/345099.345100}, 4465 acmid = {345100}, 4466 publisher = {ACM}, 4467 address = {New York, NY, USA}, 4468 keywords = {polymorphism, subtyping, type inference}, 4478 4469 } 4479 4470 … … 5458 5449 5459 5450 @inproceedings{Krebbers14, 5460 keywords= {c formalization},5461 contributer= {a3moss@uwaterloo.ca},5462 author= {Krebbers, Robbert},5463 title= {An Operational and Axiomatic Semantics for Non-determinism and Sequence Points in C},5464 booktitle= {Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages},5465 series= {POPL '14},5466 year= {2014},5467 isbn= {978-1-4503-2544-8},5468 location= {San Diego, California, USA},5469 pages= {101--112},5470 numpages= {12},5471 url= {http://doi.acm.org/10.1145/2535838.2535878},5472 doi= {10.1145/2535838.2535878},5473 acmid= {2535878},5474 publisher= {ACM},5475 address= {New York, NY, USA},5451 keywords = {c formalization}, 5452 contributer = {a3moss@uwaterloo.ca}, 5453 author = {Krebbers, Robbert}, 5454 title = {An Operational and Axiomatic Semantics for Non-determinism and Sequence Points in C}, 5455 booktitle = {Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages}, 5456 series = {POPL '14}, 5457 year = {2014}, 5458 isbn = {978-1-4503-2544-8}, 5459 location = {San Diego, California, USA}, 5460 pages = {101--112}, 5461 numpages = {12}, 5462 url = {http://doi.acm.org/10.1145/2535838.2535878}, 5463 doi = {10.1145/2535838.2535878}, 5464 acmid = {2535878}, 5465 publisher = {ACM}, 5466 address = {New York, NY, USA}, 5476 5467 } 5477 5468 … … 7540 7531 7541 7532 @article{SysVABI, 7542 keywords ={System V ABI},7543 contributer ={a3moss@uwaterloo.ca},7544 title ={System {V} application binary interface},7545 author ={Matz, Michael and Hubicka, Jan and Jaeger, Andreas and Mitchell, Mark},7546 journal ={AMD64 Architecture Processor Supplement, Draft v0},7547 volume ={99},7548 year ={2013}7533 keywords = {System V ABI}, 7534 contributer = {a3moss@uwaterloo.ca}, 7535 title={System {V} application binary interface}, 7536 author={Matz, Michael and Hubicka, Jan and Jaeger, Andreas and Mitchell, Mark}, 7537 journal={AMD64 Architecture Processor Supplement, Draft v0}, 7538 volume={99}, 7539 year={2013} 7549 7540 } 7550 7541 … … 7773 7764 7774 7765 @techreport{Black90, 7775 title ={Typechecking polymorphism in {Emerald}},7776 author ={Black, Andrew P and Hutchinson, Norman C},7777 year ={1990},7778 institution ={Cambridge Research Laboratory, Digital Equipment Corporation}7766 title={Typechecking polymorphism in {Emerald}}, 7767 author={Black, Andrew P and Hutchinson, Norman C}, 7768 year={1990}, 7769 institution={Cambridge Research Laboratory, Digital Equipment Corporation} 7779 7770 } 7780 7771 -
driver/cc1.cc
rc2051e10 r17bc05b 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 9 17:50:53 201913 // Update Count : 38412 // Last Modified On : Mon Sep 3 16:57:05 2018 13 // Update Count : 125 14 14 // 15 15 … … 19 19 #include <string> 20 20 using std::string; 21 #include <algorithm> // find22 21 #include <cstdio> // stderr, stdout, perror, fprintf 23 22 #include <cstdlib> // getenv, exit, mkstemp 24 23 #include <unistd.h> // execvp, fork, unlink 25 24 #include <sys/wait.h> // wait 26 #include <fcntl.h>27 28 25 29 26 #include "config.h" // configure info … … 33 30 34 31 35 static string compiler_path( CFA_BACKEND_CC ); // C compiler path/name 36 static bool CFA_flag = false; // -CFA flag 37 static bool save_temps = false; // -save-temps flag 38 static string o_file; 39 static string bprefix; 40 41 42 static bool prefix( const string & arg, const string & pre ) { 32 string compiler_name( CFA_BACKEND_CC ); // path/name of C compiler 33 34 string D__GCC_BPREFIX__( "-D__GCC_BPREFIX__=" ); 35 string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" ); 36 37 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 38 int tmpfilefd = -1; 39 40 41 bool prefix( string arg, string pre ) { 43 42 return arg.substr( 0, pre.size() ) == pre; 44 43 } // prefix 45 44 46 static void suffix( const string & arg, const char * args[], int & nargs ) { 47 enum { NumSuffixes = 3 }; 48 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 49 45 enum { NumSuffixes = 2 }; 46 const string suffixes[NumSuffixes] = { "cfa", "hfa", }; 47 48 void suffix( string arg, const char * args[], int & nargs ) { 49 //std::cerr << arg << std::endl; 50 50 size_t dot = arg.find_last_of( "." ); 51 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl; 51 52 if ( dot == string::npos ) return; 52 const string * end = suffixes + NumSuffixes; 53 if ( std::find( suffixes, end, arg.substr( dot + 1 ) ) != end ) { 54 args[nargs++] = "-x"; 55 args[nargs++] = "c"; 56 } // if 53 string sx = arg.substr( dot + 1 ); 54 for ( int i = 0; i < NumSuffixes; i += 1 ) { 55 if ( sx == suffixes[i] ) { 56 args[nargs] = "-x"; 57 nargs += 1; 58 args[nargs] = "c"; 59 nargs += 1; 60 return; 61 } // if 62 } // for 57 63 } // suffix 58 64 59 65 60 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "N__=" suffix 61 62 static void checkEnv1( const char * args[], int & nargs ) { // stage 1 63 extern char ** environ; 64 65 for ( int i = 0; environ[i]; i += 1 ) { 66 string arg( environ[i] ); 66 void checkEnv( const char * args[], int & nargs ) { 67 char *value; 68 69 value = getenv( "__CFA_COMPILER__" ); 70 if ( value != NULL ) { 71 compiler_name = value; 67 72 #ifdef __DEBUG_H__ 68 cerr << "env arg:\"" << arg<< "\"" << endl;73 cerr << "env arg:\"" << compiler_name << "\"" << endl; 69 74 #endif // __DEBUG_H__ 70 71 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 72 string val( arg.substr( arg.find_first_of( "=" ) + 1 ) ); 73 if ( prefix( val, "-compiler=" ) ) { 74 compiler_path = val.substr( 10 ); 75 } // if 76 } // if 77 } // for 78 } // checkEnv1 79 80 81 static void checkEnv2( const char * args[], int & nargs ) { // stage 2 82 extern char ** environ; 83 84 for ( int i = 0; environ[i]; i += 1 ) { 85 string arg( environ[i] ); 75 } // if 76 77 value = getenv( "__GCC_MACHINE__" ); 78 if ( value != NULL ) { 79 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 86 80 #ifdef __DEBUG_H__ 87 cerr << "env arg:\"" << arg << "\"" << endl;81 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 88 82 #endif // __DEBUG_H__ 89 90 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 91 string val( arg.substr( arg.find_first_of( "=" ) + 1 ) ); 92 if ( prefix( val, "-compiler=" ) ) { 93 compiler_path = val.substr( 10 ); 94 } else if ( val == "-CFA" ) { 95 CFA_flag = true; 96 } else if ( val == "-save-temps" ) { 97 save_temps = true; 98 } else if ( prefix( val, "-o=" ) ) { // output file for -CFA 99 o_file = val.substr( 3 ); 100 } else if ( prefix( val, "-B=" ) ) { // location of cfa-cpp 101 bprefix = val.substr( 3 ); 102 } else { // normal flag for cfa-cpp 103 args[nargs++] = ( *new string( arg.substr( arg.find_first_of( "=" ) + 1 ) ) ).c_str(); 104 } // if 105 } // if 106 } // for 107 } // checkEnv2 108 109 110 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa"; 111 static int tmpfilefd = -1; 112 static bool startrm = false; 113 114 static void rmtmpfile() { 115 if ( tmpfilefd == -1 ) return; // RACE, file created ? 116 117 startrm = true; // RACE with C-c C-c 83 nargs += 1; 84 } // if 85 86 value = getenv( "__GCC_VERSION__" ); 87 if ( value != NULL ) { 88 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 89 #ifdef __DEBUG_H__ 90 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 91 #endif // __DEBUG_H__ 92 nargs += 1; 93 } // if 94 } // checkEnv 95 96 97 void rmtmpfile() { 118 98 if ( unlink( tmpname ) == -1 ) { // remove tmpname 119 perror ( "C C1 Translator error: failed, unlink" );120 exit( EXIT_FAILURE ); 121 } // if 122 tmpfilefd = -1; // mark removed99 perror ( "CFA Translator error: cpp failed" ); 100 exit( EXIT_FAILURE ); 101 } // if 102 tmpfilefd = -1; // mark closed 123 103 } // rmtmpfile 124 104 125 105 126 static void sigTermHandler( int ) { // C-c C-c 127 if ( startrm ) return; // return and let rmtmpfile finish, and then program finishes 128 106 void sigTermHandler( __attribute__((unused)) int signal ) { 129 107 if ( tmpfilefd != -1 ) { // RACE, file created ? 130 rmtmpfile(); // remove tmpname131 } // if132 exit( EXIT_FAILURE ); // terminate108 rmtmpfile(); // remove 109 exit( EXIT_FAILURE ); // terminate 110 } // if 133 111 } // sigTermHandler 134 112 135 113 136 staticvoid Stage1( const int argc, const char * const argv[] ) {114 void Stage1( const int argc, const char * const argv[] ) { 137 115 int code; 116 138 117 string arg; 139 140 const char * cpp_in = nullptr; 141 const char * cpp_out = nullptr; 142 118 string bprefix; 119 120 const char *cpp_in = NULL; 121 const char *cpp_out = NULL; 122 123 bool CFA_flag = false; 143 124 bool cpp_flag = false; 144 bool o_flag = false;145 146 const char * args[argc + 100]; // leave space for 100 additional cpp command line values125 const char *o_name = NULL; 126 127 const char *args[argc + 100]; // leave space for 100 additional cpp command line values 147 128 int nargs = 1; // number of arguments in args list; 0 => command name 129 const char *cargs[20]; // leave space for 20 additional cfa-cpp command line values 130 int ncargs = 1; // 0 => command name 131 132 signal( SIGINT, sigTermHandler ); 133 signal( SIGTERM, sigTermHandler ); 148 134 149 135 #ifdef __DEBUG_H__ 150 136 cerr << "Stage1" << endl; 151 137 #endif // __DEBUG_H__ 152 checkEnv 1( args, nargs ); // arguments passed via environment variables138 checkEnv( args, nargs ); // arguments passed via environment variables 153 139 #ifdef __DEBUG_H__ 154 140 for ( int i = 1; i < argc; i += 1 ) { … … 182 168 i += 1; // and the argument 183 169 cpp_flag = true; 184 185 // all other flags 170 } else if ( arg == "-D__CFA_PREPROCESS__" ) { 171 CFA_flag = true; 172 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CFA_PREPROCESS__" ) { 173 i += 1; // and the argument 174 CFA_flag = true; 175 } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) { 176 cargs[ncargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str(); 177 ncargs += 1; 178 } else if ( arg == "-D" && prefix( argv[i + 1], D__CFA_FLAGPREFIX__.substr(2) ) ) { 179 cargs[ncargs] = ( *new string( string( argv[i + 1] ).substr( D__CFA_FLAGPREFIX__.size() - 2 ) ) ).c_str(); 180 ncargs += 1; 181 i += 1; // and the argument 182 } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) { 183 bprefix = arg.substr( D__GCC_BPREFIX__.size() ); 184 } else if ( arg == "-D" && prefix( argv[i + 1], D__GCC_BPREFIX__.substr(2) ) ) { 185 bprefix = string( argv[i + 1] ).substr( D__GCC_BPREFIX__.size() - 2 ); 186 i += 1; // and the argument 187 188 // all other flags 186 189 187 190 } else if ( arg == "-o" ) { 188 191 i += 1; 189 o_flag = true; 190 cpp_out = argv[i]; 192 o_name = argv[i]; 191 193 } else { 192 args[nargs++] = argv[i]; // pass the flag along 194 args[nargs] = argv[i]; // pass the flag along 195 nargs += 1; 193 196 // CPP flags with an argument 194 197 if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" || … … 196 199 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) { 197 200 i += 1; 198 args[nargs++] = argv[i]; // pass the argument along 201 args[nargs] = argv[i]; // pass the argument along 202 nargs += 1; 199 203 #ifdef __DEBUG_H__ 200 204 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 201 205 #endif // __DEBUG_H__ 202 206 } else if ( arg == "-MD" || arg == "-MMD" ) { 203 args[nargs++] = "-MF"; // insert before file 207 args[nargs] = "-MF"; // insert before file 208 nargs += 1; 204 209 i += 1; 205 args[nargs++] = argv[i]; // pass the argument along 210 args[nargs] = argv[i]; // pass the argument along 211 nargs += 1; 206 212 #ifdef __DEBUG_H__ 207 213 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; … … 210 216 } // if 211 217 } else { // obtain input and possibly output files 212 if ( cpp_in == nullptr) {218 if ( cpp_in == NULL ) { 213 219 cpp_in = argv[i]; 214 220 #ifdef __DEBUG_H__ 215 221 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 216 222 #endif // __DEBUG_H__ 217 } else if ( cpp_out == nullptr) {223 } else if ( cpp_out == NULL ) { 218 224 cpp_out = argv[i]; 219 225 #ifdef __DEBUG_H__ … … 232 238 cerr << " " << args[i]; 233 239 } // for 234 if ( cpp_in != nullptr) cerr << " " << cpp_in;235 if ( cpp_out != nullptr) cerr << " " << cpp_out;240 if ( cpp_in != NULL ) cerr << " " << cpp_in; 241 if ( cpp_out != NULL ) cerr << " " << cpp_out; 236 242 cerr << endl; 237 243 #endif // __DEBUG_H__ 238 244 239 if ( cpp_in == nullptr) {245 if ( cpp_in == NULL ) { 240 246 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; 241 247 exit( EXIT_FAILURE ); … … 246 252 // output or -o. The call to cfa has a -E so it does not have to be added to the argument list. 247 253 248 args[0] = compiler_ path.c_str();254 args[0] = compiler_name.c_str(); 249 255 suffix( cpp_in, args, nargs ); // check suffix 250 args[nargs++] = cpp_in; 251 if ( o_flag ) { // location for output 252 args[nargs++] = "-o"; 256 args[nargs] = cpp_in; 257 nargs += 1; 258 if ( o_name != NULL ) { // location for output 259 args[nargs] = "-o"; 260 nargs += 1; 261 args[nargs] = o_name; 262 nargs += 1; 253 263 } // if 254 args[nargs++] = cpp_out; 255 args[nargs] = nullptr; // terminate argument list 264 args[nargs] = NULL; // terminate argument list 256 265 257 266 #ifdef __DEBUG_H__ 258 267 cerr << "nargs: " << nargs << endl; 259 for ( int i = 0; args[i] != nullptr; i += 1 ) {268 for ( int i = 0; args[i] != NULL; i += 1 ) { 260 269 cerr << args[i] << " "; 261 270 } // for … … 263 272 #endif // __DEBUG_H__ 264 273 265 execvp( args[0], (char * const *)args ); // should not return 266 perror( "CC1 Translator error: stage 1, execvp" ); 267 exit( EXIT_FAILURE ); 268 } // if 269 270 // Run the C preprocessor and save the output in the given file. 274 execvp( args[0], (char *const *)args ); // should not return 275 perror( "CFA Translator error: cpp level, execvp" ); 276 exit( EXIT_FAILURE ); 277 } // if 278 279 // Create a temporary file to store output of the C preprocessor. 280 281 tmpfilefd = mkstemp( tmpname ); 282 if ( tmpfilefd == -1 ) { 283 perror( "CFA Translator error: cpp level, mkstemp" ); 284 exit( EXIT_FAILURE ); 285 } // if 286 287 #ifdef __DEBUG_H__ 288 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 289 #endif // __DEBUG_H__ 290 291 // Run the C preprocessor and save the output in tmpfile. 271 292 272 293 if ( fork() == 0 ) { // child process ? … … 274 295 // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error, 275 296 // when cpp writes to stdout. Hence, stdout is redirected into the temporary file. 276 if ( freopen( cpp_out, "w", stdout ) == nullptr ) { // redirect stdout to output file277 perror( "C C1 Translator error: stage 1, freopen" );297 if ( freopen( tmpname, "w", stdout ) == NULL ) { // redirect stdout to tmpname 298 perror( "CFA Translator error: cpp level, freopen" ); 278 299 exit( EXIT_FAILURE ); 279 300 } // if 280 301 281 args[0] = compiler_ path.c_str();302 args[0] = compiler_name.c_str(); 282 303 suffix( cpp_in, args, nargs ); // check suffix 283 args[nargs++] = cpp_in; // input to cpp 284 args[nargs] = nullptr; // terminate argument list 304 args[nargs] = cpp_in; // input to cpp 305 nargs += 1; 306 args[nargs] = NULL; // terminate argument list 285 307 286 308 #ifdef __DEBUG_H__ 287 309 cerr << "cpp nargs: " << nargs << endl; 288 for ( int i = 0; args[i] != nullptr; i += 1 ) {310 for ( int i = 0; args[i] != NULL; i += 1 ) { 289 311 cerr << args[i] << " "; 290 312 } // for … … 292 314 #endif // __DEBUG_H__ 293 315 294 execvp( args[0], (char * const *)args ); // should not return 295 perror( "CC1 Translator error: stage 1 cpp, execvp" ); 296 cerr << " invoked " << args[0] << endl; 316 execvp( args[0], (char *const *)args ); // should not return 317 perror( "CFA Translator error: cpp level, execvp" ); 297 318 exit( EXIT_FAILURE ); 298 319 } // if … … 304 325 #endif // __DEBUG_H__ 305 326 327 if ( WIFSIGNALED(code) != 0 ) { // child failed ? 328 rmtmpfile(); // remove tmpname 329 cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl; 330 exit( EXIT_FAILURE ); 331 } // if 332 333 if ( WEXITSTATUS(code) != 0 ) { // child error ? 334 rmtmpfile(); // remove tmpname 335 exit( WEXITSTATUS( code ) ); // do not continue 336 } // if 337 338 // If -CFA flag specified, run the cfa-cpp preprocessor on the temporary file, and output is written to standard 339 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 340 341 if ( fork() == 0 ) { // child runs CFA 342 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str(); 343 344 // Source file-name used to generate routine names containing global initializations for TU. 345 cargs[ncargs] = ( *new string( "-F" ) ).c_str(); 346 ncargs += 1; 347 cargs[ncargs] = ( *new string( string( cpp_in ) ) ).c_str(); 348 ncargs += 1; 349 350 cargs[ncargs] = tmpname; 351 ncargs += 1; 352 if ( o_name != NULL ) { 353 cargs[ncargs] = o_name; 354 ncargs += 1; 355 } else if ( ! CFA_flag ) { // run cfa-cpp ? 356 cargs[ncargs] = cpp_out; 357 ncargs += 1; 358 } // if 359 cargs[ncargs] = NULL; // terminate argument list 360 361 #ifdef __DEBUG_H__ 362 cerr << "cfa-cpp ncargs: " << (o_name ? o_name : "No -o") << " " << CFA_flag << " " << ncargs << endl; 363 for ( int i = 0; cargs[i] != NULL; i += 1 ) { 364 cerr << cargs[i] << " "; 365 } // for 366 cerr << endl; 367 #endif // __DEBUG_H__ 368 369 execvp( cargs[0], (char * const *)cargs ); // should not return 370 perror( "CFA Translator error: cpp level, execvp" ); 371 exit( EXIT_FAILURE ); 372 } // if 373 374 wait( &code ); // wait for child to finish 375 376 #ifdef __DEBUG_H__ 377 cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl; 378 #endif // __DEBUG_H__ 379 380 // Must unlink here because file must exist across execvp. 381 rmtmpfile(); // remove tmpname 382 306 383 if ( WIFSIGNALED(code) ) { // child failed ? 307 cerr << "C C1 Translator error: stage 1, child failed" << WTERMSIG(code) << endl;308 exit( EXIT_FAILURE ); 309 } // if 310 311 exit( WEXITSTATUS(code) ); // bad cpp result stops top-level gcc384 cerr << "CFA Translator error: cfa-cpp failed with signal " << WTERMSIG(code) << endl; 385 exit( EXIT_FAILURE ); 386 } // if 387 388 exit( WEXITSTATUS(code) ); 312 389 } // Stage1 313 390 314 391 315 static void Stage2( const int argc, const char * const * argv ) { 316 int code; 392 void Stage2( const int argc, const char * const * argv ) { 317 393 string arg; 318 394 319 const char * cpp_in = nullptr; 320 const char * cpp_out = nullptr; 321 322 const char * args[argc + 100]; // leave space for 100 additional cfa command line values 395 const char *cpp_in = NULL; 396 397 const char *args[argc + 100]; // leave space for 100 additional cfa command line values 323 398 int nargs = 1; // number of arguments in args list; 0 => command name 324 const char * cargs[20]; // leave space for 20 additional cfa-cpp command line values325 int ncargs = 1; // 0 => command name326 399 327 400 #ifdef __DEBUG_H__ 328 401 cerr << "Stage2" << endl; 329 402 #endif // __DEBUG_H__ 330 checkEnv 2( cargs, ncargs ); // arguments passed via environment variables403 checkEnv( args, nargs ); // arguments passed via environment variables 331 404 #ifdef __DEBUG_H__ 332 405 for ( int i = 1; i < argc; i += 1 ) { … … 357 430 358 431 } else { 359 args[nargs++] = argv[i]; // pass the flag along 432 args[nargs] = argv[i]; // pass the flag along 433 nargs += 1; 360 434 if ( arg == "-o" ) { 361 435 i += 1; 362 cpp_out = argv[i];363 args[nargs++] = argv[i]; // pass the argument along436 args[nargs] = argv[i]; // pass the argument along 437 nargs += 1; 364 438 #ifdef __DEBUG_H__ 365 439 cerr << "arg:\"" << argv[i] << "\"" << endl; … … 368 442 } // if 369 443 } else { // obtain input and possibly output files 370 if ( cpp_in == nullptr) {444 if ( cpp_in == NULL ) { 371 445 cpp_in = argv[i]; 372 446 #ifdef __DEBUG_H__ 373 447 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 374 448 #endif // __DEBUG_H__ 375 } else if ( cpp_out == nullptr ) {376 cpp_out = argv[i];377 #ifdef __DEBUG_H__378 cerr << "cpp_out:\"" << cpp_out << "\""<< endl;379 #endif // __DEBUG_H__380 449 } else { 381 cerr << "Usage: " << argv[0] << " more than two files specified" << endl;450 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; 382 451 exit( EXIT_FAILURE ); 383 452 } // if … … 385 454 } // for 386 455 387 if ( cpp_in == nullptr ) {388 cerr << "Usage: " << argv[0] << " missing input file" << endl;389 exit( EXIT_FAILURE );390 } // if391 if ( cpp_out == nullptr ) {392 cerr << "Usage: " << argv[0] << " missing output file" << endl;393 exit( EXIT_FAILURE );394 } // if395 396 // Create a temporary file, if needed, to store output of the cfa-cpp preprocessor. Cannot be created in forked397 // process because variables tmpname and tmpfilefd are cloned.398 399 string cfa_cpp_out;400 401 if ( ! CFA_flag ) { // run compiler ?402 if ( save_temps ) {403 cfa_cpp_out = cpp_in;404 size_t dot = cfa_cpp_out.find_last_of( "." );405 if ( dot == string::npos ) {406 cerr << "CC1 Translator error: stage 2, bad file name " << endl;407 exit( EXIT_FAILURE );408 } // if409 410 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";411 if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) {412 perror( "CC1 Translator error: stage 2, creat" );413 exit( EXIT_FAILURE );414 } // if415 } else {416 tmpfilefd = mkstemps( tmpname, 4 );417 if ( tmpfilefd == -1 ) {418 perror( "CC1 Translator error: stage 2, mkstemp" );419 exit( EXIT_FAILURE );420 } // if421 cfa_cpp_out = tmpname;422 } // if423 #ifdef __DEBUG_H__424 cerr << "cfa_cpp_out: " << cfa_cpp_out << endl;425 #endif // __DEBUG_H__426 } // if427 428 // If -CFA flag specified, run the cfa-cpp preprocessor on the temporary file, and output is written to standard429 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.430 431 if ( fork() == 0 ) { // child runs CFA432 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();433 cargs[ncargs++] = cpp_in;434 435 if ( CFA_flag ) { // run cfa-cpp ?436 if ( o_file.size() != 0 ) { // location for output437 cargs[ncargs++] = ( *new string( o_file.c_str() ) ).c_str();438 } // if439 } else {440 cargs[ncargs++] = cfa_cpp_out.c_str();441 } // if442 cargs[ncargs] = nullptr; // terminate argument list443 444 #ifdef __DEBUG_H__445 for ( int i = 0; cargs[i] != nullptr; i += 1 ) {446 cerr << cargs[i] << " ";447 } // for448 cerr << endl;449 #endif // __DEBUG_H__450 451 execvp( cargs[0], (char * const *)cargs ); // should not return452 perror( "CC1 Translator error: stage 2 cfa-cpp, execvp" );453 cerr << " invoked " << cargs[0] << endl;454 exit( EXIT_FAILURE );455 } // if456 457 wait( &code ); // wait for child to finish458 459 if ( WIFSIGNALED(code) ) { // child failed ?460 rmtmpfile(); // remove tmpname461 cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl;462 exit( EXIT_FAILURE );463 } // if464 465 if ( CFA_flag ) { // no tmpfile created466 exit( WEXITSTATUS( code ) ); // stop regardless of success or failure467 } // if468 469 #ifdef __DEBUG_H__470 cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl;471 #endif // __DEBUG_H__472 473 if ( WEXITSTATUS(code) ) { // child error ?474 rmtmpfile(); // remove tmpname475 exit( WEXITSTATUS( code ) ); // do not continue476 } // if477 478 456 #ifdef __DEBUG_H__ 479 457 cerr << "args:"; … … 481 459 cerr << " " << args[i]; 482 460 } // for 483 cerr << " " << cpp_in << endl; 484 #endif // __DEBUG_H__ 485 486 if ( fork() == 0 ) { // child runs CFA 487 args[0] = compiler_path.c_str(); 488 args[nargs++] = "-S"; // only compile and put assembler output in specified file 489 args[nargs++] = "-x"; 490 args[nargs++] = "cpp-output"; 491 492 args[nargs++] = cfa_cpp_out.c_str(); 493 args[nargs] = nullptr; // terminate argument list 494 495 #ifdef __DEBUG_H__ 496 cerr << "stage2 nargs: " << nargs << endl; 497 for ( int i = 0; args[i] != nullptr; i += 1 ) { 498 cerr << args[i] << " "; 499 } // for 500 cerr << endl; 501 #endif // __DEBUG_H__ 502 503 execvp( args[0], (char * const *)args ); // should not return 504 perror( "CC1 Translator error: stage 2 cc1, execvp" ); 505 cerr << " invoked " << cargs[0] << endl; 506 exit( EXIT_FAILURE ); // tell gcc not to go any further 507 } // if 508 509 wait( &code ); // wait for child to finish 510 rmtmpfile(); // remove tmpname 511 512 if ( WIFSIGNALED(code) ) { // child failed ? 513 cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl; 514 exit( EXIT_FAILURE ); 515 } // if 516 517 #ifdef __DEBUG_H__ 518 cerr << "return code from gcc cc1:" << WEXITSTATUS(code) << endl; 519 #endif // __DEBUG_H__ 520 521 exit( WEXITSTATUS( code ) ); // stop regardless of success or failure 461 cerr << endl; 462 if ( cpp_in != NULL ) cerr << " " << cpp_in; 463 #endif // __DEBUG_H__ 464 465 args[0] = compiler_name.c_str(); 466 args[nargs] = "-S"; // only compile and put assembler output in specified file 467 nargs += 1; 468 args[nargs] = cpp_in; 469 nargs += 1; 470 args[nargs] = NULL; // terminate argument list 471 472 #ifdef __DEBUG_H__ 473 cerr << "stage2 nargs: " << nargs << endl; 474 for ( int i = 0; args[i] != NULL; i += 1 ) { 475 cerr << args[i] << " "; 476 } // for 477 cerr << endl; 478 #endif // __DEBUG_H__ 479 480 execvp( args[0], (char * const *)args ); // should not return 481 perror( "CFA Translator error: cpp level, execvp" ); 482 exit( EXIT_FAILURE ); // tell gcc not to go any further 522 483 } // Stage2 523 484 524 485 525 // This program is called twice because of the -no-integrated-cpp. The calls are differentiated by the first526 // command-line argument. The first call replaces the traditional cpp pass to preprocess the C program. The second call527 // is to the compiler, which is broken into two steps: preprocess again with cfa-cpp and then call gcc to compile the528 // doubly preprocessed program.529 530 486 int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) { 531 487 #ifdef __DEBUG_H__ 532 for ( int i = 0; env[i] != nullptr; i += 1 ) {488 for ( int i = 0; env[i] != NULL; i += 1 ) { 533 489 cerr << env[i] << endl; 534 490 } // for 535 491 #endif // __DEBUG_H__ 536 492 537 signal( SIGINT, sigTermHandler ); 538 signal( SIGTERM, sigTermHandler ); 539 540 string arg( argv[1] ); 493 string arg = argv[1]; 541 494 542 495 // Currently, stage 1 starts with flag -E and stage 2 with flag -fpreprocessed. -
driver/cfa.cc
rc2051e10 r17bc05b 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 9 17:57:40201913 // Update Count : 41712 // Last Modified On : Sat Aug 10 08:44:15 2019 13 // Update Count : 311 14 14 // 15 15 … … 28 28 #include "config.h" // configure info 29 29 30 30 31 using std::cerr; 31 32 using std::endl; … … 33 34 using std::to_string; 34 35 36 35 37 //#define __DEBUG_H__ 36 38 37 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "N__=" suffix 38 39 void Putenv( char * argv[], string arg ) { 40 // environment variables must have unique names 41 static int flags = 0; 42 43 if ( putenv( (char *)( *new string( string( __CFA_FLAGPREFIX__ + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) { 44 cerr << argv[0] << " error, cannot set environment variable." << endl; 45 exit( EXIT_FAILURE ); 46 } // if 47 } // Putenv 48 49 // check if string has prefix 39 50 40 bool prefix( const string & arg, const string & pre ) { 51 41 return arg.substr( 0, pre.size() ) == pre; … … 57 47 } 58 48 59 bool suffix( const string & arg ) { // check if string has suffix 60 enum { NumSuffixes = 3 }; 61 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 62 63 size_t dot = arg.find_last_of( "." ); 64 if ( dot == string::npos ) return false; 65 const string * end = suffixes + NumSuffixes; 66 return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end; 49 bool suffix( const string & arg ) { 50 static const string suffixes[] = { ".cfa", ".hfa", ".cfa.ii" }; 51 for(const auto sfix : suffixes) { 52 if(arg.size() <= sfix.size()) continue; 53 size_t pos = arg.find_last_of(sfix); 54 size_t exp = (arg.size() - 1); 55 if(pos == exp) return true; 56 } 57 return false; 67 58 } // suffix 68 59 69 60 70 static inline bool dirExists( const string & path ) { // check if directory exists 61 void shuffle( const char * args[], int S, int E, int N ) { 62 // S & E index 1 passed the end so adjust with -1 63 #ifdef __DEBUG_H__ 64 cerr << "shuffle:" << S << " " << E << " " << N << endl; 65 #endif // __DEBUG_H__ 66 for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { 67 #ifdef __DEBUG_H__ 68 cerr << "\t" << j << " " << j-N << endl; 69 #endif // __DEBUG_H__ 70 args[j] = args[j-N]; 71 } // for 72 } // shuffle 73 74 static inline bool dirExists( const string & path ) { 71 75 struct stat info; 72 if ( stat( path.c_str(), &info ) != 0 ) return false; 73 return (info.st_mode & S_IFDIR) != 0; 74 } // dirExists 76 if(stat( path.c_str(), &info ) != 0) 77 return false; 78 else if(info.st_mode & S_IFDIR) 79 return true; 80 else 81 return false; 82 } //dirExists 75 83 76 84 static inline string dir(const string & path) { … … 79 87 80 88 81 #define xstr(s) str(s)82 89 #define str(s) #s 83 90 84 91 int main( int argc, char * argv[] ) { 85 92 string Version( CFA_VERSION_LONG ); // current version number from CONFIG 86 string Major( xstr( CFA_VERSION_MAJOR ) ), Minor( xstr( CFA_VERSION_MINOR ) ), Patch( xstr( CFA_VERSION_PATCH ) );93 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); 87 94 88 95 string installincdir( CFA_INCDIR ); // fixed location of include files … … 92 99 string heading; // banner printed at start of cfa compilation 93 100 string arg; // current command-line argument during command-line parsing 94 string bprefix; // path where gcc looks for compilersteps101 string Bprefix; // path where gcc looks for compiler command steps 95 102 string langstd; // language standard 96 103 … … 99 106 100 107 bool x_flag = false; // -x flag 101 bool nonoptarg = false; // no non-option arguments specified, i.e., no file names102 bool link = true; // link stage occurring108 bool nonoptarg = false; // indicates non-option argument specified 109 bool link = true; // linking as well as compiling 103 110 bool verbose = false; // -v flag 104 111 bool quiet = false; // -quiet flag … … 113 120 bool m32 = false; // -m32 flag 114 121 bool m64 = false; // -m64 flag 115 bool intree = false; // build in tree122 bool intree = false; 116 123 bool compiling_libs = false; 117 124 bool disttree = false; 118 int o_file = 0; // -o filename position119 125 120 126 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 140 146 141 147 if ( arg == "-Xlinker" || arg == "-o" ) { 142 args[nargs++] = argv[i]; // pass argument along 148 args[nargs] = argv[i]; // pass the argument along 149 nargs += 1; 143 150 i += 1; 144 151 if ( i == argc ) continue; // next argument available ? 145 args[nargs ++] = argv[i]; // passargument along146 if ( arg == "-o" ) o_file = i; // remember file152 args[nargs] = argv[i]; // pass the argument along 153 nargs += 1; 147 154 } else if ( arg == "-XCFA" ) { // CFA pass through 148 155 i += 1; 149 Putenv( argv, argv[i] ); 156 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str(); 157 nargs += 1; 150 158 151 159 // CFA specific arguments … … 154 162 CFA_flag = true; // strip the -CFA flag 155 163 link = false; 156 args[nargs++] = "-fsyntax-only"; // stop after stage 2 164 args[nargs] = "-E"; // replace the argument with -E 165 nargs += 1; 157 166 } else if ( arg == "-debug" ) { 158 167 debug = true; // strip the debug flag 159 168 } else if ( arg == "-nodebug" ) { 160 debug = false; // strip the nodebug flag169 debug = false; // strip the debug flag 161 170 } else if ( arg == "-nolib" ) { 162 171 nolib = true; // strip the nodebug flag … … 182 191 if ( i == argc ) continue; // next argument available ? 183 192 compiler_path = argv[i]; 184 Putenv( argv, arg + "=" + argv[i] ); 193 if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) { 194 cerr << argv[0] << " error, cannot set environment variable." << endl; 195 exit( EXIT_FAILURE ); 196 } // if 185 197 186 198 // C specific arguments … … 188 200 } else if ( arg == "-v" ) { 189 201 verbose = true; // verbosity required 190 args[nargs++] = argv[i]; // pass argument along 202 args[nargs] = argv[i]; // pass the argument along 203 nargs += 1; 191 204 } else if ( arg == "-g" ) { 192 205 debugging = true; // symbolic debugging required 193 args[nargs++] = argv[i]; // pass argument along 194 } else if ( arg == "-save-temps" ) { 195 args[nargs++] = argv[i]; // pass argument along 196 Putenv( argv, arg ); // save cfa-cpp output 206 args[nargs] = argv[i]; // pass the argument along 207 nargs += 1; 197 208 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 198 209 string lang; 199 args[nargs++] = argv[i]; // pass argument along 210 args[nargs] = argv[i]; // pass the argument along 211 nargs += 1; 200 212 if ( arg.length() == 2 ) { // separate argument ? 201 213 i += 1; 202 214 if ( i == argc ) continue; // next argument available ? 203 215 lang = argv[i]; 204 args[nargs++] = argv[i]; // pass argument along 216 args[nargs] = argv[i]; // pass the argument along 217 nargs += 1; 205 218 } else { 206 219 lang = arg.substr( 2 ); … … 209 222 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 210 223 std_flag = true; // -std=XX provided 211 args[nargs++] = argv[i]; // pass argument along 224 args[nargs] = argv[i]; // pass the argument along 225 nargs += 1; 212 226 } else if ( arg == "-w" ) { 213 args[nargs++] = argv[i]; // pass argument along 214 Putenv( argv, arg ); 227 args[nargs] = argv[i]; // pass the argument along 228 nargs += 1; 229 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 230 nargs += 1; 215 231 } else if ( prefix( arg, "-W" ) ) { // check before next tests 216 232 if ( arg == "-Werror" || arg == "-Wall" ) { 217 args[nargs++] = argv[i]; // pass argument along 218 Putenv( argv, argv[i] ); 233 args[nargs] = argv[i]; // pass the argument along 234 nargs += 1; 235 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 236 nargs += 1; 219 237 } else { 220 238 unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; 221 args[nargs] = argv[i]; // conditionally pass argument along222 const char * warning = argv[i] + adv; // extract warning239 args[nargs] = argv[i]; // conditionally pass the argument along 240 const char * warning = argv[i] + adv; // extract warning 223 241 if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp 224 Putenv( argv, arg);242 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); 225 243 } // if 226 244 nargs += 1; 227 245 } // if 228 246 } else if ( prefix( arg, "-B" ) ) { 229 bprefix = arg.substr(2); // strip the -B flag 247 Bprefix = arg.substr(2); // strip the -B flag 248 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 249 nargs += 1; 250 } else if ( prefix( arg, "-b" ) ) { 251 if ( arg.length() == 2 ) { // separate argument ? 252 i += 1; 253 if ( i == argc ) continue; // next argument available ? 254 arg += argv[i]; // concatenate argument 255 } // if 256 // later versions of gcc require the -b option to appear at the start of the command line 257 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 258 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 259 if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) { 260 cerr << argv[0] << " error, cannot set environment variable." << endl; 261 exit( EXIT_FAILURE ); 262 } // if 263 sargs += 1; 264 nargs += 1; 265 } else if ( prefix( arg, "-V" ) ) { 266 if ( arg.length() == 2 ) { // separate argument ? 267 i += 1; 268 if ( i == argc ) continue; // next argument available ? 269 arg += argv[i]; // concatenate argument 270 } // if 271 // later versions of gcc require the -V option to appear at the start of the command line 272 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 273 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 274 if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) { 275 cerr << argv[0] << " error, cannot set environment variable." << endl; 276 exit( EXIT_FAILURE ); 277 } // if 278 sargs += 1; 279 nargs += 1; 230 280 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 231 args[nargs++] = argv[i]; // pass argument along 281 args[nargs] = argv[i]; // pass the argument along 282 nargs += 1; 232 283 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 233 284 cpp_flag = true; // cpp only … … 236 287 } else if ( arg[1] == 'l' ) { 237 288 // if the user specifies a library, load it after user code 238 libs[nlibs++] = argv[i]; 289 libs[nlibs] = argv[i]; 290 nlibs += 1; 239 291 } else if ( arg == "-m32" ) { 240 292 m32 = true; 241 293 m64 = false; 242 args[nargs++] = argv[i]; 294 args[nargs] = argv[i]; 295 nargs += 1; 243 296 } else if ( arg == "-m64" ) { 244 297 m64 = true; 245 298 m32 = false; 246 args[nargs++] = argv[i]; 299 args[nargs] = argv[i]; 300 nargs += 1; 247 301 } else { 248 302 // concatenate any other arguments 249 args[nargs++] = argv[i]; 303 args[nargs] = argv[i]; 304 nargs += 1; 250 305 } // if 251 306 } else { 252 307 bool cfa = suffix( arg ); // check suffix 253 308 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 254 args[nargs++] = "-x"; 255 args[nargs++] = "c"; 309 args[nargs] = "-x"; 310 nargs += 1; 311 args[nargs] = "c"; 312 nargs += 1; 256 313 } // if 257 args[nargs++] = argv[i]; // concatenate files 314 args[nargs] = argv[i]; // concatenate file 315 nargs += 1; 258 316 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 259 args[nargs++] = "-x"; 260 args[nargs++] = "none"; 317 args[nargs] = "-x"; 318 nargs += 1; 319 args[nargs] = "none"; 320 nargs += 1; 261 321 } // if 262 322 nonoptarg = true; … … 265 325 266 326 #ifdef __x86_64__ 267 args[nargs++] = "-mcx16"; // allow double-wide CAA 327 args[nargs] = "-mcx16"; // allow double-wide CAA 328 nargs += 1; 268 329 #endif // __x86_64__ 269 330 … … 276 337 #endif // __DEBUG_H__ 277 338 278 // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed.279 339 if ( cpp_flag && CFA_flag ) { 280 340 cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; … … 283 343 284 344 // add the CFA include-library paths, which allow direct access to header files without directory qualification 285 if ( ! intree ) { 286 args[nargs++] = "-I" CFA_INCDIR; 345 if( !intree ) { 346 args[nargs] = "-I" CFA_INCDIR; 347 nargs += 1; 287 348 if ( ! noincstd_flag ) { // do not use during build 288 args[nargs++] = "-I" CFA_INCDIR "stdhdr"; 349 args[nargs] = "-I" CFA_INCDIR "stdhdr"; 350 nargs += 1; 289 351 } // if 290 args[nargs++] = "-I" CFA_INCDIR "concurrency"; 291 args[nargs++] = "-I" CFA_INCDIR "containers"; 352 args[nargs] = "-I" CFA_INCDIR "concurrency"; 353 nargs += 1; 354 args[nargs] = "-I" CFA_INCDIR "containers"; 355 nargs += 1; 292 356 } else { 293 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 357 args[nargs] = "-I" TOP_SRCDIR "libcfa/src"; 358 nargs += 1; 294 359 if ( ! noincstd_flag ) { // do not use during build 295 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 360 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 361 nargs += 1; 296 362 } // if 297 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 298 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 299 } // if 363 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 364 nargs += 1; 365 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 366 nargs += 1; 367 } 300 368 301 369 // add stdbool to get defines for bool/true/false 302 args[nargs++] = "-imacros"; 303 args[nargs++] = "stdbool.h"; 370 args[nargs] = "-imacros"; 371 nargs += 1; 372 args[nargs] = "stdbool.h"; 373 nargs += 1; 304 374 305 375 string libbase; 306 if ( !intree ) {376 if( !intree ) { 307 377 libbase = CFA_LIBDIR; 308 378 } else { 309 379 libbase = TOP_BUILDDIR "libcfa/"; 310 } // if380 } 311 381 312 382 if( compiling_libs ) { 313 Putenv( argv, "-t" ); 314 } // if 315 316 string arch( m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU) ); 383 args[nargs] = "-D__CFA_FLAG__=-t"; 384 nargs += 1; 385 } 386 387 string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU); 317 388 if ( ! m32 && ! m64 ) { 318 389 if ( arch == "x86" ) { 319 args[nargs++] = "-m32"; 390 args[nargs] = "-m32"; 391 nargs += 1; 320 392 } else if ( arch == "x64" ) { 321 args[nargs++] = "-m64"; 393 args[nargs] = "-m64"; 394 nargs += 1; 322 395 } // if 323 396 } // if 324 325 397 const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug"); 326 398 string libdir = libbase + arch + "-" + config; … … 345 417 346 418 if(disttree) { 347 Putenv( argv, "--prelude-dir=" + dir(argv[0])));419 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str(); 348 420 } else if(intree) { 349 Putenv( argv, "--prelude-dir=" + libdir + "/prelude"));421 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str(); 350 422 } else { 351 Putenv( argv, "--prelude-dir=" + libdir));423 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str(); 352 424 } 353 425 nargs += 1; 426 354 427 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries 355 args[nargs++] = libs[i]; 428 args[nargs] = libs[i]; 429 nargs += 1; 356 430 } // for 357 431 358 432 if ( link ) { 359 args[nargs++] = "-Xlinker"; 360 args[nargs++] = "--undefined=__cfaabi_dbg_bits_write"; 361 args[nargs++] = "-Xlinker"; 362 args[nargs++] = "--undefined=__cfaabi_interpose_startup"; 363 args[nargs++] = "-Xlinker"; 364 args[nargs++] = "--undefined=__cfaabi_appready_startup"; 365 366 // include the cfa library in case it is needed 367 args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 368 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 369 args[nargs++] = "-Wl,--push-state,--as-needed"; 370 args[nargs++] = "-lcfathread"; 371 args[nargs++] = "-Wl,--pop-state"; 372 args[nargs++] = "-lcfa"; 373 args[nargs++] = "-lpthread"; 374 args[nargs++] = "-ldl"; 375 args[nargs++] = "-lrt"; 376 args[nargs++] = "-lm"; 377 } // if 378 379 args[nargs++] = "-fexceptions"; // add exception flags (unconditionally) 380 381 // add flags based on the type of compile 382 383 args[nargs++] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); 384 args[nargs++] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); 385 args[nargs++] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); 386 args[nargs++] = "-D__CFA__"; 387 args[nargs++] = "-D__CFORALL__"; 388 args[nargs++] = "-D__cforall"; 433 args[nargs] = "-Xlinker"; 434 nargs += 1; 435 args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; 436 nargs += 1; 437 args[nargs] = "-Xlinker"; 438 nargs += 1; 439 args[nargs] = "--undefined=__cfaabi_interpose_startup"; 440 nargs += 1; 441 args[nargs] = "-Xlinker"; 442 nargs += 1; 443 args[nargs] = "--undefined=__cfaabi_appready_startup"; 444 nargs += 1; 445 446 // include the cfa library in case it's needed 447 args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 448 nargs += 1; 449 args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 450 nargs += 1; 451 args[nargs] = "-Wl,--push-state,--as-needed"; 452 nargs += 1; 453 args[nargs] = "-lcfathread"; 454 nargs += 1; 455 args[nargs] = "-Wl,--pop-state"; 456 nargs += 1; 457 args[nargs] = "-lcfa"; 458 nargs += 1; 459 args[nargs] = "-lpthread"; 460 nargs += 1; 461 args[nargs] = "-ldl"; 462 nargs += 1; 463 args[nargs] = "-lrt"; 464 nargs += 1; 465 args[nargs] = "-lm"; 466 nargs += 1; 467 } // if 468 469 // Add exception flags (unconditionally) 470 args[nargs] = "-fexceptions"; 471 nargs += 1; 472 473 // add the correct set of flags based on the type of compile this is 474 475 args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); 476 nargs += 1; 477 args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); 478 nargs += 1; 479 args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); 480 nargs += 1; 481 args[nargs] = "-D__CFA__"; 482 nargs += 1; 483 args[nargs] = "-D__CFORALL__"; 484 nargs += 1; 485 args[nargs] = "-D__cforall"; 486 nargs += 1; 389 487 390 488 if ( cpp_flag ) { 391 args[nargs++] = "-D__CPP__"; 392 } // if 393 489 args[nargs] = "-D__CPP__"; 490 nargs += 1; 491 } // if 492 493 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 494 nargs += 1; 394 495 if ( CFA_flag ) { 395 Putenv( argv, "-N" ); 396 Putenv( argv, "-CFA" ); 397 // -CFA implies cc1 stage 2, but gcc does not pass the -o file to this stage because it believe the file is for 398 // the linker. Hence, the -o file is explicit passed to cc1 stage 2 and used as cfa-cpp's output file. 399 if ( o_file ) Putenv( argv, string( "-o=" ) + argv[o_file] ); 496 args[sargs] = "-D__CFA_FLAG__=-N"; 497 args[nargs] = "-D__CFA_PREPROCESS_"; 498 nargs += 1; 400 499 } else { 401 Putenv( argv, "-L" ); 402 } // if 403 404 Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") ); 500 args[sargs] = "-D__CFA_FLAG__=-L"; 501 } // if 502 sargs += 1; 405 503 406 504 if ( debug ) { 407 505 heading += " (debug)"; 408 args[nargs++] = "-D__CFA_DEBUG__"; 506 args[nargs] = "-D__CFA_DEBUG__"; 507 nargs += 1; 409 508 } else { 410 509 heading += " (no debug)"; 411 510 } // if 412 511 413 if ( bprefix.length() == 0 ) {512 if ( Bprefix.length() == 0 ) { 414 513 if(disttree) { 415 bprefix = dir(argv[0]);514 Bprefix = dir(argv[0]); 416 515 } else if(intree) { 417 bprefix = srcdriverdir;516 Bprefix = srcdriverdir; 418 517 } else { 419 bprefix = installlibdir;518 Bprefix = installlibdir; 420 519 } 421 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 422 Putenv( argv, ( *new string( string("-B=") + bprefix ) ).c_str() ); 423 } // if 424 425 args[nargs++] = "-Xlinker"; // used by backtrace 426 args[nargs++] = "-export-dynamic"; 520 521 if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/'; 522 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 523 nargs += 1; 524 } // if 525 526 args[nargs] = "-Xlinker"; // used by backtrace 527 nargs += 1; 528 args[nargs] = "-export-dynamic"; 529 nargs += 1; 427 530 428 531 // execute the compilation command … … 438 541 439 542 if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name 440 args[nargs++] = "-no-integrated-cpp"; 441 args[nargs++] = "-Wno-deprecated"; 442 #ifdef HAVE_CAST_FUNCTION_TYPE 443 args[nargs++] = "-Wno-cast-function-type"; 444 #endif // HAVE_CAST_FUNCTION_TYPE 543 args[nargs] = "-no-integrated-cpp"; 544 nargs += 1; 545 args[nargs] = "-Wno-deprecated"; 546 nargs += 1; 547 #ifdef HAVE_CAST_FUNCTION_TYPE 548 args[nargs] = "-Wno-cast-function-type"; 549 nargs += 1; 550 #endif // HAVE_CAST_FUNCTION_TYPE 445 551 if ( ! std_flag ) { // default c11, if none specified 446 args[nargs++] = "-std=gnu11"; 552 args[nargs] = "-std=gnu11"; 553 nargs += 1; 447 554 } // if 448 args[nargs++] = "-fgnu89-inline"; 449 args[nargs++] = "-D__int8_t_defined"; // prevent gcc type-size attributes 450 args[nargs++] = ( *new string( string("-B") + bprefix ) ).c_str(); 555 args[nargs] = "-fgnu89-inline"; 556 nargs += 1; 557 args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes 558 nargs += 1; 559 args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str(); 560 nargs += 1; 451 561 } else { 452 562 cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl; … … 454 564 } // if 455 565 456 args[nargs] = nullptr; // terminate566 args[nargs] = NULL; // terminate with NULL 457 567 458 568 #ifdef __DEBUG_H__ 459 569 cerr << "nargs: " << nargs << endl; 460 570 cerr << "args:" << endl; 461 for ( int i = 0; args[i] != nullptr; i += 1 ) {462 cerr << " \"" << args[i] << "\" " << endl;571 for ( int i = 0; args[i] != NULL; i += 1 ) { 572 cerr << " \"" << args[i] << "\" "; 463 573 } // for 464 574 cerr << endl; … … 481 591 if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc 482 592 483 for ( int i = 0; args[i] != nullptr; i += 1 ) {593 for ( int i = 0; args[i] != NULL; i += 1 ) { 484 594 cerr << args[i] << " "; 485 595 } // for … … 495 605 496 606 execvp( args[0], (char *const *)args ); // should not return 497 perror( "CFA Translator error: execvp" );607 perror( "CFA Translator error: cfa level, execvp" ); 498 608 exit( EXIT_FAILURE ); 499 609 } // main -
src/ResolvExpr/Unify.cc
rc2051e10 r17bc05b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Wed Sep 4 10:00:00 201913 // Update Count : 4 411 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 43 14 14 // 15 15 … … 278 278 #endif 279 279 if ( ( common = commonType( type1, type2, widen.first, widen.second, indexer, env, openVars ) ) ) { 280 common-> tq = tq1.unify( tq2 );280 common->get_qualifiers() = tq1 | tq2; 281 281 #ifdef DEBUG 282 282 std::cerr << "unifyInexact: common type is "; … … 295 295 if ( ( tq1 > tq2 || widen.first ) && ( tq2 > tq1 || widen.second ) ) { 296 296 common = type1->clone(); 297 common-> tq = tq1.unify( tq2 );297 common->get_qualifiers() = tq1 | tq2; 298 298 result = true; 299 299 } else { … … 302 302 } else { 303 303 common = type1->clone(); 304 common-> tq = tq1.unify( tq2 );304 common->get_qualifiers() = tq1 | tq2; 305 305 result = true; 306 306 } // if -
src/SynTree/Expression.cc
rc2051e10 r17bc05b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hr Aug 15 13:43:00 201913 // Update Count : 6 412 // Last Modified On : Tue Aug 13 11:31:00 2019 13 // Update Count : 63 14 14 // 15 15 … … 646 646 result = new VoidType( Type::Qualifiers() ); 647 647 } 648 }649 bool StmtExpr::get_lvalue() const {650 return result->get_lvalue();651 648 } 652 649 void StmtExpr::print( std::ostream & os, Indenter indent ) const { -
src/SynTree/Expression.h
rc2051e10 r17bc05b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 15 13:46:00 201913 // Update Count : 5 412 // Last Modified On : Wed Aug 14 14:24:00 2019 13 // Update Count : 53 14 14 // 15 15 … … 777 777 virtual ~StmtExpr(); 778 778 779 bool get_lvalue() const final;780 781 779 CompoundStmt * get_statements() const { return statements; } 782 780 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } -
src/SynTree/Type.h
rc2051e10 r17bc05b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Sep 4 09:58:00201913 // Update Count : 1 7011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 14 17:11:24 2019 13 // Update Count : 169 14 14 // 15 15 … … 131 131 bool operator>( Qualifiers other ) const { return *this != other && *this >= other; } 132 132 BFCommon( Qualifiers, NumTypeQualifier ) 133 134 Qualifiers unify( Qualifiers const & other ) const {135 int or_flags = Mask & (val | other.val);136 int and_flags = val & other.val;137 return Qualifiers( or_flags | and_flags );138 }139 133 }; // Qualifiers 140 134 -
src/main.cc
rc2051e10 r17bc05b 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 23 06:50:08201913 // Update Count : 60 712 // Last Modified On : Wed Jun 5 20:35:13 2019 13 // Update Count : 601 14 14 // 15 15 … … 96 96 DeclarationNode * parseTree = nullptr; // program parse tree 97 97 98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start 99 99 100 100 static std::string PreludeDirector = ""; 101 101 102 static void parse_cmdline( int argc, char *argv[] );102 static void parse_cmdline( int argc, char *argv[], const char *& filename ); 103 103 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 104 104 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); … … 172 172 FILE * input; // use FILE rather than istream because yyin is FILE 173 173 ostream * output = & cout; 174 const char * filename = nullptr; 174 175 list< Declaration * > translationUnit; 175 176 … … 183 184 // } // for 184 185 185 parse_cmdline( argc, argv );// process command-line arguments186 parse_cmdline( argc, argv, filename ); // process command-line arguments 186 187 CodeGen::FixMain::setReplaceMain( !nomainp ); 187 188 188 if ( waiting_for_gdb) {189 if(waiting_for_gdb) { 189 190 std::cerr << "Waiting for gdb" << std::endl; 190 191 std::cerr << "run :" << std::endl; 191 192 std::cerr << " gdb attach " << getpid() << std::endl; 192 193 raise(SIGSTOP); 193 } // if194 } 194 195 195 196 try { … … 197 198 if ( optind < argc ) { // any commands after the flags ? => input file name 198 199 input = fopen( argv[ optind ], "r" ); 199 assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) ); 200 assertf( input, "cannot open %s\n", argv[ optind ] ); 201 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to) 202 if ( filename == nullptr ) filename = argv[ optind ]; 203 // prelude filename comes in differently 204 if ( libcfap ) filename = "prelude.cfa"; 200 205 optind += 1; 201 206 } else { // no input file name 202 207 input = stdin; 208 std::cerr << "Input from stdin" << std::endl; 209 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass 210 // a fake name along 211 if ( filename == nullptr ) filename = "stdin"; 203 212 } // if 204 213 … … 438 447 439 448 440 static const char optstring[] = ":hlLmNnpP:S:t wW:D:";449 static const char optstring[] = ":hlLmNnpP:S:tgwW:D:F:"; 441 450 442 451 enum { PreludeDir = 128 }; … … 457 466 { "", no_argument, nullptr, 0 }, // -W 458 467 { "", no_argument, nullptr, 0 }, // -D 468 { "", no_argument, nullptr, 0 }, // -F 459 469 { nullptr, 0, nullptr, 0 } 460 470 }; // long_opts … … 476 486 "", // -W 477 487 "", // -D 488 "", // -F 478 489 }; // description 479 490 … … 510 521 511 522 static void usage( char *argv[] ) { 512 cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], whereoptions are:" << endl;523 cout << "Usage: " << argv[0] << " options are:" << endl; 513 524 int i = 0, j = 1; // j skips starting colon 514 525 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { … … 536 547 } // usage 537 548 538 static void parse_cmdline( int argc, char * argv[] ) {549 static void parse_cmdline( int argc, char * argv[], const char *& filename ) { 539 550 opterr = 0; // (global) prevent getopt from printing error messages 540 551 … … 610 621 case 'D': // ignore -Dxxx, forwarded by cpp, hidden 611 622 break; 623 case 'F': // source file-name without suffix, hidden 624 filename = optarg; 625 break; 612 626 case '?': // unknown option 613 627 if ( optopt ) { // short option ? -
tests/pybin/tools.py
rc2051e10 r17bc05b 328 328 329 329 def core_archive(dst, name, exe): 330 # Get the core dump330 # Get the files to copy 331 331 core = os.path.join(os.getcwd(), "core" ) 332 332 333 # update the path for this test334 dst = os.path.join(dst, name)333 # Uncomment if we want timestamps on coredumps 334 # dst = os.path.join(dst, "%s_%s" % (name, pretty_now())) 335 335 336 336 # make a directory for this test 337 # mkdir makes the parent directory only so add a dummy338 337 mkdir(os.path.join(dst, "dir")) 339 338
Note:
See TracChangeset
for help on using the changeset viewer.