Index: src/AST/BasicKind.hpp
===================================================================
--- src/AST/BasicKind.hpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/AST/BasicKind.hpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -19,5 +19,5 @@
 
 // GENERATED START, DO NOT EDIT
-// GENERATED BY BasicTypes-gen.cc
+// GENERATED BY BasicTypes-gen.cpp
 enum BasicKind {
 	Bool,
Index: src/AST/Print.cpp
===================================================================
--- src/AST/Print.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/AST/Print.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -23,5 +23,5 @@
 #include "Type.hpp"
 #include "TypeSubstitution.hpp"
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 #include "Common/Iterate.hpp"
 
Index: src/AST/Type.cpp
===================================================================
--- src/AST/Type.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/AST/Type.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -50,5 +50,5 @@
 
 // GENERATED START, DO NOT EDIT
-// GENERATED BY BasicTypes-gen.cc
+// GENERATED BY BasicTypes-gen.cpp
 const char * BasicType::typeNames[] = {
 	"_Bool",
Index: src/AST/TypeEnvironment.cpp
===================================================================
--- src/AST/TypeEnvironment.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/AST/TypeEnvironment.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -34,5 +34,5 @@
 #include "ResolvExpr/Unify.h"      // for unifyInexact
 #include "Tuples/Tuples.h"         // for isTtype
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 
 using ResolvExpr::WidenMode;
Index: c/BasicTypes-gen.cc
===================================================================
--- src/BasicTypes-gen.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ 	(revision )
@@ -1,489 +1,0 @@
-#include <algorithm>
-#include <queue>
-#include <iostream>
-#include <iomanip>
-#include <fstream>
-#include <utility>
-#include <string>
-using namespace std;
-#include <assert.h>
-#include <string.h>										// strlen
-#include "config.h"									// configure info
-
-enum Kind {
-	Bool,
-	Char,
-	SignedChar,
-	UnsignedChar,
-	ShortSignedInt,
-	ShortUnsignedInt,
-	SignedInt,
-	UnsignedInt,
-	LongSignedInt,
-	LongUnsignedInt,
-	LongLongSignedInt,
-	LongLongUnsignedInt,
-	SignedInt128,
-	UnsignedInt128,
-	uFloat16,
-	uFloat16Complex,
-	uFloat32,
-	uFloat32Complex,
-	Float,
-	FloatComplex,
-	// FloatImaginary,
-	uFloat32x,
-	uFloat32xComplex,
-	uFloat64,
-	uFloat64Complex,
-	Double,
-	DoubleComplex,
-	// DoubleImaginary,
-	uFloat64x,
-	uFloat64xComplex,
-	uuFloat80,
-	uFloat128,
-	uFloat128Complex,
-	uuFloat128,
-	LongDouble,
-	LongDoubleComplex,
-	// LongDoubleImaginary,
-	uFloat128x,
-	uFloat128xComplex,
-	NUMBER_OF_BASIC_TYPES
-};
-
-enum NumSort {											// floating point types act as both signed and unsigned
-	Signed = 0x1,
-	Unsigned = 0x2,
-	Floating = 0x3
-};
-
-struct Node {
-	Kind basicType;										// basic type
-	const char * name;									// basic-type name
-	const char * abbrev;								// internal abbreviation (documentation only)
-	const char * type;									// actual type name
-	const char * mangled;								// mangled abbreviation
-	NumSort sign;										// is this a signed integral type?
-	int left, middle, right;							// 3-ary tree, -1 => nullptr
-	int rank;											// integral rank (C standard 6.3.1.1.1, extended)
-} graph[NUMBER_OF_BASIC_TYPES] = {
-	{ Bool, "Bool", "B", "_Bool", "b", Signed, Char, SignedChar, -1, 0 }, // root
-
-	{ Char, "Char", "C", "char", "c", Signed, SignedChar, UnsignedChar, ShortSignedInt, 1 },
-	{ SignedChar, "SignedChar", "SC", "signed char", "a", Signed, UnsignedChar, ShortSignedInt, -1, 1 },
-	{ UnsignedChar, "UnsignedChar", "UC", "unsigned char", "h", Unsigned, ShortUnsignedInt, ShortSignedInt, -1, 1 },
-
-	{ ShortSignedInt, "ShortSignedInt", "SI", "signed short int", "s", Signed, ShortUnsignedInt, SignedInt, -1, 2 },
-	{ ShortUnsignedInt, "ShortUnsignedInt", "SUI", "unsigned short int", "t", Unsigned, UnsignedInt, SignedInt, -1, 2 },
-
-	{ SignedInt, "SignedInt", "I", "signed int", "i", Signed, UnsignedInt, LongSignedInt, -1, 3 },
-	{ UnsignedInt, "UnsignedInt", "UI", "unsigned int", "j", Unsigned, LongUnsignedInt, LongSignedInt, -1, 3 },
-
-	{ LongSignedInt, "LongSignedInt", "LI", "signed long int", "l", Signed, LongUnsignedInt, LongLongSignedInt, -1, 4 },
-	{ LongUnsignedInt, "LongUnsignedInt", "LUI", "unsigned long int", "m", Unsigned, LongLongSignedInt, LongLongUnsignedInt, -1, 4 },
-
-	{ LongLongSignedInt, "LongLongSignedInt", "LLI", "signed long long int", "x", Signed, LongLongUnsignedInt, SignedInt128, -1, 5 },
-	{ LongLongUnsignedInt, "LongLongUnsignedInt", "LLUI", "unsigned long long int", "y", Unsigned, SignedInt128, UnsignedInt128, -1, 5 },
-
-	{ SignedInt128, "SignedInt128", "IB", "__int128", "n", Signed, UnsignedInt128, uFloat16, -1, 6 },
-	{ UnsignedInt128, "UnsignedInt128", "UIB", "unsigned __int128", "o", Unsigned, uFloat16, -1, -1, 6 },
-
-	{ uFloat16, "uFloat16", "_FH", "_Float16", "DF16_", Floating, uFloat32, uFloat16Complex, -1, 7 },
-	{ uFloat16Complex, "uFloat16Complex", "_FH", "_Float16 _Complex", "CDF16_", Floating, uFloat32Complex, -1, -1, 7 },
-	{ uFloat32, "uFloat32", "_F", "_Float32", "DF32_", Floating, Float, uFloat32Complex, -1, 8 },
-	{ uFloat32Complex, "uFloat32Complex", "_FC", "_Float32 _Complex", "CDF32_", Floating, FloatComplex, -1, -1, 8 },
-	{ Float, "Float", "F", "float", "f", Floating, uFloat32x, FloatComplex, -1, 9 },
-	{ FloatComplex, "FloatComplex", "FC", "float _Complex", "Cf", Floating, uFloat32xComplex, -1, -1, 9 },
-	// { FloatImaginary, "FloatImaginary", "FI", "float _Imaginary", "If", false, DoubleImaginary, FloatComplex, -1, 9 },
-
-	{ uFloat32x, "uFloat32x", "_FX", "_Float32x", "DF32x_", Floating, uFloat64, uFloat32xComplex, -1, 10 },
-	{ uFloat32xComplex, "uFloat32xComplex", "_FXC", "_Float32x _Complex", "CDF32x_", Floating, uFloat64Complex, -1, -1, 10 },
-	{ uFloat64, "uFloat64", "FD", "_Float64", "DF64_", Floating, Double, uFloat64Complex, -1, 11 },
-	{ uFloat64Complex, "uFloat64Complex", "_FDC", "_Float64 _Complex", "CDF64_", Floating, DoubleComplex, -1, -1, 11 },
-	{ Double, "Double", "D", "double", "d", Floating, uFloat64x, DoubleComplex, -1, 12 },
-	{ DoubleComplex, "DoubleComplex", "DC", "double _Complex", "Cd", Floating, uFloat64xComplex, -1, -1, 12 },
-	// { DoubleImaginary, "DoubleImaginary", "DI", "double _Imaginary", "Id", false, LongDoubleImaginary, DoubleComplex, -1, 12 },
-
-	{ uFloat64x, "uFloat64x", "F80X", "_Float64x", "DF64x_", Floating, uuFloat80, uFloat64xComplex, -1, 13 },
-	{ uFloat64xComplex, "uFloat64xComplex", "_FDXC", "_Float64x _Complex", "CDF64x_", Floating, uFloat128Complex, -1, -1, 13 },
-	{ uuFloat80, "uuFloat80", "F80", "__float80", "Dq", Floating, uFloat128, uFloat64xComplex, -1, 14 },
-	{ uFloat128, "uFloat128", "_FB", "_Float128", "DF128_", Floating, uuFloat128, uFloat128Complex, -1, 15 },
-	{ uFloat128Complex, "uFloat128Complex", "_FLDC", "_Float128 _Complex", "CDF128_", Floating, LongDoubleComplex, -1, -1, 15 },
-	{ uuFloat128, "uuFloat128", "FB", "__float128", "g", Floating, LongDouble, uFloat128Complex, -1, 16 },
-	{ LongDouble, "LongDouble", "LD", "long double", "e", Floating, uFloat128x, LongDoubleComplex, -1, 17 },
-	{ LongDoubleComplex, "LongDoubleComplex", "LDC", "long double _Complex", "Ce", Floating, uFloat128xComplex, -1, -1, 17 },
-	// { LongDoubleImaginary, "LongDoubleImaginary", "LDI", "long double _Imaginary", "Ie", false, LongDoubleComplex, -1, -1, 17 },
-
-	{ uFloat128x, "uFloat128x", "_FBX", "_Float128x", "DF128x_", Floating, uFloat128xComplex, -1, -1, 18 },
-	{ uFloat128xComplex, "uFloat128xComplex", "_FLDXC", "_Float128x _Complex", "CDF128x_", Floating, -1, -1, -1, 18 }
-}; // graph
-
-static int costMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
-static int signMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
-static Kind commonTypeMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
-
-void generateCosts( int row ) {
-	bool seen[NUMBER_OF_BASIC_TYPES] = { false /*, ... */ };
-
-	struct el_cost {
-		int i;
-		int path;
-		int sign;
-
-		el_cost( int i = 0, int p = 0, int s = 0 ) : i(i), path(p), sign(s) {}
-
-		// reverse the sense for use in largest-on-top priority queue
-		bool operator< (const el_cost& o) const {
-			return path > o.path || (path == o.path && sign > o.sign);
-		}
-	};
-
-	// initialize BFS queue with root of traversal
-	priority_queue< el_cost > q;
-	q.emplace( row, 0, 0 );
-
-	// BFS costs
-	do {
-		// visit cost element
-		int col = q.top().i;
-		// skip if already set
-		if ( seen[col] ) {
-			q.pop();
-			continue;
-		} else {
-			seen[col] = true;
-		} // if
-
-		// otherwise set min-costs into matrix
-		int cost = q.top().path;
-		int scost = q.top().sign;
-		costMatrix[row][col] = cost;
-		signMatrix[row][col] = scost;
-		q.pop();
-
-		// traverse children
-		int i = graph[col].left;
-		if ( i == -1 ) continue;
-		q.emplace( i, cost + 1, scost + ! (graph[col].sign & graph[i].sign) );
-
-		i = graph[col].middle;
-		if ( i == -1 ) continue;
-		q.emplace( i, cost + 1, scost + !(graph[col].sign & graph[i].sign) );
-
-		i = graph[col].right;
-		if ( i == -1 ) continue;
-		q.emplace( i, cost + 1, scost + !(graph[col].sign & graph[i].sign) );
-	} while ( ! q.empty() );
-} // generateCosts
-
-void generateCommonType( int row, int col ) {			// row <= col
-	if ( costMatrix[row][col] >= 0 ) {
-		// safe conversion from row => col
-		commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[col].basicType;
-	} else if ( costMatrix[col][row] >= 0 ) {
-		// safe conversion from col => row
-		commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[row].basicType;
-	} else {
-		// need to find least common ancestor
-		// can cheat a bit here, in that there is always a direct ancestor of the later (col) element
-		int i = graph[col].left;
-		if ( i == -1 ) assert("invalid ancestor assumption");
-		if ( costMatrix[row][i] >= 0 ) {
-			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
-			return;
-		} // if
-
-		i = graph[col].middle;
-		if ( i == -1 ) assert("invalid ancestor assumption");
-		if ( costMatrix[row][i] >= 0 ) {
-			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
-			return;
-		} // if
-
-		i = graph[col].right;
-		if ( i == -1 ) assert("invalid ancestor assumption");
-		if ( costMatrix[row][i] >= 0 ) {
-			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
-			return;
-		} // if
-
-		assert("invalid ancestor assumption");
-	} // if
-} // generateCommonType
-
-void resetInput( fstream & file, const char * filename, stringstream & buffer, stringstream & code, string & str ) {
-	file.close();
-	buffer.str( "" );
-	code.str( "" );
-	file.open( filename, fstream::in );
-	if ( file.fail() ) {
-		cout << "Internal error, could not open " << filename << " for input." << endl;
-		abort();
-	} // if
-	buffer << file.rdbuf();
-	str = buffer.str();
-} // resetInput
-
-void output( fstream & file, const char * filename, stringstream & code ) {
-	file.close();
-	file.open( filename, fstream::out );
-	if ( file.fail() ) {
-		cout << "Internal error, could not open " << filename << " for output." << endl;
-		abort();
-	} // if
-	file << code.rdbuf();								// overwrite file
-} // output
-
-void Abort( const char * kind, const char * file ) {
-	cerr << "Internal error, could not find " << kind << " of generated code for " << file << endl;
-} // Abort
-
-int main() {
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // initialization
-		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-			costMatrix[r][c] = -1;
-			signMatrix[r][c] = -1;
-			commonTypeMatrix[r][c] = NUMBER_OF_BASIC_TYPES;
-		} // for
-	} // for
-	int lastInteger = NUMBER_OF_BASIC_TYPES;
-
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // perform breath-first traversal to generate cost graph
-		generateCosts(r);
-	} // for
-
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // use cost graph to find nearest-common-ancestor
-		for (int c = r; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-			generateCommonType(r, c);
-		} // for
-	} // for
-
-	// Find the last integer type.
-	// Assumes at least 1, and all come before the floating types.
-	for ( int i = 1 ; i < NUMBER_OF_BASIC_TYPES ; i += 1 ) {
-		if ( Floating == graph[i].sign ) {
-			lastInteger = (i - 1);
-			break;
-		}
-	}
-
-	#define STARTMK "// GENERATED START, DO NOT EDIT"
-	#define ENDMK "// GENERATED END"
-	string BYMK( __FILE__ );
-	string::size_type posn = BYMK.find_last_of( "/" );
-	if ( posn != string::npos ) BYMK.erase( 0, posn - 1); // remove directories
-	BYMK = "// GENERATED BY " + BYMK;
-
-	fstream file;
-	stringstream buffer, code;
-	string str;
-	size_t start, end;
-
-	#define TypeH_AST TOP_SRCDIR "src/AST/BasicKind.hpp"
-	resetInput( file, TypeH_AST, buffer, code, str );
-
-	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH_AST );
-	start += sizeof( STARTMK );							// includes newline
-	code << str.substr( 0, start );
-
-	code << BYMK << endl;
-	code << "enum BasicKind {" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
-		code << "\t" << graph[r].name << "," << endl;
-	} // for
-	code << "\tNUMBER_OF_BASIC_TYPES," << endl;
-	code << "\tMAX_INTEGER_TYPE = " << graph[lastInteger].name << "," << endl;
-	code << "};" << endl;
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH_AST );
-	code << str.substr( start );
-
-	output( file, TypeH_AST, code );
-	// cout << code.str();
-
-
-	#define TypeC_AST TOP_SRCDIR "src/AST/Type.cpp"
-	resetInput( file, TypeC_AST, buffer, code, str );
-
-	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC_AST );
-	start += sizeof( STARTMK );							// includes newline
-	code << str.substr( 0, start );
-
-	code << BYMK << endl;
-	code << "const char * BasicType::typeNames[] = {" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
-		code << "\t\"" << graph[r].type << "\"," << endl;
-	} // for
-	code << "};" << endl;
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC_AST );
-	code << str.substr( start );
-
-	output( file, TypeC_AST, code );
-	// cout << code.str();
-
-
-	#define ConversionCost TOP_SRCDIR "src/ResolvExpr/ConversionCost.cc"
-	resetInput( file, ConversionCost, buffer, code, str );
-
-	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", ConversionCost );
-	start += sizeof( STARTMK );							// includes newline
-	code << str.substr( 0, start );
-
-	code << "\t" << BYMK << endl;
-	code << "\t/* EXTENDED INTEGRAL RANK HIERARCHY (root to leaves)" << endl;
-	for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-		code << '\t' << left;
-		if ( graph[c].rank != graph[c + 1].rank ) {
-			code << right << setw(30) << graph[c].type << left;
-		} else if ( graph[c].rank != graph[c + 2].rank ) {
-			code << string( 10, ' ' ) << setw(25) << graph[c].type << graph[c + 1].type;
-			c += 1;
-		} else {
-			code << setw(20) << graph[c].type << setw(20) << graph[c + 1].type << graph[c + 2].type;
-			c += 2;
-		} // if
-		code << endl;
-	} // for
-	code << right << "\t*/" << endl;
-	code << "\t";										// indentation for end marker
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
-	if ( (end = str.find( STARTMK, start + 1 )) == string::npos ) Abort( "start", ConversionCost );
-	end += sizeof( STARTMK );
-	code << str.substr( start, end - start );
-
-	code << "\t" << BYMK << endl;
-	code << "\tstatic const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node" << endl
-		 << "\t\t/*           ";
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
-		code << setw(5) << graph[r].abbrev;
-	} // for
-	code << " */" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
-		code << "\t\t/* " << setw(6) << graph[r].abbrev << " */ {";
-		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-			code << setw(4) << costMatrix[r][c] << ",";
-		} // for
-		code << " }," << endl;
-	} // for
-	code << "\t}; // costMatrix" << endl;
-
-	// maximum conversion cost from int
-	code << "\tstatic const int maxIntCost = " << *max_element(costMatrix[SignedInt], costMatrix[SignedInt] + NUMBER_OF_BASIC_TYPES) << ";" << endl;
-	code << "\t";										// indentation for end marker
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
-	if ( (end = str.find( STARTMK, start + 1 )) == string::npos ) Abort( "start", ConversionCost );
-	end += sizeof( STARTMK );
-	code << str.substr( start, end - start );
-
-	code << "\t" << BYMK << endl;
-	code << "\tstatic const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion" << endl
-		 << "\t\t/*           ";
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
-		code << setw(5) << graph[r].abbrev;
-	} // for
-	code << " */" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
-		code << "\t\t/* " << setw(6) << graph[r].abbrev << " */ {";
-		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-			code << setw(4) << signMatrix[r][c] << ",";
-		} // for
-		code << " }," << endl;
-	} // for
-	code << "\t}; // signMatrix" << endl;
-	code << "\t";										// indentation for end marker
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
-	code << str.substr( start );
-
-	output( file, ConversionCost, code );
-	// cout << code.str();
-
-
-	#define CommonType TOP_SRCDIR "src/ResolvExpr/CommonType.cc"
-	resetInput( file, CommonType, buffer, code, str );
-
-	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", CommonType );
-	start += sizeof( STARTMK );							// includes newline
-	code << str.substr( 0, start );
-
-	enum { PER_ROW = 6 };
-	code << "\t" << BYMK << endl;
-	code << "\t#define BT ast::BasicKind::" << endl;
-	code << "\tstatic const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor" << endl
-	     << "\t\t/*\t\t ";
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
-		code << setw(24) << graph[r].abbrev;
-		if ( (r+1) % PER_ROW == 0 ) {
-			code << endl << "\t\t\t\t ";
-		} // if
-	} // for
-	code << "*/" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
-		code << "\t\t\t\t  {\n\t\t/* " << setw(6) << graph[r].abbrev << " */";
-		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
-			string s = string{"BT "} + graph[commonTypeMatrix[r][c]].name;
-			code << setw(23) << s << ",";
-			if ( (c+1) % PER_ROW == 0 ) {
-				code << endl << "\t\t\t\t  ";
-			} // if
-		} // for
-		code << "}," << endl;
-	} // for
-	code << "\t}; // commonTypes" << endl;
-	code << "\t#undef BT" << endl;
-	code << "\t";										// indentation for end marker
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", CommonType );
-	code << str.substr( start );
-
-	output( file, CommonType, code );
-	// cout << code.str();
-
-
-	#define ManglerCommon TOP_SRCDIR "src/SymTab/ManglerCommon.cc"
-	resetInput( file, ManglerCommon, buffer, code, str );
-
-	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", ManglerCommon );
-	start += sizeof( STARTMK );							// includes newline
-	code << str.substr( 0, start );
-
-	code <<
-		"// GENERATED BY " __FILE__ "\n"
-		"// NOTES ON MANGLING:\n"
-		"// * Itanium spec says that Float80 encodes to \"e\" (like LongDouble), but the distinct lengths cause resolution problems.\n"
-		"// * Float128 is supposed to encode to \"g\", but I wanted it to mangle equal to LongDouble.\n"
-		"// * Mangling for non-standard complex types is by best guess\n"
-		"// * _FloatN is supposed to encode as \"DF\"N\"_\"; modified for same reason as above.\n"
-		"// * unused mangling identifiers:\n"
-		"//   - \"z\" ellipsis\n"
-		"//   - \"Dd\" IEEE 754r 64-bit decimal floating point (borrowed for _Float32x)\n"
-		"//   - \"De\" IEEE 754r 128-bit decimal floating point\n"
-		"//   - \"Df\" IEEE 754r 32-bit decimal floating point\n"
-		"//   - \"Dh\" IEEE 754r 16-bit decimal floating point (borrowed for _Float16)\n"
-		"//   - \"DF\"N\"_\" ISO/IEC TS 18661 N-bit binary floating point (_FloatN)\n"
-		"//   - \"Di\" char32_t\n"
-		"//   - \"Ds\" char16_t\n";
-
-	code << "const std::string basicTypes[ast::BasicKind::NUMBER_OF_BASIC_TYPES] = {" << endl;
-	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
-		code << "\t\"" << graph[r].mangled << "\"," << setw(9 - strlen(graph[r].mangled)) << ' ' << "// " << graph[r].type << endl;
-	} // for
-	code << "}; // basicTypes" << endl;
-
-	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ManglerCommon );
-	code << str.substr( start );
-
-	output( file, ManglerCommon, code );
-	// cout << code.str();
-} // main
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "g++-8 -Wall -Wextra BasicTypes-gen.cc" //
-// End: //
Index: src/BasicTypes-gen.cpp
===================================================================
--- src/BasicTypes-gen.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
+++ src/BasicTypes-gen.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -0,0 +1,489 @@
+#include <algorithm>
+#include <queue>
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <utility>
+#include <string>
+using namespace std;
+#include <assert.h>
+#include <string.h>										// strlen
+#include "config.h"									// configure info
+
+enum Kind {
+	Bool,
+	Char,
+	SignedChar,
+	UnsignedChar,
+	ShortSignedInt,
+	ShortUnsignedInt,
+	SignedInt,
+	UnsignedInt,
+	LongSignedInt,
+	LongUnsignedInt,
+	LongLongSignedInt,
+	LongLongUnsignedInt,
+	SignedInt128,
+	UnsignedInt128,
+	uFloat16,
+	uFloat16Complex,
+	uFloat32,
+	uFloat32Complex,
+	Float,
+	FloatComplex,
+	// FloatImaginary,
+	uFloat32x,
+	uFloat32xComplex,
+	uFloat64,
+	uFloat64Complex,
+	Double,
+	DoubleComplex,
+	// DoubleImaginary,
+	uFloat64x,
+	uFloat64xComplex,
+	uuFloat80,
+	uFloat128,
+	uFloat128Complex,
+	uuFloat128,
+	LongDouble,
+	LongDoubleComplex,
+	// LongDoubleImaginary,
+	uFloat128x,
+	uFloat128xComplex,
+	NUMBER_OF_BASIC_TYPES
+};
+
+enum NumSort {											// floating point types act as both signed and unsigned
+	Signed = 0x1,
+	Unsigned = 0x2,
+	Floating = 0x3
+};
+
+struct Node {
+	Kind basicType;										// basic type
+	const char * name;									// basic-type name
+	const char * abbrev;								// internal abbreviation (documentation only)
+	const char * type;									// actual type name
+	const char * mangled;								// mangled abbreviation
+	NumSort sign;										// is this a signed integral type?
+	int left, middle, right;							// 3-ary tree, -1 => nullptr
+	int rank;											// integral rank (C standard 6.3.1.1.1, extended)
+} graph[NUMBER_OF_BASIC_TYPES] = {
+	{ Bool, "Bool", "B", "_Bool", "b", Signed, Char, SignedChar, -1, 0 }, // root
+
+	{ Char, "Char", "C", "char", "c", Signed, SignedChar, UnsignedChar, ShortSignedInt, 1 },
+	{ SignedChar, "SignedChar", "SC", "signed char", "a", Signed, UnsignedChar, ShortSignedInt, -1, 1 },
+	{ UnsignedChar, "UnsignedChar", "UC", "unsigned char", "h", Unsigned, ShortUnsignedInt, ShortSignedInt, -1, 1 },
+
+	{ ShortSignedInt, "ShortSignedInt", "SI", "signed short int", "s", Signed, ShortUnsignedInt, SignedInt, -1, 2 },
+	{ ShortUnsignedInt, "ShortUnsignedInt", "SUI", "unsigned short int", "t", Unsigned, UnsignedInt, SignedInt, -1, 2 },
+
+	{ SignedInt, "SignedInt", "I", "signed int", "i", Signed, UnsignedInt, LongSignedInt, -1, 3 },
+	{ UnsignedInt, "UnsignedInt", "UI", "unsigned int", "j", Unsigned, LongUnsignedInt, LongSignedInt, -1, 3 },
+
+	{ LongSignedInt, "LongSignedInt", "LI", "signed long int", "l", Signed, LongUnsignedInt, LongLongSignedInt, -1, 4 },
+	{ LongUnsignedInt, "LongUnsignedInt", "LUI", "unsigned long int", "m", Unsigned, LongLongSignedInt, LongLongUnsignedInt, -1, 4 },
+
+	{ LongLongSignedInt, "LongLongSignedInt", "LLI", "signed long long int", "x", Signed, LongLongUnsignedInt, SignedInt128, -1, 5 },
+	{ LongLongUnsignedInt, "LongLongUnsignedInt", "LLUI", "unsigned long long int", "y", Unsigned, SignedInt128, UnsignedInt128, -1, 5 },
+
+	{ SignedInt128, "SignedInt128", "IB", "__int128", "n", Signed, UnsignedInt128, uFloat16, -1, 6 },
+	{ UnsignedInt128, "UnsignedInt128", "UIB", "unsigned __int128", "o", Unsigned, uFloat16, -1, -1, 6 },
+
+	{ uFloat16, "uFloat16", "_FH", "_Float16", "DF16_", Floating, uFloat32, uFloat16Complex, -1, 7 },
+	{ uFloat16Complex, "uFloat16Complex", "_FH", "_Float16 _Complex", "CDF16_", Floating, uFloat32Complex, -1, -1, 7 },
+	{ uFloat32, "uFloat32", "_F", "_Float32", "DF32_", Floating, Float, uFloat32Complex, -1, 8 },
+	{ uFloat32Complex, "uFloat32Complex", "_FC", "_Float32 _Complex", "CDF32_", Floating, FloatComplex, -1, -1, 8 },
+	{ Float, "Float", "F", "float", "f", Floating, uFloat32x, FloatComplex, -1, 9 },
+	{ FloatComplex, "FloatComplex", "FC", "float _Complex", "Cf", Floating, uFloat32xComplex, -1, -1, 9 },
+	// { FloatImaginary, "FloatImaginary", "FI", "float _Imaginary", "If", false, DoubleImaginary, FloatComplex, -1, 9 },
+
+	{ uFloat32x, "uFloat32x", "_FX", "_Float32x", "DF32x_", Floating, uFloat64, uFloat32xComplex, -1, 10 },
+	{ uFloat32xComplex, "uFloat32xComplex", "_FXC", "_Float32x _Complex", "CDF32x_", Floating, uFloat64Complex, -1, -1, 10 },
+	{ uFloat64, "uFloat64", "FD", "_Float64", "DF64_", Floating, Double, uFloat64Complex, -1, 11 },
+	{ uFloat64Complex, "uFloat64Complex", "_FDC", "_Float64 _Complex", "CDF64_", Floating, DoubleComplex, -1, -1, 11 },
+	{ Double, "Double", "D", "double", "d", Floating, uFloat64x, DoubleComplex, -1, 12 },
+	{ DoubleComplex, "DoubleComplex", "DC", "double _Complex", "Cd", Floating, uFloat64xComplex, -1, -1, 12 },
+	// { DoubleImaginary, "DoubleImaginary", "DI", "double _Imaginary", "Id", false, LongDoubleImaginary, DoubleComplex, -1, 12 },
+
+	{ uFloat64x, "uFloat64x", "F80X", "_Float64x", "DF64x_", Floating, uuFloat80, uFloat64xComplex, -1, 13 },
+	{ uFloat64xComplex, "uFloat64xComplex", "_FDXC", "_Float64x _Complex", "CDF64x_", Floating, uFloat128Complex, -1, -1, 13 },
+	{ uuFloat80, "uuFloat80", "F80", "__float80", "Dq", Floating, uFloat128, uFloat64xComplex, -1, 14 },
+	{ uFloat128, "uFloat128", "_FB", "_Float128", "DF128_", Floating, uuFloat128, uFloat128Complex, -1, 15 },
+	{ uFloat128Complex, "uFloat128Complex", "_FLDC", "_Float128 _Complex", "CDF128_", Floating, LongDoubleComplex, -1, -1, 15 },
+	{ uuFloat128, "uuFloat128", "FB", "__float128", "g", Floating, LongDouble, uFloat128Complex, -1, 16 },
+	{ LongDouble, "LongDouble", "LD", "long double", "e", Floating, uFloat128x, LongDoubleComplex, -1, 17 },
+	{ LongDoubleComplex, "LongDoubleComplex", "LDC", "long double _Complex", "Ce", Floating, uFloat128xComplex, -1, -1, 17 },
+	// { LongDoubleImaginary, "LongDoubleImaginary", "LDI", "long double _Imaginary", "Ie", false, LongDoubleComplex, -1, -1, 17 },
+
+	{ uFloat128x, "uFloat128x", "_FBX", "_Float128x", "DF128x_", Floating, uFloat128xComplex, -1, -1, 18 },
+	{ uFloat128xComplex, "uFloat128xComplex", "_FLDXC", "_Float128x _Complex", "CDF128x_", Floating, -1, -1, -1, 18 }
+}; // graph
+
+static int costMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
+static int signMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
+static Kind commonTypeMatrix[NUMBER_OF_BASIC_TYPES][NUMBER_OF_BASIC_TYPES];
+
+void generateCosts( int row ) {
+	bool seen[NUMBER_OF_BASIC_TYPES] = { false /*, ... */ };
+
+	struct el_cost {
+		int i;
+		int path;
+		int sign;
+
+		el_cost( int i = 0, int p = 0, int s = 0 ) : i(i), path(p), sign(s) {}
+
+		// reverse the sense for use in largest-on-top priority queue
+		bool operator< (const el_cost& o) const {
+			return path > o.path || (path == o.path && sign > o.sign);
+		}
+	};
+
+	// initialize BFS queue with root of traversal
+	priority_queue< el_cost > q;
+	q.emplace( row, 0, 0 );
+
+	// BFS costs
+	do {
+		// visit cost element
+		int col = q.top().i;
+		// skip if already set
+		if ( seen[col] ) {
+			q.pop();
+			continue;
+		} else {
+			seen[col] = true;
+		} // if
+
+		// otherwise set min-costs into matrix
+		int cost = q.top().path;
+		int scost = q.top().sign;
+		costMatrix[row][col] = cost;
+		signMatrix[row][col] = scost;
+		q.pop();
+
+		// traverse children
+		int i = graph[col].left;
+		if ( i == -1 ) continue;
+		q.emplace( i, cost + 1, scost + ! (graph[col].sign & graph[i].sign) );
+
+		i = graph[col].middle;
+		if ( i == -1 ) continue;
+		q.emplace( i, cost + 1, scost + !(graph[col].sign & graph[i].sign) );
+
+		i = graph[col].right;
+		if ( i == -1 ) continue;
+		q.emplace( i, cost + 1, scost + !(graph[col].sign & graph[i].sign) );
+	} while ( ! q.empty() );
+} // generateCosts
+
+void generateCommonType( int row, int col ) {			// row <= col
+	if ( costMatrix[row][col] >= 0 ) {
+		// safe conversion from row => col
+		commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[col].basicType;
+	} else if ( costMatrix[col][row] >= 0 ) {
+		// safe conversion from col => row
+		commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[row].basicType;
+	} else {
+		// need to find least common ancestor
+		// can cheat a bit here, in that there is always a direct ancestor of the later (col) element
+		int i = graph[col].left;
+		if ( i == -1 ) assert("invalid ancestor assumption");
+		if ( costMatrix[row][i] >= 0 ) {
+			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
+			return;
+		} // if
+
+		i = graph[col].middle;
+		if ( i == -1 ) assert("invalid ancestor assumption");
+		if ( costMatrix[row][i] >= 0 ) {
+			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
+			return;
+		} // if
+
+		i = graph[col].right;
+		if ( i == -1 ) assert("invalid ancestor assumption");
+		if ( costMatrix[row][i] >= 0 ) {
+			commonTypeMatrix[row][col] = commonTypeMatrix[col][row] = graph[i].basicType;
+			return;
+		} // if
+
+		assert("invalid ancestor assumption");
+	} // if
+} // generateCommonType
+
+void resetInput( fstream & file, const char * filename, stringstream & buffer, stringstream & code, string & str ) {
+	file.close();
+	buffer.str( "" );
+	code.str( "" );
+	file.open( filename, fstream::in );
+	if ( file.fail() ) {
+		cout << "Internal error, could not open " << filename << " for input." << endl;
+		abort();
+	} // if
+	buffer << file.rdbuf();
+	str = buffer.str();
+} // resetInput
+
+void output( fstream & file, const char * filename, stringstream & code ) {
+	file.close();
+	file.open( filename, fstream::out );
+	if ( file.fail() ) {
+		cout << "Internal error, could not open " << filename << " for output." << endl;
+		abort();
+	} // if
+	file << code.rdbuf();								// overwrite file
+} // output
+
+void Abort( const char * kind, const char * file ) {
+	cerr << "Internal error, could not find " << kind << " of generated code for " << file << endl;
+} // Abort
+
+int main() {
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // initialization
+		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+			costMatrix[r][c] = -1;
+			signMatrix[r][c] = -1;
+			commonTypeMatrix[r][c] = NUMBER_OF_BASIC_TYPES;
+		} // for
+	} // for
+	int lastInteger = NUMBER_OF_BASIC_TYPES;
+
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // perform breath-first traversal to generate cost graph
+		generateCosts(r);
+	} // for
+
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // use cost graph to find nearest-common-ancestor
+		for (int c = r; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+			generateCommonType(r, c);
+		} // for
+	} // for
+
+	// Find the last integer type.
+	// Assumes at least 1, and all come before the floating types.
+	for ( int i = 1 ; i < NUMBER_OF_BASIC_TYPES ; i += 1 ) {
+		if ( Floating == graph[i].sign ) {
+			lastInteger = (i - 1);
+			break;
+		}
+	}
+
+	#define STARTMK "// GENERATED START, DO NOT EDIT"
+	#define ENDMK "// GENERATED END"
+	string BYMK( __FILE__ );
+	string::size_type posn = BYMK.find_last_of( "/" );
+	if ( posn != string::npos ) BYMK.erase( 0, posn - 1); // remove directories
+	BYMK = "// GENERATED BY " + BYMK;
+
+	fstream file;
+	stringstream buffer, code;
+	string str;
+	size_t start, end;
+
+	#define TypeH_AST TOP_SRCDIR "src/AST/BasicKind.hpp"
+	resetInput( file, TypeH_AST, buffer, code, str );
+
+	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH_AST );
+	start += sizeof( STARTMK );							// includes newline
+	code << str.substr( 0, start );
+
+	code << BYMK << endl;
+	code << "enum BasicKind {" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
+		code << "\t" << graph[r].name << "," << endl;
+	} // for
+	code << "\tNUMBER_OF_BASIC_TYPES," << endl;
+	code << "\tMAX_INTEGER_TYPE = " << graph[lastInteger].name << "," << endl;
+	code << "};" << endl;
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH_AST );
+	code << str.substr( start );
+
+	output( file, TypeH_AST, code );
+	// cout << code.str();
+
+
+	#define TypeC_AST TOP_SRCDIR "src/AST/Type.cpp"
+	resetInput( file, TypeC_AST, buffer, code, str );
+
+	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC_AST );
+	start += sizeof( STARTMK );							// includes newline
+	code << str.substr( 0, start );
+
+	code << BYMK << endl;
+	code << "const char * BasicType::typeNames[] = {" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
+		code << "\t\"" << graph[r].type << "\"," << endl;
+	} // for
+	code << "};" << endl;
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC_AST );
+	code << str.substr( start );
+
+	output( file, TypeC_AST, code );
+	// cout << code.str();
+
+
+	#define ConversionCost TOP_SRCDIR "src/ResolvExpr/ConversionCost.cc"
+	resetInput( file, ConversionCost, buffer, code, str );
+
+	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", ConversionCost );
+	start += sizeof( STARTMK );							// includes newline
+	code << str.substr( 0, start );
+
+	code << "\t" << BYMK << endl;
+	code << "\t/* EXTENDED INTEGRAL RANK HIERARCHY (root to leaves)" << endl;
+	for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+		code << '\t' << left;
+		if ( graph[c].rank != graph[c + 1].rank ) {
+			code << right << setw(30) << graph[c].type << left;
+		} else if ( graph[c].rank != graph[c + 2].rank ) {
+			code << string( 10, ' ' ) << setw(25) << graph[c].type << graph[c + 1].type;
+			c += 1;
+		} else {
+			code << setw(20) << graph[c].type << setw(20) << graph[c + 1].type << graph[c + 2].type;
+			c += 2;
+		} // if
+		code << endl;
+	} // for
+	code << right << "\t*/" << endl;
+	code << "\t";										// indentation for end marker
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
+	if ( (end = str.find( STARTMK, start + 1 )) == string::npos ) Abort( "start", ConversionCost );
+	end += sizeof( STARTMK );
+	code << str.substr( start, end - start );
+
+	code << "\t" << BYMK << endl;
+	code << "\tstatic const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node" << endl
+		 << "\t\t/*           ";
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
+		code << setw(5) << graph[r].abbrev;
+	} // for
+	code << " */" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
+		code << "\t\t/* " << setw(6) << graph[r].abbrev << " */ {";
+		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+			code << setw(4) << costMatrix[r][c] << ",";
+		} // for
+		code << " }," << endl;
+	} // for
+	code << "\t}; // costMatrix" << endl;
+
+	// maximum conversion cost from int
+	code << "\tstatic const int maxIntCost = " << *max_element(costMatrix[SignedInt], costMatrix[SignedInt] + NUMBER_OF_BASIC_TYPES) << ";" << endl;
+	code << "\t";										// indentation for end marker
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
+	if ( (end = str.find( STARTMK, start + 1 )) == string::npos ) Abort( "start", ConversionCost );
+	end += sizeof( STARTMK );
+	code << str.substr( start, end - start );
+
+	code << "\t" << BYMK << endl;
+	code << "\tstatic const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion" << endl
+		 << "\t\t/*           ";
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
+		code << setw(5) << graph[r].abbrev;
+	} // for
+	code << " */" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
+		code << "\t\t/* " << setw(6) << graph[r].abbrev << " */ {";
+		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+			code << setw(4) << signMatrix[r][c] << ",";
+		} // for
+		code << " }," << endl;
+	} // for
+	code << "\t}; // signMatrix" << endl;
+	code << "\t";										// indentation for end marker
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ConversionCost );
+	code << str.substr( start );
+
+	output( file, ConversionCost, code );
+	// cout << code.str();
+
+
+	#define CommonType TOP_SRCDIR "src/ResolvExpr/CommonType.cc"
+	resetInput( file, CommonType, buffer, code, str );
+
+	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", CommonType );
+	start += sizeof( STARTMK );							// includes newline
+	code << str.substr( 0, start );
+
+	enum { PER_ROW = 6 };
+	code << "\t" << BYMK << endl;
+	code << "\t#define BT ast::BasicKind::" << endl;
+	code << "\tstatic const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor" << endl
+	     << "\t\t/*\t\t ";
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // titles
+		code << setw(24) << graph[r].abbrev;
+		if ( (r+1) % PER_ROW == 0 ) {
+			code << endl << "\t\t\t\t ";
+		} // if
+	} // for
+	code << "*/" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { // costs
+		code << "\t\t\t\t  {\n\t\t/* " << setw(6) << graph[r].abbrev << " */";
+		for ( int c = 0; c < NUMBER_OF_BASIC_TYPES; c += 1 ) {
+			string s = string{"BT "} + graph[commonTypeMatrix[r][c]].name;
+			code << setw(23) << s << ",";
+			if ( (c+1) % PER_ROW == 0 ) {
+				code << endl << "\t\t\t\t  ";
+			} // if
+		} // for
+		code << "}," << endl;
+	} // for
+	code << "\t}; // commonTypes" << endl;
+	code << "\t#undef BT" << endl;
+	code << "\t";										// indentation for end marker
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", CommonType );
+	code << str.substr( start );
+
+	output( file, CommonType, code );
+	// cout << code.str();
+
+
+	#define ManglerCommon TOP_SRCDIR "src/SymTab/ManglerCommon.cc"
+	resetInput( file, ManglerCommon, buffer, code, str );
+
+	if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", ManglerCommon );
+	start += sizeof( STARTMK );							// includes newline
+	code << str.substr( 0, start );
+
+	code <<
+		"// GENERATED BY " __FILE__ "\n"
+		"// NOTES ON MANGLING:\n"
+		"// * Itanium spec says that Float80 encodes to \"e\" (like LongDouble), but the distinct lengths cause resolution problems.\n"
+		"// * Float128 is supposed to encode to \"g\", but I wanted it to mangle equal to LongDouble.\n"
+		"// * Mangling for non-standard complex types is by best guess\n"
+		"// * _FloatN is supposed to encode as \"DF\"N\"_\"; modified for same reason as above.\n"
+		"// * unused mangling identifiers:\n"
+		"//   - \"z\" ellipsis\n"
+		"//   - \"Dd\" IEEE 754r 64-bit decimal floating point (borrowed for _Float32x)\n"
+		"//   - \"De\" IEEE 754r 128-bit decimal floating point\n"
+		"//   - \"Df\" IEEE 754r 32-bit decimal floating point\n"
+		"//   - \"Dh\" IEEE 754r 16-bit decimal floating point (borrowed for _Float16)\n"
+		"//   - \"DF\"N\"_\" ISO/IEC TS 18661 N-bit binary floating point (_FloatN)\n"
+		"//   - \"Di\" char32_t\n"
+		"//   - \"Ds\" char16_t\n";
+
+	code << "const std::string basicTypes[ast::BasicKind::NUMBER_OF_BASIC_TYPES] = {" << endl;
+	for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) {
+		code << "\t\"" << graph[r].mangled << "\"," << setw(9 - strlen(graph[r].mangled)) << ' ' << "// " << graph[r].type << endl;
+	} // for
+	code << "}; // basicTypes" << endl;
+
+	if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", ManglerCommon );
+	code << str.substr( start );
+
+	output( file, ManglerCommon, code );
+	// cout << code.str();
+} // main
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "g++-8 -Wall -Wextra BasicTypes-gen.cpp" //
+// End: //
Index: src/CodeGen/FixNames.cc
===================================================================
--- src/CodeGen/FixNames.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/CodeGen/FixNames.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -25,5 +25,5 @@
 #include "FixMain.h"               // for FixMain
 #include "SymTab/Mangler.h"        // for Mangler
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 
 namespace CodeGen {
Index: c/CompilationState.cc
===================================================================
--- src/CompilationState.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ 	(revision )
@@ -1,52 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// CompilationState.cc --
-//
-// Author           : Rob Schluntz
-// Created On       : Mon Ju1 30 10:47:01 2018
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Apr 10 19:12:50 2023
-// Update Count     : 6
-//
-
-#include "config.h"
-
-int
-	astp = false,
-	bresolvep = false,
-	bboxp = false,
-	bcodegenp = false,
-	ctorinitp = false,
-	declstatsp = false,
-	exdeclp = false,
-	exprp = false,
-	expraltp = false,
-	genericsp = false,
-	invariant = false,
-	libcfap = false,
-	nopreludep = false,
-	genproto = false,
-	deterministic_output = false,
-	useNewAST = true,
-	nomainp = false,
-	resolvep = false,
-	resolvprotop = false,
-	symtabp = false,
-	treep = false,
-	tuplep = false,
-	validp = false,
-	errorp = false,
-	codegenp = false,
-	prettycodegenp = false,
-	linemarks = false,
-	reppseu = false;
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End:  //
Index: src/CompilationState.cpp
===================================================================
--- src/CompilationState.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
+++ src/CompilationState.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -0,0 +1,52 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// CompilationState.cc --
+//
+// Author           : Rob Schluntz
+// Created On       : Mon Ju1 30 10:47:01 2018
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Mon Apr 10 19:12:50 2023
+// Update Count     : 6
+//
+
+#include "config.h"
+
+int
+	astp = false,
+	bresolvep = false,
+	bboxp = false,
+	bcodegenp = false,
+	ctorinitp = false,
+	declstatsp = false,
+	exdeclp = false,
+	exprp = false,
+	expraltp = false,
+	genericsp = false,
+	invariant = false,
+	libcfap = false,
+	nopreludep = false,
+	genproto = false,
+	deterministic_output = false,
+	useNewAST = true,
+	nomainp = false,
+	resolvep = false,
+	resolvprotop = false,
+	symtabp = false,
+	treep = false,
+	tuplep = false,
+	validp = false,
+	errorp = false,
+	codegenp = false,
+	prettycodegenp = false,
+	linemarks = false,
+	reppseu = false;
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End:  //
Index: c/CompilationState.h
===================================================================
--- src/CompilationState.h	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ 	(revision )
@@ -1,56 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// CompilationState.h --
-//
-// Author           : Rob Schluntz
-// Created On       : Mon Ju1 30 10:47:01 2018
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Apr 10 19:12:53 2023
-// Update Count     : 6
-//
-
-extern int yydebug;                   // set for -g flag (Grammar)
-extern int
-	astp,
-	bresolvep,
-	bboxp,
-	bcodegenp,
-	ctorinitp,
-	declstatsp,
-	exdeclp,
-	exprp,
-	expraltp,
-	genericsp,
-	invariant,
-	libcfap,
-	nopreludep,
-	genproto,
-	deterministic_output,
-	useNewAST,
-	nomainp,
-	resolvep,
-	resolvprotop,
-	symtabp,
-	treep,
-	tuplep,
-	validp,
-	errorp,
-	codegenp,
-	prettycodegenp,
-	linemarks,
-	reppseu;
-
-// is the compiler building prelude or libcfa?
-inline bool buildingLibrary() {
-	return libcfap | treep;
-}
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End:  //
Index: src/CompilationState.hpp
===================================================================
--- src/CompilationState.hpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
+++ src/CompilationState.hpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -0,0 +1,56 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// CompilationState.h --
+//
+// Author           : Rob Schluntz
+// Created On       : Mon Ju1 30 10:47:01 2018
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Mon Apr 10 19:12:53 2023
+// Update Count     : 6
+//
+
+extern int yydebug;                   // set for -g flag (Grammar)
+extern int
+	astp,
+	bresolvep,
+	bboxp,
+	bcodegenp,
+	ctorinitp,
+	declstatsp,
+	exdeclp,
+	exprp,
+	expraltp,
+	genericsp,
+	invariant,
+	libcfap,
+	nopreludep,
+	genproto,
+	deterministic_output,
+	useNewAST,
+	nomainp,
+	resolvep,
+	resolvprotop,
+	symtabp,
+	treep,
+	tuplep,
+	validp,
+	errorp,
+	codegenp,
+	prettycodegenp,
+	linemarks,
+	reppseu;
+
+// is the compiler building prelude or libcfa?
+inline bool buildingLibrary() {
+	return libcfap | treep;
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End:  //
Index: src/InitTweak/GenInit.cc
===================================================================
--- src/InitTweak/GenInit.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/InitTweak/GenInit.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -27,5 +27,5 @@
 #include "AST/Node.hpp"
 #include "AST/Stmt.hpp"
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 #include "CodeGen/OperatorTable.h"
 #include "Common/SemanticError.h"      // for SemanticError
Index: src/MakeLibCfa.cpp
===================================================================
--- src/MakeLibCfa.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/MakeLibCfa.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -14,5 +14,5 @@
 //
 
-#include "MakeLibCfa.h"
+#include "MakeLibCfa.hpp"
 
 #include "AST/Copy.hpp"
Index: c/MakeLibCfa.h
===================================================================
--- src/MakeLibCfa.h	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ 	(revision )
@@ -1,33 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// MakeLibCfa.h --
-//
-// Author           : Richard C. Bilson
-// Created On       : Sat May 16 10:42:14 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:31:35 2017
-// Update Count     : 2
-//
-
-#pragma once
-
-#include <list>  // for list
-
-class Declaration;
-namespace ast {
-	class TranslationUnit;
-}
-
-namespace LibCfa {
-	void makeLibCfa( ast::TranslationUnit & translationUnit );
-} // namespace LibCfa
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/MakeLibCfa.hpp
===================================================================
--- src/MakeLibCfa.hpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
+++ src/MakeLibCfa.hpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -0,0 +1,33 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// MakeLibCfa.h --
+//
+// Author           : Richard C. Bilson
+// Created On       : Sat May 16 10:42:14 2015
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 09:31:35 2017
+// Update Count     : 2
+//
+
+#pragma once
+
+#include <list>  // for list
+
+class Declaration;
+namespace ast {
+	class TranslationUnit;
+}
+
+namespace LibCfa {
+	void makeLibCfa( ast::TranslationUnit & translationUnit );
+} // namespace LibCfa
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/Makefile.am	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -19,11 +19,11 @@
 ACLOCAL_AMFLAGS  = -I automake
 
-SRC = main.cc \
-	CompilationState.cc \
-	CompilationState.h \
+SRC = main.cpp \
+	CompilationState.cpp \
+	CompilationState.hpp \
 	MakeLibCfa.cpp \
-	MakeLibCfa.h
+	MakeLibCfa.hpp
 
-SRCDEMANGLE = CompilationState.cc
+SRCDEMANGLE = CompilationState.cpp
 
 MAINTAINERCLEANFILES =
@@ -55,5 +55,5 @@
 $(addprefix $(srcdir)/, ResolvExpr/ConversionCost.cc ResolvExpr/CommonType.cc SymTab/ManglerCommon.cc) : $(srcdir)/AST/BasicKind.hpp
 
-$(srcdir)/AST/BasicKind.hpp : BasicTypes-gen.cc
+$(srcdir)/AST/BasicKind.hpp : BasicTypes-gen.cpp
 	${AM_V_GEN}${CXXCOMPILE} $< -o BasicTypes-gen -Wall -Wextra -Werror=return-type
 	@./BasicTypes-gen
Index: src/ResolvExpr/CandidateFinder.cpp
===================================================================
--- src/ResolvExpr/CandidateFinder.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/ResolvExpr/CandidateFinder.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -26,5 +26,5 @@
 #include "Candidate.hpp"
 #include "CastCost.hpp"           // for castCost
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 #include "ConversionCost.h"       // for conversionCast
 #include "Cost.h"
Index: src/ResolvExpr/CommonType.cc
===================================================================
--- src/ResolvExpr/CommonType.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/ResolvExpr/CommonType.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -39,5 +39,5 @@
 
 	// GENERATED START, DO NOT EDIT
-	// GENERATED BY BasicTypes-gen.cc
+	// GENERATED BY BasicTypes-gen.cpp
 	#define BT ast::BasicKind::
 	static const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor
Index: src/ResolvExpr/ConversionCost.cc
===================================================================
--- src/ResolvExpr/ConversionCost.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/ResolvExpr/ConversionCost.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -35,5 +35,5 @@
 
 	// GENERATED START, DO NOT EDIT
-	// GENERATED BY BasicTypes-gen.cc
+	// GENERATED BY BasicTypes-gen.cpp
 	/* EXTENDED INTEGRAL RANK HIERARCHY (root to leaves)
 	                         _Bool
@@ -60,5 +60,5 @@
 
 	// GENERATED START, DO NOT EDIT
-	// GENERATED BY BasicTypes-gen.cc
+	// GENERATED BY BasicTypes-gen.cpp
 	static const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node
 		/*               B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
@@ -108,5 +108,5 @@
 
 	// GENERATED START, DO NOT EDIT
-	// GENERATED BY BasicTypes-gen.cc
+	// GENERATED BY BasicTypes-gen.cpp
 	static const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion
 		/*               B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
Index: src/ResolvExpr/Resolver.cc
===================================================================
--- src/ResolvExpr/Resolver.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/ResolvExpr/Resolver.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -28,5 +28,5 @@
 #include "typeops.h"                     // for extractResultType
 #include "Unify.h"                       // for unify
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 #include "AST/Decl.hpp"
 #include "AST/Init.hpp"
Index: src/SymTab/ManglerCommon.cc
===================================================================
--- src/SymTab/ManglerCommon.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/SymTab/ManglerCommon.cc	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -26,5 +26,5 @@
 
 // GENERATED START, DO NOT EDIT
-// GENERATED BY BasicTypes-gen.cc
+// GENERATED BY BasicTypes-gen.cpp
 // NOTES ON MANGLING:
 // * Itanium spec says that Float80 encodes to "e" (like LongDouble), but the distinct lengths cause resolution problems.
Index: src/Validate/Autogen.cpp
===================================================================
--- src/Validate/Autogen.cpp	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ src/Validate/Autogen.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -42,5 +42,5 @@
 #include "SymTab/GenImplicitCall.hpp"  // for genImplicitCall
 #include "SymTab/Mangler.h"        // for Mangler
-#include "CompilationState.h"
+#include "CompilationState.hpp"
 
 namespace Validate {
Index: c/main.cc
===================================================================
--- src/main.cc	(revision 195d1d89c805c47fc486b2b8cf91431ffa3d0689)
+++ 	(revision )
@@ -1,713 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// main.cc --
-//
-// Author           : Peter Buhr and Rob Schluntz
-// Created On       : Fri May 15 23:12:02 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Nov  1 21:12:58 2023
-// Update Count     : 690
-//
-
-#include <cxxabi.h>                         // for __cxa_demangle
-#include <execinfo.h>                       // for backtrace, backtrace_symbols
-#include <getopt.h>                         // for no_argument, optind, geto...
-#include <cassert>                          // for assertf
-#include <cstdio>                           // for fopen, FILE, fclose, stdin
-#include <cstdlib>                          // for exit, free, abort, EXIT_F...
-#include <csignal>                          // for signal, SIGABRT, SIGSEGV
-#include <cstring>                          // for index
-#include <fstream>                          // for ofstream
-#include <iostream>                         // for operator<<, basic_ostream
-#include <iomanip>
-#include <iterator>                         // for back_inserter
-#include <list>                             // for list
-#include <string>                           // for char_traits, operator<<
-
-#include "AST/Pass.hpp"                     // for pass_visitor_stats
-#include "AST/Print.hpp"                    // for printAll
-#include "AST/TranslationUnit.hpp"          // for TranslationUnit
-#include "AST/Util.hpp"                     // for checkInvariants
-#include "CompilationState.h"
-#include "../config.h"                      // for CFA_LIBDIR
-#include "CodeGen/FixMain.h"                // for FixMain
-#include "CodeGen/FixNames.h"               // for fixNames
-#include "CodeGen/Generate.h"               // for generate
-#include "CodeGen/LinkOnce.h"               // for translateLinkOnce
-#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
-#include "Common/DeclStats.hpp"             // for printDeclStats
-#include "Common/ResolvProtoDump.hpp"       // for dumpAsResolverProto
-#include "Common/Stats.h"                   // for Stats
-#include "Common/utility.h"                 // for deleteAll, filter, printAll
-#include "Concurrency/Actors.hpp"           // for implementActors
-#include "Concurrency/Corun.hpp"            // for implementCorun
-#include "Concurrency/Keywords.h"           // for implementMutex, implement...
-#include "Concurrency/Waitfor.h"            // for generateWaitfor
-#include "Concurrency/Waituntil.hpp"        // for generateWaitUntil
-#include "ControlStruct/ExceptDecl.h"       // for translateExcept
-#include "ControlStruct/ExceptTranslate.h"  // for translateThrows, translat...
-#include "ControlStruct/FixLabels.hpp"      // for fixLabels
-#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
-#include "GenPoly/Box.h"                    // for box
-#include "GenPoly/InstantiateGeneric.h"     // for instantiateGeneric
-#include "GenPoly/Lvalue.h"                 // for convertLvalue
-#include "GenPoly/Specialize.h"             // for convertSpecializations
-#include "InitTweak/FixInit.h"              // for fix
-#include "InitTweak/GenInit.h"              // for genInit
-#include "MakeLibCfa.h"                     // for makeLibCfa
-#include "Parser/RunParser.hpp"             // for buildList, dumpParseTree,...
-#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
-#include "ResolvExpr/EraseWith.hpp"         // for eraseWith
-#include "ResolvExpr/Resolver.h"            // for resolve
-#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
-#include "Validate/Autogen.hpp"             // for autogenerateRoutines
-#include "Validate/ImplementEnumFunc.hpp"   // for implementEnumFunc
-#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
-#include "Validate/EliminateTypedef.hpp"    // for eliminateTypedef
-#include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers
-#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
-#include "Validate/FixQualifiedTypes.hpp"   // for fixQualifiedTypes
-#include "Validate/FixReturnTypes.hpp"      // for fixReturnTypes
-#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
-#include "Validate/GenericParameter.hpp"    // for fillGenericParameters, tr...
-#include "Validate/HoistStruct.hpp"         // for hoistStruct
-#include "Validate/HoistTypeDecls.hpp"      // for hoistTypeDecls
-#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
-#include "Validate/LabelAddressFixer.hpp"   // for fixLabelAddresses
-#include "Validate/LinkInstanceTypes.hpp"   // for linkInstanceTypes
-#include "Validate/ReplaceTypedef.hpp"      // for replaceTypedef
-#include "Validate/ReturnCheck.hpp"         // for checkReturnStatements
-#include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign
-#include "Validate/ReplacePseudoFunc.hpp"   // for replacePseudoFunc
-#include "Virtual/ExpandCasts.h"            // for expandCasts
-#include "Virtual/VirtualDtor.hpp"          // for implementVirtDtors
-
-using namespace std;
-
-static void NewPass( const char * const name ) {
-	Stats::Heap::newPass( name );
-	using namespace Stats::Counters;
-	{
-		static auto group = build<CounterGroup>( "Pass Visitor Template" );
-		auto pass = build<CounterGroup>( name, group );
-		ast::pass_visitor_stats.depth = 0;
-		ast::pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass );
-		ast::pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass );
-	}
-}
-
-#define PASS( name, pass, unit, ... )       \
-	if ( errorp ) { cerr << name << endl; } \
-	NewPass(name);                          \
-	Stats::Time::StartBlock(name);          \
-	pass(unit,##__VA_ARGS__);               \
-	Stats::Time::StopBlock();               \
-	if ( invariant ) {                      \
-		ast::checkInvariants(unit);         \
-	}
-
-#define DUMP( cond, unit )                  \
-	if ( cond ) {                           \
-		dump(unit);                         \
-		return EXIT_SUCCESS;                \
-	}
-
-static bool waiting_for_gdb = false;					// flag to set cfa-cpp to wait for gdb on start
-
-static string PreludeDirector = "";
-
-static void parse_cmdline( int argc, char * argv[] );
-static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
-
-static void backtrace( int start ) {					// skip first N stack frames
-	enum { Frames = 50, };								// maximum number of stack frames
-	void * array[Frames];
-	size_t size = ::backtrace( array, Frames );
-	char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
-
-	*index( messages[0], '(' ) = '\0';					// find executable name
-	cerr << "Stack back trace for: " << messages[0] << endl;
-
-	// skip last 2 stack frames after main
-	for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
-		char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
-
-		for ( char * p = messages[i]; *p; p += 1 ) {	// find parantheses and +offset
-			if ( *p == '(' ) {
-				mangled_name = p;
-			} else if ( *p == '+' ) {
-				offset_begin = p;
-			} else if ( *p == ')' ) {
-				offset_end = p;
-				break;
-			} // if
-		} // for
-
-		// if line contains symbol, attempt to demangle
-		int frameNo = i - start;
-		if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
-			*mangled_name++ = '\0';						// delimit strings
-			*offset_begin++ = '\0';
-			*offset_end++ = '\0';
-
-			int status;
-			char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
-			// bug in __cxa_demangle for single-character lower-case non-mangled names
-			if ( status == 0 ) {						// demangling successful ?
-				cerr << "(" << frameNo << ") " << messages[i] << " : "
-					 << real_name << "+" << offset_begin << offset_end << endl;
-			} else {									// otherwise, output mangled name
-				cerr << "(" << frameNo << ") " << messages[i] << " : "
-					 << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl;
-			} // if
-
-			free( real_name );
-		} else {										// otherwise, print the whole line
-			cerr << "(" << frameNo << ") " << messages[i] << endl;
-		} // if
-	} // for
-
-	free( messages );
-} // backtrace
-
-#define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused ))
-
-static void _Signal(struct sigaction & act, int sig, int flags ) {
-	sigemptyset( &act.sa_mask );
-	act.sa_flags = flags;
-
-	if ( sigaction( sig, &act, nullptr ) == -1 ) {
-	    cerr << "*cfa-cpp compilation error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl;
-	    _exit( EXIT_FAILURE );
-	} // if
-}
-
-static void Signal( int sig, void (* handler)(SIGPARMS), int flags ) {
-	struct sigaction act;
-	act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
-	_Signal(act, sig, flags);
-} // Signal
-
-static void Signal( int sig, void (* handler)(int), int flags ) {
-	struct sigaction act;
-	act.sa_handler = handler;
-	_Signal(act, sig, flags);
-} // Signal
-
-static void sigSegvBusHandler( SIGPARMS ) {
-	if ( sfp->si_addr == nullptr ) {
-		cerr << "Null pointer (nullptr) dereference." << endl;
-	} else {
-		cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl
-			 << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl;
-	} // if
-	backtrace( 2 );										// skip first 2 stack frames
-	abort();											// cause core dump for debugging
-} // sigSegvBusHandler
-
-static void sigFpeHandler( SIGPARMS ) {
-	const char * msg;
-
-	switch ( sfp->si_code ) {
-	  case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break;
-	  case FPE_FLTOVF: msg = "overflow"; break;
-	  case FPE_FLTUND: msg = "underflow"; break;
-	  case FPE_FLTRES: msg = "inexact result"; break;
-	  case FPE_FLTINV: msg = "invalid operation"; break;
-	  default: msg = "unknown";
-	} // choose
-	cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl
-		 << "Possible cause is constant-expression evaluation invalid." << endl;
-	backtrace( 2 );										// skip first 2 stack frames
-	abort();											// cause core dump for debugging
-} // sigFpeHandler
-
-static void sigAbortHandler( SIGPARMS ) {
-	backtrace( 6 );										// skip first 6 stack frames
-	Signal( SIGABRT, SIG_DFL, SA_SIGINFO );	// reset default signal handler
-	raise( SIGABRT );									// reraise SIGABRT
-} // sigAbortHandler
-
-int main( int argc, char * argv[] ) {
-	FILE * input;										// use FILE rather than istream because yyin is FILE
-	ostream * output = & cout;
-	ast::TranslationUnit transUnit;
-
-	Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
-	Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO );
-	Signal( SIGFPE, sigFpeHandler, SA_SIGINFO );
-	Signal( SIGABRT, sigAbortHandler, SA_SIGINFO );
-
-	// cout << "main" << endl;
-	// for ( int i = 0; i < argc; i += 1 ) {
-	// 	cout << '\t' << argv[i] << endl;
-	// } // for
-
-	parse_cmdline( argc, argv );						// process command-line arguments
-
-	if ( waiting_for_gdb ) {
-		cerr << "Waiting for gdb" << endl;
-		cerr << "run :" << endl;
-		cerr << "  gdb attach " << getpid() << endl;
-		raise(SIGSTOP);
-	} // if
-
-	try {
-		// choose to read the program from a file or stdin
-		if ( optind < argc ) {							// any commands after the flags ? => input file name
-			input = fopen( argv[ optind ], "r" );
-			assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
-			optind += 1;
-		} else {										// no input file name
-			input = stdin;
-		} // if
-
-		Stats::Time::StartGlobal();
-		NewPass("Parse");
-		Stats::Time::StartBlock("Parse");
-
-		// read in the builtins, extras, and the prelude
-		if ( ! nopreludep ) {							// include gcc builtins
-			// -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
-
-			assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." );
-
-			// Read to gcc builtins, if not generating the cfa library
-			FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cfa").c_str(), "r" );
-			assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
-			parse( gcc_builtins, ast::Linkage::Compiler );
-
-			// read the extra prelude in, if not generating the cfa library
-			FILE * extras = fopen( (PreludeDirector + "/extras.cfa").c_str(), "r" );
-			assertf( extras, "cannot open extras.cf\n" );
-			parse( extras, ast::Linkage::BuiltinC );
-			if ( ! libcfap ) {
-				// read the prelude in, if not generating the cfa library
-				FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" );
-				assertf( prelude, "cannot open prelude.cfa\n" );
-				parse( prelude, ast::Linkage::Intrinsic );
-
-				// Read to cfa builtins, if not generating the cfa library
-				FILE * builtins = fopen( (PreludeDirector + "/builtins.cfa").c_str(), "r" );
-				assertf( builtins, "cannot open builtins.cf\n" );
-				parse( builtins, ast::Linkage::BuiltinCFA );
-			} // if
-		} // if
-
-		parse( input, libcfap ? ast::Linkage::Intrinsic : ast::Linkage::Cforall, yydebug );
-
-		transUnit = buildUnit();
-
-		DUMP( astp, std::move( transUnit ) );
-
-		Stats::Time::StopBlock();
-
-		PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit );
-
-		PASS( "Translate Exception Declarations", ControlStruct::translateExcept, transUnit );
-		DUMP( exdeclp, std::move( transUnit ) );
-		PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign, transUnit );
-		PASS( "Replace Typedefs", Validate::replaceTypedef, transUnit );
-		PASS( "Fix Return Types", Validate::fixReturnTypes, transUnit );
-		PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers, transUnit );
-
-		PASS( "Link Instance Types", Validate::linkInstanceTypes, transUnit );
-
-		PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit );
-		PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit );
-
-		PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit );
-		PASS( "Hoist Struct", Validate::hoistStruct, transUnit );
-		PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit );
-		PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit );
-		// Need to happen before fixing returns because implementEnumFunc has ReturnStmt
-		
-		PASS( "Generate Enum Attributes Functions", Validate::implementEnumFunc, transUnit );
-		PASS( "Check Function Returns", Validate::checkReturnStatements, transUnit );
-		PASS( "Fix Return Statements", InitTweak::fixReturnStatements, transUnit );
-		PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit );
-		PASS( "Fix Unique Ids", Validate::fixUniqueIds, transUnit );
-		PASS( "Implement Corun", Concurrency::implementCorun, transUnit );
-		PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit );
-
-		PASS( "Generate Autogen Routines", Validate::autogenerateRoutines, transUnit );
-		
-		PASS( "Implement Actors", Concurrency::implementActors, transUnit );
-		PASS( "Implement Virtual Destructors", Virtual::implementVirtDtors, transUnit );
-		PASS( "Implement Mutex", Concurrency::implementMutex, transUnit );
-		PASS( "Implement Thread Start", Concurrency::implementThreadStarter, transUnit );
-		PASS( "Compound Literal", Validate::handleCompoundLiterals, transUnit );
-		PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit );
-		PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit );
-		PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );
-
-		if ( symtabp ) {
-			return EXIT_SUCCESS;
-		} // if
-
-		if ( expraltp ) {
-			ResolvExpr::printCandidates( transUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		DUMP( validp, std::move( transUnit ) );
-
-		PASS( "Translate Throws", ControlStruct::translateThrows, transUnit );
-		PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );
-		PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit  );
-		PASS( "Fix Names", CodeGen::fixNames, transUnit );
-		PASS( "Gen Init", InitTweak::genInit, transUnit );
-		PASS( "Expand Member Tuples" , Tuples::expandMemberTuples, transUnit );
-
-		if ( libcfap ) {
-			// Generate the bodies of cfa library functions.
-			LibCfa::makeLibCfa( transUnit );
-		} // if
-
-		if ( declstatsp ) {
-			printDeclStats( transUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		DUMP( bresolvep, std::move( transUnit ) );
-
-		if ( resolvprotop ) {
-			dumpAsResolverProto( transUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		PASS( "Resolve", ResolvExpr::resolve, transUnit );
-		DUMP( exprp, std::move( transUnit ) );
-		PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit );
-		PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); // Here
-		PASS( "Erase With", ResolvExpr::eraseWith, transUnit );
-
-		// fix ObjectDecl - replaces ConstructorInit nodes
-		DUMP( ctorinitp, std::move( transUnit ) );
-
-		// Currently not working due to unresolved issues with UniqueExpr
-		PASS( "Expand Unique Expr", Tuples::expandUniqueExpr, transUnit ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
-
-		PASS( "Translate Tries", ControlStruct::translateTries, transUnit );
-		PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit );
-		PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );
-
-		// Needs to happen before tuple types are expanded.
-		PASS( "Convert Specializations",  GenPoly::convertSpecializations, transUnit );
-
-		PASS( "Expand Tuples", Tuples::expandTuples, transUnit );
-		DUMP( tuplep, std::move( transUnit ) );
-
-		// Must come after Translate Tries.
-		PASS( "Virtual Expand Casts", Virtual::expandCasts, transUnit );
-
-		PASS( "Instantiate Generics", GenPoly::instantiateGeneric, transUnit );
-		DUMP( genericsp, std::move( transUnit ) );
-
-		PASS( "Convert L-Value", GenPoly::convertLvalue, transUnit );
-		DUMP( bboxp, std::move( transUnit ) );
-		PASS( "Box", GenPoly::box, transUnit );
-		PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit );
-
-		// Code has been lowered to C, now we can start generation.
-
-		DUMP( bcodegenp, std::move( transUnit ) );
-
-		if ( optind < argc ) {							// any commands after the flags and input file ? => output file name
-			output = new ofstream( argv[ optind ] );
-		} // if
-
-		PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false );
-		CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
-
-		if ( output != &cout ) {
-			delete output;
-		} // if
-	} catch ( SemanticErrorException & e ) {
-		if ( errorp ) {
-			cerr << "---AST at error:---" << endl;
-			dump( std::move( transUnit ), cerr );
-			cerr << endl << "---End of AST, begin error message:---\n" << endl;
-		} // if
-		e.print();
-		if ( output != &cout ) {
-			delete output;
-		} // if
-		return EXIT_FAILURE;
-	} catch ( std::bad_alloc & ) {
-		cerr << "*cfa-cpp compilation error* std::bad_alloc" << endl;
-		backtrace( 1 );
-		abort();
-	} catch ( ... ) {
-		exception_ptr eptr = current_exception();
-		try {
-			if (eptr) {
-				rethrow_exception(eptr);
-			} else {
-				cerr << "*cfa-cpp compilation error* exception uncaught and unknown" << endl;
-			} // if
-		} catch( const exception & e ) {
-			cerr << "*cfa-cpp compilation error* uncaught exception \"" << e.what() << "\"\n";
-		} // try
-		return EXIT_FAILURE;
-	} // try
-
-	Stats::print();
-	return EXIT_SUCCESS;
-} // main
-
-
-static const char optstring[] = ":c:ghilLmNnpdP:S:twW:D:";
-
-enum { PreludeDir = 128 };
-static struct option long_opts[] = {
-	{ "colors", required_argument, nullptr, 'c' },
-	{ "gdb", no_argument, nullptr, 'g' },
-	{ "help", no_argument, nullptr, 'h' },
-	{ "invariant", no_argument, nullptr, 'i' },
-	{ "libcfa", no_argument, nullptr, 'l' },
-	{ "linemarks", no_argument, nullptr, 'L' },
-	{ "no-main", no_argument, nullptr, 'm' },
-	{ "no-linemarks", no_argument, nullptr, 'N' },
-	{ "no-prelude", no_argument, nullptr, 'n' },
-	{ "prototypes", no_argument, nullptr, 'p' },
-	{ "deterministic-out", no_argument, nullptr, 'd' },
-	{ "print", required_argument, nullptr, 'P' },
-	{ "prelude-dir", required_argument, nullptr, PreludeDir },
-	{ "statistics", required_argument, nullptr, 'S' },
-	{ "tree", no_argument, nullptr, 't' },
-	{ "", no_argument, nullptr, 0 },					// -w
-	{ "", no_argument, nullptr, 0 },					// -W
-	{ "", no_argument, nullptr, 0 },					// -D
-	{ nullptr, 0, nullptr, 0 }
-}; // long_opts
-
-static const char * description[] = {
-	"diagnostic color: never, always, auto",			// -c
-	"wait for gdb to attach",							// -g
-	"print translator help message",					// -h
-	"invariant checking during AST passes",				// -i
-	"generate libcfa.c",								// -l
-	"generate line marks",								// -L
-	"do not replace main",								// -m
-	"do not generate line marks",						// -N
-	"do not read prelude",								// -n
-	"do not generate prelude prototypes => prelude not printed", // -p
-	"only print deterministic output",                  // -d
-	"print",											// -P
-	"<directory> prelude directory for debug/nodebug",	// no flag
-	"<option-list> enable profiling information: counters, heap, time, all, none", // -S
-	"building cfa standard lib",						// -t
-	"",													// -w
-	"",													// -W
-	"",													// -D
-}; // description
-
-static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" );
-
-static struct Printopts {
-	const char * name;
-	int & flag;
-	int val;
-	const char * descript;
-} printopts[] = {
-	{ "ascodegen", codegenp, true, "print AST as codegen rather than AST" },
-	{ "asterr", errorp, true, "print AST on error" },
-	{ "declstats", declstatsp, true, "print code property statistics" },
-	{ "parse", yydebug, true, "print yacc (parsing) debug information" },
-	{ "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" },
-	{ "rproto", resolvprotop, true, "resolver-proto instance" },
-	{ "rsteps", resolvep, true, "print resolver steps" },
-	// AST dumps
-	{ "ast", astp, true, "print AST after parsing" },
-	{ "excpdecl", exdeclp, true, "print AST after translating exception decls" },
-	{ "symevt", symtabp, true, "print AST after symbol table events" },
-	{ "expralt", expraltp, true, "print AST after expressions alternatives" },
-	{ "valdecl", validp, true, "print AST after declaration validation pass" },
-	{ "bresolver", bresolvep, true, "print AST before resolver step" },
-	{ "expranly", exprp, true, "print AST after expression analysis" },
-	{ "ctordtor", ctorinitp, true, "print AST after ctor/dtor are replaced" },
-	{ "tuple", tuplep, true, "print AST after tuple expansion" },
-	{ "instgen", genericsp, true, "print AST after instantiate generics" },
-	{ "bbox", bboxp, true, "print AST before box pass" },
-	{ "bcodegen", bcodegenp, true, "print AST before code generation" }
-};
-enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
-
-static void usage( char * argv[] ) {
-    cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
-	int i = 0, j = 1;									// j skips starting colon
-	for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
-		if ( long_opts[i].name[0] != '\0' ) {			// hidden option, internal usage only
-			if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag
-				cout << "  -" << optstring[j] << ",";
-			} else {									// no flag
-				j -= 1;									// compensate
-				cout << "     ";
-			} // if
-			cout << " --" << left << setw(12) << long_opts[i].name << "  ";
-			if ( strcmp( long_opts[i].name, "print" ) == 0 ) {
-				cout << "one of: " << endl;
-				for ( int i = 0; i < printoptsSize; i += 1 ) {
-					cout << setw(10) << " " << left << setw(10) << printopts[i].name << "  " << printopts[i].descript << endl;
-				} // for
-			} else {
-				cout << description[i] << endl;
-			} // if
-		} // if
-		if ( optstring[j + 1] == ':' ) j += 1;
-	} // for
-	if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" );
-    exit( EXIT_FAILURE );
-} // usage
-
-static void parse_cmdline( int argc, char * argv[] ) {
-	opterr = 0;											// (global) prevent getopt from printing error messages
-
-	bool Wsuppress = false, Werror = false;
-	int c;
-	while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) {
-		switch ( c ) {
-		  case 'c':										// diagnostic colors
-			if ( strcmp( optarg, "always" ) == 0 ) {
-				ErrorHelpers::colors = ErrorHelpers::Colors::Always;
-			} else if ( strcmp( optarg, "never" ) == 0 ) {
-				ErrorHelpers::colors = ErrorHelpers::Colors::Never;
-			} else if ( strcmp( optarg, "auto" ) == 0 ) {
-				ErrorHelpers::colors = ErrorHelpers::Colors::Auto;
-			} // if
-			break;
-		  case 'h':										// help message
-			usage( argv );								// no return
-			break;
-		  case 'i':										// invariant checking
-			invariant = true;
-			break;
-		  case 'l':										// generate libcfa.c
-			libcfap = true;
-			break;
-		  case 'L':										// generate line marks
-			linemarks = true;
-			break;
-		  case 'm':										// do not replace main
-			nomainp = true;
-			break;
-		  case 'N':										// do not generate line marks
-			linemarks = false;
-			break;
-		  case 'n':										// do not read prelude
-			nopreludep = true;
-			break;
-		  case 'p':										// generate prototypes for prelude functions
-			genproto = true;
-			break;
-		  case 'd':                                     // don't print non-deterministic output
-			deterministic_output = true;
-			break;
-		  case 'P':										// print options
-			for ( int i = 0;; i += 1 ) {
-				if ( i == printoptsSize ) {
-					cout << "Unknown --print option " << optarg << endl;
-					goto Default;
-				} // if
-				if ( strcmp( optarg, printopts[i].name ) == 0 ) {
-					printopts[i].flag = printopts[i].val;
-					break;
-				} // if
-			} // for
-			break;
-		  case PreludeDir:								// prelude directory for debug/nodebug, hidden
-			PreludeDirector = optarg;
-			break;
-		  case 'S':										// enable profiling information, argument comma separated list of names
-			Stats::parse_params( optarg );
-			break;
-		  case 't':										// building cfa stdlib
-			treep = true;
-			break;
-		  case 'g':										// wait for gdb
-			waiting_for_gdb = true;
-			break;
-		  case 'w':										// suppress all warnings, hidden
-			Wsuppress = true;
-			break;
-		  case 'W':										// coordinate gcc -W with CFA, hidden
-			if ( strcmp( optarg, "all" ) == 0 ) {
-				SemanticWarning_EnableAll();
-			} else if ( strcmp( optarg, "error" ) == 0 ) {
-				Werror = true;
-			} else {
-				char * warning = optarg;
-				Severity s;
-				if ( strncmp( optarg, "no-", 3 ) == 0 ) {
-					warning += 3;
-					s = Severity::Suppress;
-				} else {
-					s = Severity::Warn;
-				} // if
-				SemanticWarning_Set( warning, s );
-			} // if
-			break;
-		  case 'D':										// ignore -Dxxx, forwarded by cpp, hidden
-			break;
-		  case '?':										// unknown option
-			if ( optopt ) {								// short option ?
-				cout << "Unknown option -" << (char)optopt << endl;
-			} else {
-				cout << "Unknown option " << argv[optind - 1] << endl;
-			} // if
-			goto Default;
-		  case ':':										// missing option
-			if ( optopt ) {								// short option ?
-				cout << "Missing option for -" << (char)optopt << endl;
-			} else {
-				cout << "Missing option for " << argv[optind - 1] << endl;
-			} // if
-			goto Default;
-		  Default:
-		  default:
-			usage( argv );								// no return
-		} // switch
-	} // while
-
-	if ( Werror ) {
-		SemanticWarning_WarningAsError();
-	} // if
-	if ( Wsuppress ) {
-		SemanticWarning_SuppressAll();
-	} // if
-	// for ( const auto w : WarningFormats ) {
-	// 	cout << w.name << ' ' << (int)w.severity << endl;
-	// } // for
-} // parse_cmdline
-
-static bool notPrelude( ast::ptr<ast::Decl> & decl ) {
-	return !decl->linkage.is_builtin;
-}
-
-static void dump( ast::TranslationUnit && unit, std::ostream & out ) {
-	// May filter out all prelude declarations.
-	if ( genproto ) {
-		std::list<ast::ptr<ast::Decl>> decls;
-		std::copy_if( unit.decls.begin(), unit.decls.end(),
-			std::back_inserter( decls ), notPrelude );
-		decls.swap( unit.decls );
-	}
-
-	// May print as full dump or as code generation.
-	if ( codegenp ) {
-		CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false );
-	} else {
-		ast::printAll( out, unit.decls );
-	}
-}
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End:  //
Index: src/main.cpp
===================================================================
--- src/main.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
+++ src/main.cpp	(revision 083e637af37a72dd11b4293ac0f9fc8ffbaf46a8)
@@ -0,0 +1,713 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// main.cc --
+//
+// Author           : Peter Buhr and Rob Schluntz
+// Created On       : Fri May 15 23:12:02 2015
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Wed Nov  1 21:12:58 2023
+// Update Count     : 690
+//
+
+#include <cxxabi.h>                         // for __cxa_demangle
+#include <execinfo.h>                       // for backtrace, backtrace_symbols
+#include <getopt.h>                         // for no_argument, optind, geto...
+#include <cassert>                          // for assertf
+#include <cstdio>                           // for fopen, FILE, fclose, stdin
+#include <cstdlib>                          // for exit, free, abort, EXIT_F...
+#include <csignal>                          // for signal, SIGABRT, SIGSEGV
+#include <cstring>                          // for index
+#include <fstream>                          // for ofstream
+#include <iostream>                         // for operator<<, basic_ostream
+#include <iomanip>
+#include <iterator>                         // for back_inserter
+#include <list>                             // for list
+#include <string>                           // for char_traits, operator<<
+
+#include "AST/Pass.hpp"                     // for pass_visitor_stats
+#include "AST/Print.hpp"                    // for printAll
+#include "AST/TranslationUnit.hpp"          // for TranslationUnit
+#include "AST/Util.hpp"                     // for checkInvariants
+#include "CompilationState.hpp"
+#include "../config.h"                      // for CFA_LIBDIR
+#include "CodeGen/FixMain.h"                // for FixMain
+#include "CodeGen/FixNames.h"               // for fixNames
+#include "CodeGen/Generate.h"               // for generate
+#include "CodeGen/LinkOnce.h"               // for translateLinkOnce
+#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
+#include "Common/DeclStats.hpp"             // for printDeclStats
+#include "Common/ResolvProtoDump.hpp"       // for dumpAsResolverProto
+#include "Common/Stats.h"                   // for Stats
+#include "Common/utility.h"                 // for deleteAll, filter, printAll
+#include "Concurrency/Actors.hpp"           // for implementActors
+#include "Concurrency/Corun.hpp"            // for implementCorun
+#include "Concurrency/Keywords.h"           // for implementMutex, implement...
+#include "Concurrency/Waitfor.h"            // for generateWaitfor
+#include "Concurrency/Waituntil.hpp"        // for generateWaitUntil
+#include "ControlStruct/ExceptDecl.h"       // for translateExcept
+#include "ControlStruct/ExceptTranslate.h"  // for translateThrows, translat...
+#include "ControlStruct/FixLabels.hpp"      // for fixLabels
+#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
+#include "GenPoly/Box.h"                    // for box
+#include "GenPoly/InstantiateGeneric.h"     // for instantiateGeneric
+#include "GenPoly/Lvalue.h"                 // for convertLvalue
+#include "GenPoly/Specialize.h"             // for convertSpecializations
+#include "InitTweak/FixInit.h"              // for fix
+#include "InitTweak/GenInit.h"              // for genInit
+#include "MakeLibCfa.hpp"                   // for makeLibCfa
+#include "Parser/RunParser.hpp"             // for buildList, dumpParseTree,...
+#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
+#include "ResolvExpr/EraseWith.hpp"         // for eraseWith
+#include "ResolvExpr/Resolver.h"            // for resolve
+#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
+#include "Validate/Autogen.hpp"             // for autogenerateRoutines
+#include "Validate/ImplementEnumFunc.hpp"   // for implementEnumFunc
+#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
+#include "Validate/EliminateTypedef.hpp"    // for eliminateTypedef
+#include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers
+#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
+#include "Validate/FixQualifiedTypes.hpp"   // for fixQualifiedTypes
+#include "Validate/FixReturnTypes.hpp"      // for fixReturnTypes
+#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
+#include "Validate/GenericParameter.hpp"    // for fillGenericParameters, tr...
+#include "Validate/HoistStruct.hpp"         // for hoistStruct
+#include "Validate/HoistTypeDecls.hpp"      // for hoistTypeDecls
+#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
+#include "Validate/LabelAddressFixer.hpp"   // for fixLabelAddresses
+#include "Validate/LinkInstanceTypes.hpp"   // for linkInstanceTypes
+#include "Validate/ReplaceTypedef.hpp"      // for replaceTypedef
+#include "Validate/ReturnCheck.hpp"         // for checkReturnStatements
+#include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign
+#include "Validate/ReplacePseudoFunc.hpp"   // for replacePseudoFunc
+#include "Virtual/ExpandCasts.h"            // for expandCasts
+#include "Virtual/VirtualDtor.hpp"          // for implementVirtDtors
+
+using namespace std;
+
+static void NewPass( const char * const name ) {
+	Stats::Heap::newPass( name );
+	using namespace Stats::Counters;
+	{
+		static auto group = build<CounterGroup>( "Pass Visitor Template" );
+		auto pass = build<CounterGroup>( name, group );
+		ast::pass_visitor_stats.depth = 0;
+		ast::pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass );
+		ast::pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass );
+	}
+}
+
+#define PASS( name, pass, unit, ... )       \
+	if ( errorp ) { cerr << name << endl; } \
+	NewPass(name);                          \
+	Stats::Time::StartBlock(name);          \
+	pass(unit,##__VA_ARGS__);               \
+	Stats::Time::StopBlock();               \
+	if ( invariant ) {                      \
+		ast::checkInvariants(unit);         \
+	}
+
+#define DUMP( cond, unit )                  \
+	if ( cond ) {                           \
+		dump(unit);                         \
+		return EXIT_SUCCESS;                \
+	}
+
+static bool waiting_for_gdb = false;					// flag to set cfa-cpp to wait for gdb on start
+
+static string PreludeDirector = "";
+
+static void parse_cmdline( int argc, char * argv[] );
+static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
+
+static void backtrace( int start ) {					// skip first N stack frames
+	enum { Frames = 50, };								// maximum number of stack frames
+	void * array[Frames];
+	size_t size = ::backtrace( array, Frames );
+	char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
+
+	*index( messages[0], '(' ) = '\0';					// find executable name
+	cerr << "Stack back trace for: " << messages[0] << endl;
+
+	// skip last 2 stack frames after main
+	for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
+		char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
+
+		for ( char * p = messages[i]; *p; p += 1 ) {	// find parantheses and +offset
+			if ( *p == '(' ) {
+				mangled_name = p;
+			} else if ( *p == '+' ) {
+				offset_begin = p;
+			} else if ( *p == ')' ) {
+				offset_end = p;
+				break;
+			} // if
+		} // for
+
+		// if line contains symbol, attempt to demangle
+		int frameNo = i - start;
+		if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
+			*mangled_name++ = '\0';						// delimit strings
+			*offset_begin++ = '\0';
+			*offset_end++ = '\0';
+
+			int status;
+			char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
+			// bug in __cxa_demangle for single-character lower-case non-mangled names
+			if ( status == 0 ) {						// demangling successful ?
+				cerr << "(" << frameNo << ") " << messages[i] << " : "
+					 << real_name << "+" << offset_begin << offset_end << endl;
+			} else {									// otherwise, output mangled name
+				cerr << "(" << frameNo << ") " << messages[i] << " : "
+					 << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl;
+			} // if
+
+			free( real_name );
+		} else {										// otherwise, print the whole line
+			cerr << "(" << frameNo << ") " << messages[i] << endl;
+		} // if
+	} // for
+
+	free( messages );
+} // backtrace
+
+#define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused ))
+
+static void _Signal(struct sigaction & act, int sig, int flags ) {
+	sigemptyset( &act.sa_mask );
+	act.sa_flags = flags;
+
+	if ( sigaction( sig, &act, nullptr ) == -1 ) {
+	    cerr << "*cfa-cpp compilation error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl;
+	    _exit( EXIT_FAILURE );
+	} // if
+}
+
+static void Signal( int sig, void (* handler)(SIGPARMS), int flags ) {
+	struct sigaction act;
+	act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
+	_Signal(act, sig, flags);
+} // Signal
+
+static void Signal( int sig, void (* handler)(int), int flags ) {
+	struct sigaction act;
+	act.sa_handler = handler;
+	_Signal(act, sig, flags);
+} // Signal
+
+static void sigSegvBusHandler( SIGPARMS ) {
+	if ( sfp->si_addr == nullptr ) {
+		cerr << "Null pointer (nullptr) dereference." << endl;
+	} else {
+		cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl
+			 << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl;
+	} // if
+	backtrace( 2 );										// skip first 2 stack frames
+	abort();											// cause core dump for debugging
+} // sigSegvBusHandler
+
+static void sigFpeHandler( SIGPARMS ) {
+	const char * msg;
+
+	switch ( sfp->si_code ) {
+	  case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break;
+	  case FPE_FLTOVF: msg = "overflow"; break;
+	  case FPE_FLTUND: msg = "underflow"; break;
+	  case FPE_FLTRES: msg = "inexact result"; break;
+	  case FPE_FLTINV: msg = "invalid operation"; break;
+	  default: msg = "unknown";
+	} // choose
+	cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl
+		 << "Possible cause is constant-expression evaluation invalid." << endl;
+	backtrace( 2 );										// skip first 2 stack frames
+	abort();											// cause core dump for debugging
+} // sigFpeHandler
+
+static void sigAbortHandler( SIGPARMS ) {
+	backtrace( 6 );										// skip first 6 stack frames
+	Signal( SIGABRT, SIG_DFL, SA_SIGINFO );	// reset default signal handler
+	raise( SIGABRT );									// reraise SIGABRT
+} // sigAbortHandler
+
+int main( int argc, char * argv[] ) {
+	FILE * input;										// use FILE rather than istream because yyin is FILE
+	ostream * output = & cout;
+	ast::TranslationUnit transUnit;
+
+	Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
+	Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO );
+	Signal( SIGFPE, sigFpeHandler, SA_SIGINFO );
+	Signal( SIGABRT, sigAbortHandler, SA_SIGINFO );
+
+	// cout << "main" << endl;
+	// for ( int i = 0; i < argc; i += 1 ) {
+	// 	cout << '\t' << argv[i] << endl;
+	// } // for
+
+	parse_cmdline( argc, argv );						// process command-line arguments
+
+	if ( waiting_for_gdb ) {
+		cerr << "Waiting for gdb" << endl;
+		cerr << "run :" << endl;
+		cerr << "  gdb attach " << getpid() << endl;
+		raise(SIGSTOP);
+	} // if
+
+	try {
+		// choose to read the program from a file or stdin
+		if ( optind < argc ) {							// any commands after the flags ? => input file name
+			input = fopen( argv[ optind ], "r" );
+			assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
+			optind += 1;
+		} else {										// no input file name
+			input = stdin;
+		} // if
+
+		Stats::Time::StartGlobal();
+		NewPass("Parse");
+		Stats::Time::StartBlock("Parse");
+
+		// read in the builtins, extras, and the prelude
+		if ( ! nopreludep ) {							// include gcc builtins
+			// -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
+
+			assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." );
+
+			// Read to gcc builtins, if not generating the cfa library
+			FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cfa").c_str(), "r" );
+			assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
+			parse( gcc_builtins, ast::Linkage::Compiler );
+
+			// read the extra prelude in, if not generating the cfa library
+			FILE * extras = fopen( (PreludeDirector + "/extras.cfa").c_str(), "r" );
+			assertf( extras, "cannot open extras.cf\n" );
+			parse( extras, ast::Linkage::BuiltinC );
+			if ( ! libcfap ) {
+				// read the prelude in, if not generating the cfa library
+				FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" );
+				assertf( prelude, "cannot open prelude.cfa\n" );
+				parse( prelude, ast::Linkage::Intrinsic );
+
+				// Read to cfa builtins, if not generating the cfa library
+				FILE * builtins = fopen( (PreludeDirector + "/builtins.cfa").c_str(), "r" );
+				assertf( builtins, "cannot open builtins.cf\n" );
+				parse( builtins, ast::Linkage::BuiltinCFA );
+			} // if
+		} // if
+
+		parse( input, libcfap ? ast::Linkage::Intrinsic : ast::Linkage::Cforall, yydebug );
+
+		transUnit = buildUnit();
+
+		DUMP( astp, std::move( transUnit ) );
+
+		Stats::Time::StopBlock();
+
+		PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit );
+
+		PASS( "Translate Exception Declarations", ControlStruct::translateExcept, transUnit );
+		DUMP( exdeclp, std::move( transUnit ) );
+		PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign, transUnit );
+		PASS( "Replace Typedefs", Validate::replaceTypedef, transUnit );
+		PASS( "Fix Return Types", Validate::fixReturnTypes, transUnit );
+		PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers, transUnit );
+
+		PASS( "Link Instance Types", Validate::linkInstanceTypes, transUnit );
+
+		PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit );
+		PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit );
+
+		PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit );
+		PASS( "Hoist Struct", Validate::hoistStruct, transUnit );
+		PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit );
+		PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit );
+		// Need to happen before fixing returns because implementEnumFunc has ReturnStmt
+		
+		PASS( "Generate Enum Attributes Functions", Validate::implementEnumFunc, transUnit );
+		PASS( "Check Function Returns", Validate::checkReturnStatements, transUnit );
+		PASS( "Fix Return Statements", InitTweak::fixReturnStatements, transUnit );
+		PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit );
+		PASS( "Fix Unique Ids", Validate::fixUniqueIds, transUnit );
+		PASS( "Implement Corun", Concurrency::implementCorun, transUnit );
+		PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit );
+
+		PASS( "Generate Autogen Routines", Validate::autogenerateRoutines, transUnit );
+		
+		PASS( "Implement Actors", Concurrency::implementActors, transUnit );
+		PASS( "Implement Virtual Destructors", Virtual::implementVirtDtors, transUnit );
+		PASS( "Implement Mutex", Concurrency::implementMutex, transUnit );
+		PASS( "Implement Thread Start", Concurrency::implementThreadStarter, transUnit );
+		PASS( "Compound Literal", Validate::handleCompoundLiterals, transUnit );
+		PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit );
+		PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit );
+		PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit );
+
+		if ( symtabp ) {
+			return EXIT_SUCCESS;
+		} // if
+
+		if ( expraltp ) {
+			ResolvExpr::printCandidates( transUnit );
+			return EXIT_SUCCESS;
+		} // if
+
+		DUMP( validp, std::move( transUnit ) );
+
+		PASS( "Translate Throws", ControlStruct::translateThrows, transUnit );
+		PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );
+		PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit  );
+		PASS( "Fix Names", CodeGen::fixNames, transUnit );
+		PASS( "Gen Init", InitTweak::genInit, transUnit );
+		PASS( "Expand Member Tuples" , Tuples::expandMemberTuples, transUnit );
+
+		if ( libcfap ) {
+			// Generate the bodies of cfa library functions.
+			LibCfa::makeLibCfa( transUnit );
+		} // if
+
+		if ( declstatsp ) {
+			printDeclStats( transUnit );
+			return EXIT_SUCCESS;
+		} // if
+
+		DUMP( bresolvep, std::move( transUnit ) );
+
+		if ( resolvprotop ) {
+			dumpAsResolverProto( transUnit );
+			return EXIT_SUCCESS;
+		} // if
+
+		PASS( "Resolve", ResolvExpr::resolve, transUnit );
+		DUMP( exprp, std::move( transUnit ) );
+		PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit );
+		PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); // Here
+		PASS( "Erase With", ResolvExpr::eraseWith, transUnit );
+
+		// fix ObjectDecl - replaces ConstructorInit nodes
+		DUMP( ctorinitp, std::move( transUnit ) );
+
+		// Currently not working due to unresolved issues with UniqueExpr
+		PASS( "Expand Unique Expr", Tuples::expandUniqueExpr, transUnit ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
+
+		PASS( "Translate Tries", ControlStruct::translateTries, transUnit );
+		PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit );
+		PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );
+
+		// Needs to happen before tuple types are expanded.
+		PASS( "Convert Specializations",  GenPoly::convertSpecializations, transUnit );
+
+		PASS( "Expand Tuples", Tuples::expandTuples, transUnit );
+		DUMP( tuplep, std::move( transUnit ) );
+
+		// Must come after Translate Tries.
+		PASS( "Virtual Expand Casts", Virtual::expandCasts, transUnit );
+
+		PASS( "Instantiate Generics", GenPoly::instantiateGeneric, transUnit );
+		DUMP( genericsp, std::move( transUnit ) );
+
+		PASS( "Convert L-Value", GenPoly::convertLvalue, transUnit );
+		DUMP( bboxp, std::move( transUnit ) );
+		PASS( "Box", GenPoly::box, transUnit );
+		PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit );
+
+		// Code has been lowered to C, now we can start generation.
+
+		DUMP( bcodegenp, std::move( transUnit ) );
+
+		if ( optind < argc ) {							// any commands after the flags and input file ? => output file name
+			output = new ofstream( argv[ optind ] );
+		} // if
+
+		PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false );
+		CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
+
+		if ( output != &cout ) {
+			delete output;
+		} // if
+	} catch ( SemanticErrorException & e ) {
+		if ( errorp ) {
+			cerr << "---AST at error:---" << endl;
+			dump( std::move( transUnit ), cerr );
+			cerr << endl << "---End of AST, begin error message:---\n" << endl;
+		} // if
+		e.print();
+		if ( output != &cout ) {
+			delete output;
+		} // if
+		return EXIT_FAILURE;
+	} catch ( std::bad_alloc & ) {
+		cerr << "*cfa-cpp compilation error* std::bad_alloc" << endl;
+		backtrace( 1 );
+		abort();
+	} catch ( ... ) {
+		exception_ptr eptr = current_exception();
+		try {
+			if (eptr) {
+				rethrow_exception(eptr);
+			} else {
+				cerr << "*cfa-cpp compilation error* exception uncaught and unknown" << endl;
+			} // if
+		} catch( const exception & e ) {
+			cerr << "*cfa-cpp compilation error* uncaught exception \"" << e.what() << "\"\n";
+		} // try
+		return EXIT_FAILURE;
+	} // try
+
+	Stats::print();
+	return EXIT_SUCCESS;
+} // main
+
+
+static const char optstring[] = ":c:ghilLmNnpdP:S:twW:D:";
+
+enum { PreludeDir = 128 };
+static struct option long_opts[] = {
+	{ "colors", required_argument, nullptr, 'c' },
+	{ "gdb", no_argument, nullptr, 'g' },
+	{ "help", no_argument, nullptr, 'h' },
+	{ "invariant", no_argument, nullptr, 'i' },
+	{ "libcfa", no_argument, nullptr, 'l' },
+	{ "linemarks", no_argument, nullptr, 'L' },
+	{ "no-main", no_argument, nullptr, 'm' },
+	{ "no-linemarks", no_argument, nullptr, 'N' },
+	{ "no-prelude", no_argument, nullptr, 'n' },
+	{ "prototypes", no_argument, nullptr, 'p' },
+	{ "deterministic-out", no_argument, nullptr, 'd' },
+	{ "print", required_argument, nullptr, 'P' },
+	{ "prelude-dir", required_argument, nullptr, PreludeDir },
+	{ "statistics", required_argument, nullptr, 'S' },
+	{ "tree", no_argument, nullptr, 't' },
+	{ "", no_argument, nullptr, 0 },					// -w
+	{ "", no_argument, nullptr, 0 },					// -W
+	{ "", no_argument, nullptr, 0 },					// -D
+	{ nullptr, 0, nullptr, 0 }
+}; // long_opts
+
+static const char * description[] = {
+	"diagnostic color: never, always, auto",			// -c
+	"wait for gdb to attach",							// -g
+	"print translator help message",					// -h
+	"invariant checking during AST passes",				// -i
+	"generate libcfa.c",								// -l
+	"generate line marks",								// -L
+	"do not replace main",								// -m
+	"do not generate line marks",						// -N
+	"do not read prelude",								// -n
+	"do not generate prelude prototypes => prelude not printed", // -p
+	"only print deterministic output",                  // -d
+	"print",											// -P
+	"<directory> prelude directory for debug/nodebug",	// no flag
+	"<option-list> enable profiling information: counters, heap, time, all, none", // -S
+	"building cfa standard lib",						// -t
+	"",													// -w
+	"",													// -W
+	"",													// -D
+}; // description
+
+static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" );
+
+static struct Printopts {
+	const char * name;
+	int & flag;
+	int val;
+	const char * descript;
+} printopts[] = {
+	{ "ascodegen", codegenp, true, "print AST as codegen rather than AST" },
+	{ "asterr", errorp, true, "print AST on error" },
+	{ "declstats", declstatsp, true, "print code property statistics" },
+	{ "parse", yydebug, true, "print yacc (parsing) debug information" },
+	{ "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" },
+	{ "rproto", resolvprotop, true, "resolver-proto instance" },
+	{ "rsteps", resolvep, true, "print resolver steps" },
+	// AST dumps
+	{ "ast", astp, true, "print AST after parsing" },
+	{ "excpdecl", exdeclp, true, "print AST after translating exception decls" },
+	{ "symevt", symtabp, true, "print AST after symbol table events" },
+	{ "expralt", expraltp, true, "print AST after expressions alternatives" },
+	{ "valdecl", validp, true, "print AST after declaration validation pass" },
+	{ "bresolver", bresolvep, true, "print AST before resolver step" },
+	{ "expranly", exprp, true, "print AST after expression analysis" },
+	{ "ctordtor", ctorinitp, true, "print AST after ctor/dtor are replaced" },
+	{ "tuple", tuplep, true, "print AST after tuple expansion" },
+	{ "instgen", genericsp, true, "print AST after instantiate generics" },
+	{ "bbox", bboxp, true, "print AST before box pass" },
+	{ "bcodegen", bcodegenp, true, "print AST before code generation" }
+};
+enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
+
+static void usage( char * argv[] ) {
+    cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
+	int i = 0, j = 1;									// j skips starting colon
+	for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
+		if ( long_opts[i].name[0] != '\0' ) {			// hidden option, internal usage only
+			if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag
+				cout << "  -" << optstring[j] << ",";
+			} else {									// no flag
+				j -= 1;									// compensate
+				cout << "     ";
+			} // if
+			cout << " --" << left << setw(12) << long_opts[i].name << "  ";
+			if ( strcmp( long_opts[i].name, "print" ) == 0 ) {
+				cout << "one of: " << endl;
+				for ( int i = 0; i < printoptsSize; i += 1 ) {
+					cout << setw(10) << " " << left << setw(10) << printopts[i].name << "  " << printopts[i].descript << endl;
+				} // for
+			} else {
+				cout << description[i] << endl;
+			} // if
+		} // if
+		if ( optstring[j + 1] == ':' ) j += 1;
+	} // for
+	if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" );
+    exit( EXIT_FAILURE );
+} // usage
+
+static void parse_cmdline( int argc, char * argv[] ) {
+	opterr = 0;											// (global) prevent getopt from printing error messages
+
+	bool Wsuppress = false, Werror = false;
+	int c;
+	while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) {
+		switch ( c ) {
+		  case 'c':										// diagnostic colors
+			if ( strcmp( optarg, "always" ) == 0 ) {
+				ErrorHelpers::colors = ErrorHelpers::Colors::Always;
+			} else if ( strcmp( optarg, "never" ) == 0 ) {
+				ErrorHelpers::colors = ErrorHelpers::Colors::Never;
+			} else if ( strcmp( optarg, "auto" ) == 0 ) {
+				ErrorHelpers::colors = ErrorHelpers::Colors::Auto;
+			} // if
+			break;
+		  case 'h':										// help message
+			usage( argv );								// no return
+			break;
+		  case 'i':										// invariant checking
+			invariant = true;
+			break;
+		  case 'l':										// generate libcfa.c
+			libcfap = true;
+			break;
+		  case 'L':										// generate line marks
+			linemarks = true;
+			break;
+		  case 'm':										// do not replace main
+			nomainp = true;
+			break;
+		  case 'N':										// do not generate line marks
+			linemarks = false;
+			break;
+		  case 'n':										// do not read prelude
+			nopreludep = true;
+			break;
+		  case 'p':										// generate prototypes for prelude functions
+			genproto = true;
+			break;
+		  case 'd':                                     // don't print non-deterministic output
+			deterministic_output = true;
+			break;
+		  case 'P':										// print options
+			for ( int i = 0;; i += 1 ) {
+				if ( i == printoptsSize ) {
+					cout << "Unknown --print option " << optarg << endl;
+					goto Default;
+				} // if
+				if ( strcmp( optarg, printopts[i].name ) == 0 ) {
+					printopts[i].flag = printopts[i].val;
+					break;
+				} // if
+			} // for
+			break;
+		  case PreludeDir:								// prelude directory for debug/nodebug, hidden
+			PreludeDirector = optarg;
+			break;
+		  case 'S':										// enable profiling information, argument comma separated list of names
+			Stats::parse_params( optarg );
+			break;
+		  case 't':										// building cfa stdlib
+			treep = true;
+			break;
+		  case 'g':										// wait for gdb
+			waiting_for_gdb = true;
+			break;
+		  case 'w':										// suppress all warnings, hidden
+			Wsuppress = true;
+			break;
+		  case 'W':										// coordinate gcc -W with CFA, hidden
+			if ( strcmp( optarg, "all" ) == 0 ) {
+				SemanticWarning_EnableAll();
+			} else if ( strcmp( optarg, "error" ) == 0 ) {
+				Werror = true;
+			} else {
+				char * warning = optarg;
+				Severity s;
+				if ( strncmp( optarg, "no-", 3 ) == 0 ) {
+					warning += 3;
+					s = Severity::Suppress;
+				} else {
+					s = Severity::Warn;
+				} // if
+				SemanticWarning_Set( warning, s );
+			} // if
+			break;
+		  case 'D':										// ignore -Dxxx, forwarded by cpp, hidden
+			break;
+		  case '?':										// unknown option
+			if ( optopt ) {								// short option ?
+				cout << "Unknown option -" << (char)optopt << endl;
+			} else {
+				cout << "Unknown option " << argv[optind - 1] << endl;
+			} // if
+			goto Default;
+		  case ':':										// missing option
+			if ( optopt ) {								// short option ?
+				cout << "Missing option for -" << (char)optopt << endl;
+			} else {
+				cout << "Missing option for " << argv[optind - 1] << endl;
+			} // if
+			goto Default;
+		  Default:
+		  default:
+			usage( argv );								// no return
+		} // switch
+	} // while
+
+	if ( Werror ) {
+		SemanticWarning_WarningAsError();
+	} // if
+	if ( Wsuppress ) {
+		SemanticWarning_SuppressAll();
+	} // if
+	// for ( const auto w : WarningFormats ) {
+	// 	cout << w.name << ' ' << (int)w.severity << endl;
+	// } // for
+} // parse_cmdline
+
+static bool notPrelude( ast::ptr<ast::Decl> & decl ) {
+	return !decl->linkage.is_builtin;
+}
+
+static void dump( ast::TranslationUnit && unit, std::ostream & out ) {
+	// May filter out all prelude declarations.
+	if ( genproto ) {
+		std::list<ast::ptr<ast::Decl>> decls;
+		std::copy_if( unit.decls.begin(), unit.decls.end(),
+			std::back_inserter( decls ), notPrelude );
+		decls.swap( unit.decls );
+	}
+
+	// May print as full dump or as code generation.
+	if ( codegenp ) {
+		CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false );
+	} else {
+		ast::printAll( out, unit.decls );
+	}
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End:  //
