Index: src/CodeGen/module.mk
===================================================================
--- src/CodeGen/module.mk	(revision c46c9992236856235ca6f5779f33a32cc75195a5)
+++ src/CodeGen/module.mk	(revision 0589e83d12bef5409ba2bb4eb9afaa0e0986ead4)
@@ -16,14 +16,16 @@
 
 SRC_CODEGEN = \
+	CodeGen/CodeGenerator.cc \
+	CodeGen/CodeGenerator.h \
+	CodeGen/CodeGeneratorNew.cpp \
+	CodeGen/CodeGeneratorNew.hpp \
 	CodeGen/FixMain2.cc \
 	CodeGen/FixMain.h \
+	CodeGen/GenType.cc \
+	CodeGen/GenType.h \
 	CodeGen/OperatorTable.cc \
 	CodeGen/OperatorTable.h
 
 SRC += $(SRC_CODEGEN) \
-	CodeGen/CodeGenerator.cc \
-	CodeGen/CodeGenerator.h \
-	CodeGen/CodeGeneratorNew.cpp \
-	CodeGen/CodeGeneratorNew.hpp \
 	CodeGen/Generate.cc \
 	CodeGen/Generate.h \
@@ -31,6 +33,4 @@
 	CodeGen/FixNames.cc \
 	CodeGen/FixNames.h \
-	CodeGen/GenType.cc \
-	CodeGen/GenType.h \
 	CodeGen/LinkOnce.cc \
 	CodeGen/LinkOnce.h \
Index: src/SymTab/Demangle.cc
===================================================================
--- src/SymTab/Demangle.cc	(revision c46c9992236856235ca6f5779f33a32cc75195a5)
+++ src/SymTab/Demangle.cc	(revision 0589e83d12bef5409ba2bb4eb9afaa0e0986ead4)
@@ -31,291 +31,4 @@
 #define PRINT(x) {}
 #endif
