Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/CodeGenerator.cc	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -10,5 +10,5 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Tus May  9 16:50:00 2017
+// Last Modified On : Wed May 10 14:45:00 2017
 // Update Count     : 484
 //
@@ -41,17 +41,4 @@
 namespace CodeGen {
 	int CodeGenerator::tabsize = 4;
-
-	// Pseudo Function: output << lineDirective(currentNode);
-    struct lineDirective {
-        CodeLocation const & loc;
-		lineDirective(CodeLocation const & location) : loc(location) {}
-		lineDirective(BaseSyntaxNode const * node) : loc(node->location) {}
-	};
-	std::ostream & operator<<(std::ostream & out, lineDirective const & ld) {
-		if (ld.loc.isSet())
-			return out << "\n# " << ld.loc.linenumber << " \""
-				<< ld.loc.filename << "\"\n";
-		return out << "\n// Unset Location\n";
-	}
 
 	// the kinds of statements that would ideally be followed by whitespace
@@ -102,5 +89,27 @@
 	}
 
-	CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ) {}
+	CodeGenerator::LineMarker::LineMarker(
+			CodeLocation const & loc, bool toPrint) :
+		loc(loc), toPrint(toPrint)
+	{}
+
+	CodeGenerator::LineMarker CodeGenerator::lineDirective(
+			BaseSyntaxNode const * node) {
+		return LineMarker(node->location, lineMarks);
+	}
+
+	std::ostream & operator<<(std::ostream & out,
+			CodeGenerator::LineMarker const & marker) {
+		if (marker.toPrint && marker.loc.isSet()) {
+			return out << "\n# " << marker.loc.linenumber << " \""
+				<< marker.loc.filename << "\"\n";
+		} else if (marker.toPrint) {
+			return out << "\n/* Missing CodeLocation */\n";
+		} else {
+        	return out;
+		}
+	}
+
+	CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
 
 	CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp )
@@ -143,6 +152,4 @@
 	// *** Declarations
 	void CodeGenerator::visit( FunctionDecl * functionDecl ) {
-		output << lineDirective( functionDecl );
-
 		extension( functionDecl );
 		genAttributes( functionDecl->get_attributes() );
@@ -168,6 +175,4 @@
 		}
 
-		output << lineDirective( objectDecl );
-
 		extension( objectDecl );
 		genAttributes( objectDecl->get_attributes() );
@@ -221,6 +226,4 @@
 
 	void CodeGenerator::visit( StructDecl * structDecl ) {
-		output << lineDirective( structDecl );
-
 		extension( structDecl );
 		handleAggregate( structDecl, "struct " );
@@ -228,6 +231,4 @@
 
 	void CodeGenerator::visit( UnionDecl * unionDecl ) {
-		output << lineDirective( unionDecl );
-
 		extension( unionDecl );
 		handleAggregate( unionDecl, "union " );
Index: src/CodeGen/CodeGenerator.h
===================================================================
--- src/CodeGen/CodeGenerator.h	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/CodeGenerator.h	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Mar  1 16:20:04 2017
-// Update Count     : 50
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed May 10 10:57:00 2017
+// Update Count     : 51
 //
 
@@ -25,4 +25,6 @@
 #include "SymTab/Indexer.h"
 
+#include "Common/utility.h"
+
 namespace CodeGen {
 	class CodeGenerator : public Visitor {
@@ -30,5 +32,5 @@
 		static int tabsize;
 
-		CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false );
+		CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false );
 		CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
 		CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
@@ -110,4 +112,13 @@
 		};
 
+		struct LineMarker {
+			CodeLocation const & loc;
+			bool toPrint;
+
+			LineMarker(CodeLocation const & loc, bool toPrint);
+		};
+
+		LineMarker lineDirective(BaseSyntaxNode const * node);
+
 		void asmName( DeclarationWithType *decl );
 
@@ -122,4 +133,5 @@
 		bool pretty = false;  // pretty print
 		bool genC = false;    // true if output has to be C code
+		bool lineMarks = false;
 
 		void printDesignators( std::list< Expression * > & );
@@ -149,4 +161,7 @@
 	/// returns C-compatible name of declaration
 	std::string genName( DeclarationWithType * decl );
+
+	std::ostream & operator<<(std::ostream &,
+		CodeGenerator::LineMarker const &);
 } // namespace CodeGen
 
