Index: src/Common/Examine.cc
===================================================================
--- src/Common/Examine.cc	(revision ae450071999426853b0ca05d084ca1a2ae0cfc96)
+++ src/Common/Examine.cc	(revision ae450071999426853b0ca05d084ca1a2ae0cfc96)
@@ -0,0 +1,58 @@
+//
+// 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.
+//
+// Examine.h --
+//
+// Author           : Andrew Beach
+// Created On       : Wed Sept 2 14:02 2020
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed Sep  8 12:15 2020
+// Update Count     : 0
+//
+
+#include "Common/Examine.h"
+
+#include "CodeGen/OperatorTable.h"
+
+DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind ) {
+	if (func->name != "main") return nullptr;
+	if (func->type->parameters.size() != 1) return nullptr;
+
+	auto param = func->type->parameters.front();
+
+	auto type = dynamic_cast<ReferenceType * >(param->get_type());
+	if (!type) return nullptr;
+
+	auto obj = dynamic_cast<StructInstType *>(type->base);
+	if (!obj) return nullptr;
+
+	if (kind != obj->baseStruct->kind) return nullptr;
+
+	return param;
+}
+
+namespace {
+	Type * getDestructorParam( FunctionDecl * func ) {
+		if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
+
+		auto params = func->type->parameters;
+		if ( 1 != params.size() ) return nullptr;
+
+		auto ref = dynamic_cast<ReferenceType *>( params.front()->get_type() );
+		if ( ref ) {
+			return ref->base;
+		}
+		return nullptr;
+	}
+}
+
+bool isDestructorFor( FunctionDecl * func, StructDecl * type_decl ) {
+	if ( Type * type = getDestructorParam( func ) ) {
+		auto stype = dynamic_cast<StructInstType *>( type );
+		return stype && stype->baseStruct == type_decl;
+	}
+	return false;
+}
Index: src/Common/Examine.h
===================================================================
--- src/Common/Examine.h	(revision ae450071999426853b0ca05d084ca1a2ae0cfc96)
+++ src/Common/Examine.h	(revision ae450071999426853b0ca05d084ca1a2ae0cfc96)
@@ -0,0 +1,23 @@
+//
+// 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.
+//
+// Examine.h --
+//
+// Author           : Andrew Beach
+// Created On       : Wed Sept 2 13:57 2020
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed Sep  8 12:08 2020
+// Update Count     : 0
+//
+
+#include "SynTree/Declaration.h"
+
+/// Check if this is a main function for a type of an aggregate kind.
+DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind );
+// Returns a pointer to the parameter if true, nullptr otherwise.
+
+/// Check if this function is a destructor for the given structure.
+bool isDestructorFor( FunctionDecl * func, StructDecl * type_decl );
Index: src/Common/module.mk
===================================================================
--- src/Common/module.mk	(revision 5339a87ca7689b734a2eb1d355830ea9713784a1)
+++ src/Common/module.mk	(revision ae450071999426853b0ca05d084ca1a2ae0cfc96)
@@ -22,4 +22,6 @@
       Common/ErrorObjects.h \
       Common/Eval.cc \
+      Common/Examine.cc \
+      Common/Examine.h \
       Common/FilterCombos.h \
       Common/Indenter.h \