-
-namespace {
-	struct GenType : public WithVisitorRef<GenType>, public WithShortCircuiting {
-		std::string typeString;
-		GenType( const std::string &typeString );
-
-		void previsit( BaseSyntaxNode * );
-		void postvisit( BaseSyntaxNode * );
-
-		void postvisit( FunctionType * funcType );
-		void postvisit( VoidType * voidType );
-		void postvisit( BasicType * basicType );
-		void postvisit( PointerType * pointerType );
-		void postvisit( ArrayType * arrayType );
-		void postvisit( ReferenceType * refType );
-		void postvisit( StructInstType * structInst );
-		void postvisit( UnionInstType * unionInst );
-		void postvisit( EnumInstType * enumInst );
-		void postvisit( TypeInstType * typeInst );
-		void postvisit( TupleType  * tupleType );
-		void postvisit( VarArgsType * varArgsType );
-		void postvisit( ZeroType * zeroType );
-		void postvisit( OneType * oneType );
-		void postvisit( GlobalScopeType * globalType );
-		void postvisit( QualifiedType * qualType );
-
-	  private:
-		void handleQualifiers( Type *type );
-		std::string handleGeneric( ReferenceToType * refType );
-		void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
-	};
-
-  std::string genDemangleType( Type * type, const std::string & baseString ) {
-		PassVisitor<GenType> gt( baseString );
-		assert( type );
-		type->accept( gt );
-		return gt.pass.typeString;
-  }
-
-	GenType::GenType( const std::string &typeString ) : typeString( typeString ) {}
-
-	// *** BaseSyntaxNode
-	void GenType::previsit( BaseSyntaxNode * ) {
-		// turn off automatic recursion for all nodes, to allow each visitor to
-		// precisely control the order in which its children are visited.
-		visit_children = false;
-	}
-
-	void GenType::postvisit( BaseSyntaxNode * node ) {
-		std::stringstream ss;
-		node->print( ss );
-		assertf( false, "Unhandled node reached in GenType: %s", ss.str().c_str() );
-	}
-
-	void GenType::postvisit( VoidType * voidType ) {
-		typeString = "void " + typeString;
-		handleQualifiers( voidType );
-	}
-
-	void GenType::postvisit( BasicType * basicType ) {
-		BasicType::Kind kind = basicType->kind;
-		assert( 0 <= kind && kind < BasicType::NUMBER_OF_BASIC_TYPES );
-		typeString = std::string( BasicType::typeNames[kind] ) + " " + typeString;
-		handleQualifiers( basicType );
-	}
-
-	void GenType::genArray( const Type::Qualifiers & qualifiers, Type * base, Expression *dimension, bool isVarLen, bool ) {
-		std::ostringstream os;
-		if ( typeString != "" ) {
-			if ( typeString[ 0 ] == '*' ) {
-				os << "(" << typeString << ")";
-			} else {
-				os << typeString;
-			} // if
-		} // if
-		os << "[";
-
-		if ( qualifiers.is_const ) {
-			os << "const ";
-		} // if
-		if ( qualifiers.is_volatile ) {
-			os << "volatile ";
-		} // if
-		if ( qualifiers.is_restrict ) {
-			os << "__restrict ";
-		} // if
-		if ( qualifiers.is_atomic ) {
-			os << "_Atomic ";
-		} // if
-		if ( dimension != 0 ) {
-			// TODO: ???
-			// PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
-			// dimension->accept( cg );
-		} else if ( isVarLen ) {
-			// no dimension expression on a VLA means it came in with the * token
-			os << "*";
-		} // if
-		os << "]";
-
-		typeString = os.str();
-
-		base->accept( *visitor );
-	}
-
-	void GenType::postvisit( PointerType * pointerType ) {
-		assert( pointerType->base != 0);
-		if ( pointerType->get_isStatic() || pointerType->get_isVarLen() || pointerType->dimension ) {
-			assert(false);
-			genArray( pointerType->get_qualifiers(), pointerType->base, pointerType->dimension, pointerType->get_isVarLen(), pointerType->get_isStatic() );
-		} else {
-			handleQualifiers( pointerType );
-			if ( typeString[ 0 ] == '?' ) {
-				typeString = "* " + typeString;
-			} else {
-				typeString = "*" + typeString;
-			} // if
-			pointerType->base->accept( *visitor );
-		} // if
-	}
-
-	void GenType::postvisit( ArrayType * arrayType ) {
-		genArray( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->get_isVarLen(), arrayType->get_isStatic() );
-	}
-
-	void GenType::postvisit( ReferenceType * refType ) {
-		assert( false );
-		assert( refType->base != 0);
-		handleQualifiers( refType );
-		typeString = "&" + typeString;
-		refType->base->accept( *visitor );
-	}
-
-	void GenType::postvisit( FunctionType * funcType ) {
-		std::ostringstream os;
-
-		if ( typeString != "" ) {
-			if ( typeString[0] == '*' ) {
-				os << "(" << typeString << ")";
-			} else {
-				os << typeString;
-			} // if
-		} // if
-
-		/************* parameters ***************/
-		const std::list<DeclarationWithType *> &pars = funcType->parameters;
-
-		if ( pars.empty() ) {
-			if ( funcType->get_isVarArgs() ) {
-				os << "()";
-			} else {
-				os << "(void)";
-			} // if
-		} else {
-			os << "(" ;
-
-			unsigned int i = 0;
-			for (DeclarationWithType * p : pars) {
-				os << genDemangleType( p->get_type(), "" );
-				if (++i != pars.size()) os << ", ";
-			}
-
-			if ( funcType->get_isVarArgs() ) {
-				os << ", ...";
-			} // if
-			os << ")";
-		} // if
-
-		typeString = os.str();
-
-		if ( funcType->returnVals.size() == 0 ) {
-			typeString += ": void";
-		} else {
-			typeString += ": " + genDemangleType(funcType->returnVals.front()->get_type(), "");
-		} // if
-
-		// add forall
-		if( ! funcType->forall.empty() ) {
-			std::ostringstream os;
-			os << "forall(";
-			unsigned int i = 0;
-			for ( auto td : funcType->forall ) {
-				os << td->typeString() << " " << td->name;
-				if (! td->assertions.empty()) {
-					os << " | { ";
-					unsigned int j = 0;
-					for (DeclarationWithType * assert : td->assertions) {
-						os << genDemangleType(assert->get_type(), assert->name);
-						if (++j != td->assertions.size()) os << ", ";
-					}
-					os << "}";
-				}
-				if (++i != funcType->forall.size()) os << ", ";
-			}
-			os << ")";
-			typeString = typeString + " -> " + os.str();
-		}
-	}
-
-	std::string GenType::handleGeneric( ReferenceToType * refType ) {
-		if ( ! refType->parameters.empty() ) {
-			std::ostringstream os;
-			// TODO: ???
-			// PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
-			os << "(";
-			// cg.pass.genCommaList( refType->parameters.begin(), refType->parameters.end() );
-			os << ") ";
-			return os.str();
-		}
-		return "";
-	}
-
-	void GenType::postvisit( StructInstType * structInst )  {
-		typeString = "struct " + structInst->name + handleGeneric( structInst ) + " " + typeString;
-		handleQualifiers( structInst );
-	}
-
-	void GenType::postvisit( UnionInstType * unionInst ) {
-		typeString = "union " + unionInst->name + handleGeneric( unionInst ) + " " + typeString;
-		handleQualifiers( unionInst );
-	}
-
-	void GenType::postvisit( EnumInstType * enumInst ) {
-		typeString = "enum " + enumInst->name + " " + typeString;
-		handleQualifiers( enumInst );
-	}
-
-	void GenType::postvisit( TypeInstType * typeInst ) {
-		typeString = typeInst->name + " " + typeString;
-		handleQualifiers( typeInst );
-	}
-
-	void GenType::postvisit( TupleType * tupleType ) {
-		unsigned int i = 0;
-		std::ostringstream os;
-		os << "[";
-		for ( Type * t : *tupleType ) {
-			i++;
-			os << genDemangleType( t, "" ) << (i == tupleType->size() ? "" : ", ");
-		}
-		os << "] ";
-		typeString = os.str() + typeString;
-	}
-
-	void GenType::postvisit( VarArgsType * varArgsType ) {
-		typeString = "__builtin_va_list " + typeString;
-		handleQualifiers( varArgsType );
-	}
-
-	void GenType::postvisit( ZeroType * zeroType ) {
-		// ideally these wouldn't hit codegen at all, but should be safe to make them ints
-		typeString = "zero_t " + typeString;
-		handleQualifiers( zeroType );
-	}
-
-	void GenType::postvisit( OneType * oneType ) {
-		// ideally these wouldn't hit codegen at all, but should be safe to make them ints
-		typeString = "one_t " + typeString;
-		handleQualifiers( oneType );
-	}
-
-	void GenType::postvisit( GlobalScopeType * globalType ) {
-		handleQualifiers( globalType );
-	}
-
-	void GenType::postvisit( QualifiedType * qualType ) {
-		std::ostringstream os;
-		os << genDemangleType( qualType->parent, "" ) << "." << genDemangleType( qualType->child, "" ) << typeString;
-		typeString = os.str();
-		handleQualifiers( qualType );
-	}
-
-	void GenType::handleQualifiers( Type * type ) {
-		if ( type->get_const() ) {
-			typeString = "const " + typeString;
-		} // if
-		if ( type->get_volatile() ) {
-			typeString = "volatile " + typeString;
-		} // if
-		if ( type->get_restrict() ) {
-			typeString = "__restrict " + typeString;
-		} // if
-		if ( type->get_atomic() ) {
-			typeString = "_Atomic " + typeString;
-		} // if
-	}
-}
-
 
 namespace SymTab {
@@ -609,5 +322,5 @@
 				if (info) name = info->inputName;
 				std::unique_ptr<Type> manager(type);
-				return genDemangleType(type, name);
+				return CodeGen::genType(type, name);
 			}
 		} // namespace