Index: src/CodeGen/GenType.cc
===================================================================
--- src/CodeGen/GenType.cc	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/GenType.cc	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -28,5 +28,5 @@
 	class GenType : public Visitor {
 	  public:
-		GenType( const std::string &typeString, bool pretty = false, bool genC = false );
+		GenType( const std::string &typeString, bool pretty = false, bool genC = false, bool lineMarks = false );
 		std::string get_typeString() const { return typeString; }
 		void set_typeString( const std::string &newValue ) { typeString = newValue; }
@@ -54,12 +54,13 @@
 		bool pretty = false; // pretty print
 		bool genC = false;   // generating C code?
+		bool lineMarks = false;
 	};
 
-	std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC ) {
-		GenType gt( baseString, pretty, genC );
+	std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC , bool lineMarks ) {
+		GenType gt( baseString, pretty, genC, lineMarks );
 		std::ostringstream os;
 
 		if ( ! type->get_attributes().empty() ) {
-			CodeGenerator cg( os, pretty, genC );
+			CodeGenerator cg( os, pretty, genC, lineMarks );
 			cg.genAttributes( type->get_attributes() );
 		} // if
@@ -73,5 +74,5 @@
   }
 
-	GenType::GenType( const std::string &typeString, bool pretty, bool genC ) : typeString( typeString ), pretty( pretty ), genC( genC ) {}
+	GenType::GenType( const std::string &typeString, bool pretty, bool genC, bool lineMarks ) : typeString( typeString ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
 
 	void GenType::visit( VoidType *voidType ) {
@@ -114,5 +115,5 @@
 		} // if
 		if ( dimension != 0 ) {
-			CodeGenerator cg( os, pretty, genC );
+			CodeGenerator cg( os, pretty, genC, lineMarks );
 			dimension->accept( cg );
 		} else if ( isVarLen ) {
@@ -168,5 +169,5 @@
 			} // if
 		} else {
-			CodeGenerator cg( os, pretty, genC );
+			CodeGenerator cg( os, pretty, genC, lineMarks );
 			os << "(" ;
 
@@ -191,5 +192,5 @@
 			// assertf( ! genC, "Aggregate type parameters should not reach code generation." );
 			std::ostringstream os;
-			CodeGenerator cg( os, pretty, genC );
+			CodeGenerator cg( os, pretty, genC, lineMarks );
 			os << "forall(";
 			cg.genCommaList( funcType->get_forall().begin(), funcType->get_forall().end() );
@@ -202,5 +203,5 @@
 		if ( ! refType->get_parameters().empty() ) {
 			std::ostringstream os;
-			CodeGenerator cg( os, pretty, genC );
+			CodeGenerator cg( os, pretty, genC, lineMarks );
 			os << "(";
 			cg.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() );
@@ -242,5 +243,5 @@
 		for ( Type * t : *tupleType ) {
 			i++;
-			os << genType( t, "", pretty, genC ) << (i == tupleType->size() ? "" : ", ");
+			os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", ");
 		}
 		os << "]";
Index: src/CodeGen/GenType.h
===================================================================
--- src/CodeGen/GenType.h	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/GenType.h	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -21,5 +21,5 @@
 
 namespace CodeGen {
-	std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false );
+	std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false );
   std::string genPrettyType( Type * type, const std::string & baseString );
 } // namespace CodeGen
Index: src/CodeGen/Generate.cc
===================================================================
--- src/CodeGen/Generate.cc	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/Generate.cc	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Jun  4 14:04:25 2015
-// Update Count     : 5
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed May 19 13:05:00 2017
+// Update Count     : 6
 //
 
@@ -31,8 +31,9 @@
 
 namespace CodeGen {
-	void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC ) {
-		CodeGen::CodeGenerator cgv( os, pretty, generateC );
+	void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {
+		CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks );
 		for ( auto & dcl : translationUnit ) {
 			if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
+				os << cgv.lineDirective(dcl);
 				dcl->accept(cgv);
 				if ( doSemicolon( dcl ) ) {
@@ -48,5 +49,5 @@
 			os << CodeGen::genPrettyType( type, "" );
 		} else {
-			CodeGen::CodeGenerator cgv( os, true, false );
+			CodeGen::CodeGenerator cgv( os, true, false, false );
 			node->accept( cgv );
 		}
Index: src/CodeGen/Generate.h
===================================================================
--- src/CodeGen/Generate.h	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ src/CodeGen/Generate.h	(revision c850687eb917f931218d61a9f12b8c3c9f211d1c)
@@ -24,5 +24,5 @@
 namespace CodeGen {
 	/// Generates code. doIntrinsics determines if intrinsic functions are printed, pretty formats output nicely (e.g., uses unmangled names, etc.), generateC is true when the output must consist only of C code (allows some assertions, etc.)
-	void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false );
+	void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false , bool lineMarks = false );
 
 	/// Generate code for a single node -- helpful for debugging in gdb
Index: src/CodeGen/LineStream.cc
===================================================================
--- src/CodeGen/LineStream.cc	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ 	(revision )
@@ -1,97 +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.
-//
-// LineStream.cc -- Modified stream that inserts line directives into output.
-//
-// Author           : Andrew Beach
-// Created On       : Thr May 4 13:15:00 2017
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon May 8 12:08:00 2017
-// Update Count     : 0
-//
-
-#include "LineStream.h"
-
-namespace CodeGen {
-
-	void LineStream::printLineDirective(CodeLocation const & location) {
-		baseStream << "\n# " << location.linenumber;
-		if (std::string("") != location.filename) {
-			baseStream << " \"" << location.filename  << '"';
-		}
-		baseStream << '\n';
-	}
-
-	bool LineStream::actualDiffersFromExpected() const {
-		return actualLocation.isSet() &&
-			// actualLocation & expectedLocation must match at the line.
-			(actualLocation.linenumber != expectedLocation.linenumber ||
-			 actualLocation.filename != expectedLocation.filename);
-	}
-
-	void LineStream::emptyBuffer(bool addNewline) {
-		if (actualDiffersFromExpected()) {
-			printLineDirective(actualLocation);
-			expectedLocation = actualLocation;
-		}
-		actualLocation.unset();
-
-		if (addNewline) {
-			expectedLocation.linenumber += 1;
-			buffer.put('\n');
-		}
-
-		baseStream << buffer.str() << std::flush;
-		buffer.str("");
-	}
-
-	void LineStream::setLoc(CodeLocation const & location) {
-		if (insertLines) {
-			if (expectedLocation.isUnset()) {
-				expectedLocation = actualLocation = location;
-			} else if (actualLocation.isUnset()) {
-				actualLocation = location;
-			} else if (actualLocation.filename != location.filename) {
-				emptyBuffer(true);
-				actualLocation = location;
-			} else if (location.linenumber <= actualLocation.linenumber){
-				actualLocation.linenumber = location.linenumber;
-			}
-		}
-	}
-
-	LineStream & LineStream::operator<<(char const * str) {
-		buffer << str;
-		return *this;
-	}
-
-	LineStream & LineStream::operator<<(std::string const & str) {
-		buffer << str;
-		return *this;
-	}
-
-	LineStream & LineStream::operator<<(StreamFlag flag) {
-		static StreamFlag const endlCopy = std::endl;
-		if (!insertLines) {
-			baseStream << flag;
-		} else if (endlCopy == flag) {
-			emptyBuffer(true);
-		} else {
-			buffer << flag;
-		}
-		return *this;
-	}
-
-	LineStream & LineStream::flush() {
-		if (insertLines) {
-			emptyBuffer(false);
-		} else {
-			baseStream.flush();
-		}
-		return *this;
-	}
-
-} // CodeGen
Index: src/CodeGen/LineStream.h
===================================================================
--- src/CodeGen/LineStream.h	(revision 29cf9c8380adc64d48f6b1c9ddf904a690e12b65)
+++ 	(revision )
@@ -1,62 +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.
-//
-// LineStream.h -- Modified stream that inserts line directives into output.
-//
-// Author           : Andrew Beach
-// Created On       : Wed May 4 09:15:00 2017
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon May 8 14:03:00 2017
-// Update Count     : 1
-//
-
-#ifndef LINE_STREAM_H
-#define LINE_STREAM_H
-
-#include <ostream>
-#include <sstream>
-#include <string>
-
-#include "Common/utility.h"
-
-namespace CodeGen {
-
-	class LineStream {
-		std::ostream & baseStream;
-		std::ostringstream buffer;
-
-		bool const insertLines;
-
-		CodeLocation actualLocation;
-		CodeLocation expectedLocation;
-
-		void printLineDirective(CodeLocation const & location);
-		bool actualDiffersFromExpected() const;
-		void emptyBuffer(bool addNewline);
-
-	public:
-		typedef std::ostream &(*StreamFlag)(std::ostream &);
-
-		LineStream(std::ostream & baseStream, bool insertLines) :
-			baseStream(baseStream), insertLines(insertLines)
-		{}
-
-		/// Update the currentLocation in source code.
-		void setLoc(CodeLocation const & location);
-
-		/// Formated output is buffered until flushed.
-		LineStream & operator<<(char const *str);
-		LineStream & operator<<(std::string const & str);
-		LineStream & operator<<(StreamFlag flag);
-
-		/// Flush all buffered output.
-		LineStream & flush();
-
-	}; // LineStream
-
-} // CodeGen
-
-#endif // LINE_STREAM_H
