Browse Source

typedef struct and start removing auto

Ginger Bill 8 years ago
parent
commit
aa2bcb166f
12 changed files with 286 additions and 308 deletions
  1. 37 60
      src/checker/checker.cpp
  2. 11 11
      src/checker/entity.cpp
  3. 45 46
      src/checker/expr.cpp
  4. 50 48
      src/checker/types.cpp
  5. 5 5
      src/exact_value.cpp
  6. 2 2
      src/main.cpp
  7. 23 23
      src/parser.cpp
  8. 86 85
      src/ssa.cpp
  9. 9 10
      src/ssa_opt.cpp
  10. 2 2
      src/ssa_print.cpp
  11. 4 4
      src/timings.cpp
  12. 12 12
      src/tokenizer.cpp

+ 37 - 60
src/checker/checker.cpp

@@ -7,7 +7,7 @@
 #define MAP_NAME MapEntity
 #include "../map.c"
 
-enum AddressingMode {
+typedef enum AddressingMode {
 	Addressing_Invalid,
 	Addressing_NoValue,
 	Addressing_Value,
@@ -16,25 +16,25 @@ enum AddressingMode {
 	Addressing_Type,
 	Addressing_Builtin,
 	Addressing_Count,
-};
+} AddressingMode;
 
-struct Operand {
+typedef struct Operand {
 	AddressingMode mode;
 	Type *         type;
 	ExactValue     value;
 	AstNode *      expr;
 	BuiltinProcId  builtin_id;
-};
+} Operand;
 
-struct TypeAndValue {
+typedef struct TypeAndValue {
 	AddressingMode mode;
 	Type *         type;
 	ExactValue     value;
-};
+} TypeAndValue;
 
 
 
-struct DeclInfo {
+typedef struct DeclInfo {
 	Scope *scope;
 
 	Entity **entities;
@@ -46,30 +46,30 @@ struct DeclInfo {
 	u32      var_decl_tags;
 
 	MapBool deps; // Key: Entity *
-};
+} DeclInfo;
 
-struct ExprInfo {
+typedef struct ExprInfo {
 	bool           is_lhs; // Debug info
 	AddressingMode mode;
 	Type *         type; // Type_Basic
 	ExactValue     value;
-};
+} ExprInfo;
 
 ExprInfo make_expr_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue value) {
 	ExprInfo ei = {is_lhs, mode, type, value};
 	return ei;
 }
 
-struct ProcedureInfo {
+typedef struct ProcedureInfo {
 	AstFile * file;
 	Token     token;
 	DeclInfo *decl;
 	Type *    type; // Type_Procedure
 	AstNode * body; // AstNode_BlockStatement
 	u32       tags;
-};
+} ProcedureInfo;
 
-struct Scope {
+typedef struct Scope {
 	Scope *        parent;
 	Scope *        prev, *next;
 	Scope *        first_child;
@@ -84,15 +84,15 @@ struct Scope {
 	bool           is_file;
 	bool           is_init;
 	AstFile *      file;
-};
+} Scope;
 gb_global Scope *universal_scope = NULL;
 
-enum ExprKind {
+typedef enum ExprKind {
 	Expr_Expr,
 	Expr_Stmt,
-};
+} ExprKind;
 
-enum BuiltinProcId {
+typedef enum BuiltinProcId {
 	BuiltinProc_Invalid,
 
 	BuiltinProc_new,
@@ -129,13 +129,13 @@ enum BuiltinProcId {
 	BuiltinProc_enum_to_string,
 
 	BuiltinProc_Count,
-};
-struct BuiltinProc {
+} BuiltinProcId;
+typedef struct BuiltinProc {
 	String   name;
 	isize    arg_count;
 	bool      variadic;
 	ExprKind kind;
-};
+} BuiltinProc;
 gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
 	{STR_LIT(""),                 0, false, Expr_Stmt},
 
@@ -173,28 +173,28 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
 	{STR_LIT("enum_to_string"),   1, false, Expr_Expr},
 };
 
-enum ImplicitValueId {
+typedef enum ImplicitValueId {
 	ImplicitValue_Invalid,
 
 	ImplicitValue_context,
 
 	ImplicitValue_Count,
-};
-struct ImplicitValueInfo {
+} ImplicitValueId;
+typedef struct ImplicitValueInfo {
 	String  name;
 	String  backing_name;
 	Type *  type;
-};
+} ImplicitValueInfo;
 // NOTE(bill): This is initialized later
 gb_global ImplicitValueInfo implicit_value_infos[ImplicitValue_Count] = {};
 
 
 
-struct CheckerContext {
+typedef struct CheckerContext {
 	Scope *   scope;
 	DeclInfo *decl;
 	u32       stmt_state_flags;
-};
+} CheckerContext;
 
 #define MAP_TYPE TypeAndValue
 #define MAP_FUNC map_tav_
@@ -223,7 +223,7 @@ struct CheckerContext {
 
 
 // NOTE(bill): Symbol tables
-struct CheckerInfo {
+typedef struct CheckerInfo {
 	MapTypeAndValue     types;           // Key: AstNode * | Expression -> Type (and value)
 	MapEntity           definitions;     // Key: AstNode * | Identifier -> Entity
 	MapEntity           uses;            // Key: AstNode * | Identifier -> Entity
@@ -235,9 +235,9 @@ struct CheckerInfo {
 	MapIsize            type_info_map;   // Key: Type *
 	isize               type_info_count;
 	Entity *            implicit_values[ImplicitValue_Count];
-};
+} CheckerInfo;
 
-struct Checker {
+typedef struct Checker {
 	Parser *    parser;
 	CheckerInfo info;
 
@@ -255,11 +255,11 @@ struct Checker {
 
 	Array(Type *)          proc_stack;
 	bool                    in_defer; // TODO(bill): Actually handle correctly
-};
+} Checker;
 
-struct CycleChecker {
+typedef struct CycleChecker {
 	Array(Entity *) path; // Entity_TypeName
-};
+} CycleChecker;
 
 
 
@@ -766,7 +766,7 @@ void add_type_info_type(Checker *c, Type *t) {
 
 	isize ti_index = -1;
 	for_array(i, c->info.type_info_map.entries) {
-		auto *e = &c->info.type_info_map.entries.e[i];
+		MapIsizeEntry *e = &c->info.type_info_map.entries.e[i];
 		Type *prev_type = cast(Type *)e->key.ptr;
 		if (are_types_identical(t, prev_type)) {
 			// Duplicate entry
@@ -931,7 +931,7 @@ MapEntity generate_minimum_dependency_map(CheckerInfo *info, Entity *start) {
 	map_entity_init(&map, heap_allocator());
 
 	for_array(i, info->entities.entries) {
-		auto *entry = &info->entities.entries.e[i];
+		MapDeclInfoEntry *entry = &info->entities.entries.e[i];
 		Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
 		if (e->scope->is_global) {
 			// NOTE(bill): Require runtime stuff
@@ -1023,7 +1023,7 @@ void add_implicit_value(Checker *c, ImplicitValueId id, String name, String back
 
 void check_global_entity(Checker *c, EntityKind kind) {
 	for_array(i, c->info.entities.entries) {
-		auto *entry = &c->info.entities.entries.e[i];
+		MapDeclInfoEntry *entry = &c->info.entities.entries.e[i];
 		Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
 		if (e->kind == kind) {
 			DeclInfo *d = entry->value;
@@ -1203,7 +1203,7 @@ void check_parsed_files(Checker *c) {
 			ast_node(id, ImportDecl, decl);
 
 			HashKey key = hash_string(id->fullpath);
-			auto found = map_scope_get(&file_scopes, key);
+			Scope **found = map_scope_get(&file_scopes, key);
 			GB_ASSERT_MSG(found != NULL, "Unable to find scope for file: %.*s", LIT(id->fullpath));
 			Scope *scope = *found;
 
@@ -1338,7 +1338,7 @@ void check_parsed_files(Checker *c) {
 
 	// Add untyped expression values
 	for_array(i, c->info.untyped.entries) {
-		auto *entry = &c->info.untyped.entries.e[i];
+		MapExprInfoEntry *entry = &c->info.untyped.entries.e[i];
 		HashKey key = entry->key;
 		AstNode *expr = cast(AstNode *)cast(uintptr)key.key;
 		ExprInfo *info = &entry->value;
@@ -1364,29 +1364,6 @@ void check_parsed_files(Checker *c) {
 		}
 	}
 
-	// for_array(i, c->info.type_info_map.entries) {
-	// 	auto *e = &c->info.type_info_map.entries[i];
-	// 	Type *prev_type = cast(Type *)e->key.ptr;
-	// 	gb_printf("%td - %s\n", i, type_to_string(prev_type));
-	// }
-
-	// for_array(i, c->info.type_info_map.entries) {
-	// 	auto *p = &c->info.type_info_map.entries[i];
-	// 	for (isize j = 0; j < i-1; j++) {
-	// 		auto *q = &c->info.type_info_map.entries[j];
-	// 		Type *a = cast(Type *)p->key.ptr;
-	// 		Type *b = cast(Type *)q->key.ptr;
-	// 		p->value = i;
-	// 		// GB_ASSERT(!are_types_identical(a, b));
-	// 	}
-	// }
-
-	// for_array(i, c->info.type_info_map.entries) {
-	// 	auto *e = &c->info.type_info_map.entries[i];
-	// 	Type *prev_type = cast(Type *)e->key.ptr;
-	// 	gb_printf("%td - %s\n", e->value, type_to_string(prev_type));
-	// }
-
 	map_scope_destroy(&file_scopes);
 	array_free(&import_decls);
 }

+ 11 - 11
src/checker/entity.cpp

@@ -1,8 +1,8 @@
-struct Scope;
-struct Checker;
-struct Type;
-enum BuiltinProcId;
-enum ImplicitValueId;
+typedef struct Scope Scope;
+typedef struct Checker Checker;
+typedef struct Type Type;
+typedef enum BuiltinProcId BuiltinProcId;
+typedef enum ImplicitValueId ImplicitValueId;
 
 #define ENTITY_KINDS \
 	ENTITY_KIND(Invalid) \
@@ -16,11 +16,11 @@ enum ImplicitValueId;
 	ENTITY_KIND(ImplicitValue) \
 	ENTITY_KIND(Count)
 
-enum EntityKind {
+typedef enum EntityKind {
 #define ENTITY_KIND(k) GB_JOIN2(Entity_, k),
 	ENTITY_KINDS
 #undef ENTITY_KIND
-};
+} EntityKind;
 
 String const entity_strings[] = {
 #define ENTITY_KIND(k) {cast(u8 *)#k, gb_size_of(#k)-1},
@@ -28,16 +28,16 @@ String const entity_strings[] = {
 #undef ENTITY_KIND
 };
 
-enum EntityFlag : u32 {
+typedef enum EntityFlag {
 	EntityFlag_Visited    = 1<<0,
 	EntityFlag_Used       = 1<<1,
 	EntityFlag_Anonymous  = 1<<2,
 	EntityFlag_Field      = 1<<3,
 	EntityFlag_Param      = 1<<4,
 	EntityFlag_VectorElem = 1<<5,
-};
+} EntityFlag;
 
-struct Entity {
+typedef struct Entity {
 	EntityKind kind;
 	u32        flags;
 	Token      token;
@@ -75,7 +75,7 @@ struct Entity {
 			Entity *        backing;
 		} ImplicitValue;
 	};
-};
+} Entity;
 
 bool is_entity_exported(Entity *e) {
 	if (e->kind == Entity_ImportName) {

+ 45 - 46
src/checker/expr.cpp

@@ -3573,6 +3573,49 @@ void check_expr_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t) {
 	}
 }
 
+bool check_set_index_data(Operand *o, Type *t, i64 *max_count) {
+	t = base_type(type_deref(t));
+
+	switch (t->kind) {
+	case Type_Basic:
+		if (is_type_string(t)) {
+			if (o->mode == Addressing_Constant) {
+				*max_count = o->value.value_string.len;
+			}
+			if (o->mode != Addressing_Variable) {
+				o->mode = Addressing_Value;
+			}
+			o->type = t_u8;
+			return true;
+		}
+		break;
+
+	case Type_Array:
+		*max_count = t->Array.count;
+		if (o->mode != Addressing_Variable) {
+			o->mode = Addressing_Value;
+		}
+		o->type = t->Array.elem;
+		return true;
+
+	case Type_Vector:
+		*max_count = t->Vector.count;
+		if (o->mode != Addressing_Variable) {
+			o->mode = Addressing_Value;
+		}
+		o->type = t->Vector.elem;
+		return true;
+
+
+	case Type_Slice:
+		o->type = t->Slice.elem;
+		o->mode = Addressing_Variable;
+		return true;
+	}
+
+	return false;
+}
+
 ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) {
 	ExprKind kind = Expr_Stmt;
 
@@ -3892,52 +3935,8 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
 		Type *t = base_type(type_deref(o->type));
 		bool is_const = o->mode == Addressing_Constant;
 
-
-		auto set_index_data = [](Operand *o, Type *t, i64 *max_count) -> bool {
-			t = base_type(type_deref(t));
-
-			switch (t->kind) {
-			case Type_Basic:
-				if (is_type_string(t)) {
-					if (o->mode == Addressing_Constant) {
-						*max_count = o->value.value_string.len;
-					}
-					if (o->mode != Addressing_Variable) {
-						o->mode = Addressing_Value;
-					}
-					o->type = t_u8;
-					return true;
-				}
-				break;
-
-			case Type_Array:
-				*max_count = t->Array.count;
-				if (o->mode != Addressing_Variable) {
-					o->mode = Addressing_Value;
-				}
-				o->type = t->Array.elem;
-				return true;
-
-			case Type_Vector:
-				*max_count = t->Vector.count;
-				if (o->mode != Addressing_Variable) {
-					o->mode = Addressing_Value;
-				}
-				o->type = t->Vector.elem;
-				return true;
-
-
-			case Type_Slice:
-				o->type = t->Slice.elem;
-				o->mode = Addressing_Variable;
-				return true;
-			}
-
-			return false;
-		};
-
 		i64 max_count = -1;
-		bool valid = set_index_data(o, t, &max_count);
+		bool valid = check_set_index_data(o, t, &max_count);
 
 		if (is_const) {
 			valid = false;
@@ -3946,7 +3945,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
 		if (!valid && (is_type_struct(t) || is_type_raw_union(t))) {
 			Entity *found = find_using_index_expr(t);
 			if (found != NULL) {
-				valid = set_index_data(o, found->type, &max_count);
+				valid = check_set_index_data(o, found->type, &max_count);
 			}
 		}
 

+ 50 - 48
src/checker/types.cpp

@@ -1,6 +1,6 @@
-struct Scope;
+typedef struct Scope Scope;
 
-enum BasicKind {
+typedef enum BasicKind {
 	Basic_Invalid,
 	Basic_bool,
 	Basic_i8,
@@ -34,9 +34,9 @@ enum BasicKind {
 
 	Basic_byte = Basic_u8,
 	Basic_rune = Basic_i32,
-};
+} BasicKind;
 
-enum BasicFlag : u32 {
+typedef enum BasicFlag {
 	BasicFlag_Boolean  = GB_BIT(0),
 	BasicFlag_Integer  = GB_BIT(1),
 	BasicFlag_Unsigned = GB_BIT(2),
@@ -49,14 +49,14 @@ enum BasicFlag : u32 {
 	BasicFlag_Numeric      = BasicFlag_Integer | BasicFlag_Float,
 	BasicFlag_Ordered      = BasicFlag_Numeric | BasicFlag_String  | BasicFlag_Pointer,
 	BasicFlag_ConstantType = BasicFlag_Boolean | BasicFlag_Numeric | BasicFlag_Pointer | BasicFlag_String | BasicFlag_Rune,
-};
+} BasicFlag;
 
-struct BasicType {
+typedef struct BasicType {
 	BasicKind kind;
 	u32       flags;
 	i64       size; // -1 if arch. dep.
 	String    name;
-};
+} BasicType;
 
 
 
@@ -74,19 +74,19 @@ struct BasicType {
 	TYPE_KIND(Proc), \
 	TYPE_KIND(Count),
 
-enum TypeKind {
-#define TYPE_KIND(k) GB_JOIN2(Type_, k)
+typedef enum TypeKind {
+#define TYPE_KIND(k, ...) GB_JOIN2(Type_, k)
 	TYPE_KINDS
 #undef TYPE_KIND
-};
+} TypeKind;
 
 String const type_strings[] = {
-#define TYPE_KIND(k) {cast(u8 *)#k, gb_size_of(#k)-1}
+#define TYPE_KIND(k, ...) {cast(u8 *)#k, gb_size_of(#k)-1}
 	TYPE_KINDS
 #undef TYPE_KIND
 };
 
-enum TypeRecordKind {
+typedef enum TypeRecordKind {
 	TypeRecord_Invalid,
 
 	TypeRecord_Struct,
@@ -95,9 +95,9 @@ enum TypeRecordKind {
 	TypeRecord_Union, // Tagged
 
 	TypeRecord_Count,
-};
+} TypeRecordKind;
 
-struct Type {
+typedef struct Type {
 	TypeKind kind;
 	union {
 		BasicType Basic;
@@ -167,7 +167,42 @@ struct Type {
 			bool    variadic;
 		} Proc;
 	};
-};
+} Type;
+
+// NOTE(bill): Internal sizes of certain types
+// string: 2*word_size  (ptr+len)
+// slice:  3*word_size  (ptr+len+cap)
+// array:  count*size_of(elem) aligned
+
+// NOTE(bill): Alignment of structures and other types are to be compatible with C
+
+typedef struct BaseTypeSizes {
+	i64 word_size;
+	i64 max_align;
+} BaseTypeSizes;
+
+typedef Array(isize) Array_isize;
+
+typedef struct Selection {
+	Entity *    entity;
+	Array_isize index;
+	bool         indirect; // Set if there was a pointer deref anywhere down the line
+} Selection;
+Selection empty_selection = {};
+
+Selection make_selection(Entity *entity, Array_isize index, bool indirect) {
+	Selection s = {entity, index, indirect};
+	return s;
+}
+
+void selection_add_index(Selection *s, isize index) {
+	// IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form
+	// of heap allocation
+	if (s->index.e == NULL) {
+		array_init(&s->index, heap_allocator());
+	}
+	array_add(&s->index, index);
+}
 
 
 
@@ -793,40 +828,7 @@ Type *default_type(Type *type) {
 }
 
 
-// NOTE(bill): Internal sizes of certain types
-// string: 2*word_size  (ptr+len)
-// slice:  3*word_size  (ptr+len+cap)
-// array:  count*size_of(elem) aligned
-
-// NOTE(bill): Alignment of structures and other types are to be compatible with C
-
-struct BaseTypeSizes {
-	i64 word_size;
-	i64 max_align;
-};
-
-typedef Array(isize) Array_isize;
-
-struct Selection {
-	Entity *    entity;
-	Array_isize index;
-	bool         indirect; // Set if there was a pointer deref anywhere down the line
-};
-Selection empty_selection = {};
-
-Selection make_selection(Entity *entity, Array_isize index, bool indirect) {
-	Selection s = {entity, index, indirect};
-	return s;
-}
 
-void selection_add_index(Selection *s, isize index) {
-	// IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form
-	// of heap allocation
-	if (s->index.e == NULL) {
-		array_init(&s->index, heap_allocator());
-	}
-	array_add(&s->index, index);
-}
 
 gb_global Entity *entity__any_type_info  = NULL;
 gb_global Entity *entity__any_data       = NULL;

+ 5 - 5
src/exact_value.cpp

@@ -3,9 +3,9 @@
 // TODO(bill): Big numbers
 // IMPORTANT TODO(bill): This needs to be completely fixed!!!!!!!!
 
-struct AstNode;
+typedef struct AstNode AstNode;
 
-enum ExactValueKind {
+typedef enum ExactValueKind {
 	ExactValue_Invalid,
 
 	ExactValue_Bool,
@@ -16,9 +16,9 @@ enum ExactValueKind {
 	ExactValue_Compound, // TODO(bill): Is this good enough?
 
 	ExactValue_Count,
-};
+} ExactValueKind;
 
-struct ExactValue {
+typedef struct ExactValue {
 	ExactValueKind kind;
 	union {
 		bool      value_bool;
@@ -28,7 +28,7 @@ struct ExactValue {
 		i64      value_pointer;
 		AstNode *value_compound;
 	};
-};
+} ExactValue;
 
 HashKey hash_exact_value(ExactValue v) {
 	return hashing_proc(&v, gb_size_of(ExactValue));

+ 2 - 2
src/main.cpp

@@ -56,12 +56,12 @@ i32 win32_exec_command_line_app(char *name, char *fmt, ...) {
 	return exit_code;
 }
 
-typedef enum {
+typedef enum ArchKind {
 	ArchKind_x64,
 	ArchKind_x86,
 } ArchKind;
 
-typedef struct  {
+typedef struct ArchData {
 	BaseTypeSizes sizes;
 	String llc_flags;
 	String link_flags;

+ 23 - 23
src/parser.cpp

@@ -1,8 +1,8 @@
-struct AstNode;
-struct Scope;
-struct DeclInfo;
+typedef struct AstNode AstNode;
+typedef struct Scope Scope;
+typedef struct DeclInfo DeclInfo;
 
-enum ParseFileError {
+typedef enum ParseFileError {
 	ParseFile_None,
 
 	ParseFile_WrongExtension,
@@ -13,11 +13,11 @@ enum ParseFileError {
 	ParseFile_InvalidToken,
 
 	ParseFile_Count,
-};
+} ParseFileError;
 
 typedef Array(AstNode *) AstNodeArray;
 
-struct AstFile {
+typedef struct AstFile {
 	i32            id;
 	gbArena        arena;
 	Tokenizer      tokenizer;
@@ -43,15 +43,15 @@ struct AstFile {
 #define PARSER_MAX_FIX_COUNT 6
 	isize    fix_count;
 	TokenPos fix_prev_pos;
-};
+} AstFile;
 
-struct ImportedFile {
+typedef struct ImportedFile {
 	String   path;
 	String   rel_path;
 	TokenPos pos; // #import
-};
+} ImportedFile;
 
-struct Parser {
+typedef struct Parser {
 	String              init_fullpath;
 	Array(AstFile)      files;
 	Array(ImportedFile) imports;
@@ -59,9 +59,9 @@ struct Parser {
 	Array(String)       foreign_libraries;
 	isize               total_token_count;
 	gbMutex             mutex;
-};
+} Parser;
 
-enum ProcTag : u64 {
+typedef enum ProcTag {
 	ProcTag_bounds_check    = GB_BIT(0),
 	ProcTag_no_bounds_check = GB_BIT(1),
 
@@ -75,23 +75,23 @@ enum ProcTag : u64 {
 	ProcTag_stdcall         = GB_BIT(16),
 	ProcTag_fastcall        = GB_BIT(17),
 	// ProcTag_cdecl           = GB_BIT(18),
-};
+} ProcTag;
 
-enum VarDeclTag {
+typedef enum VarDeclTag {
 	VarDeclTag_thread_local = GB_BIT(0),
-};
+} VarDeclTag;
 
-enum StmtStateFlag : u32 {
+typedef enum StmtStateFlag {
 	StmtStateFlag_bounds_check    = GB_BIT(0),
 	StmtStateFlag_no_bounds_check = GB_BIT(1),
-};
+} StmtStateFlag;
 
 
-enum CallExprKind {
+typedef enum CallExprKind {
 	CallExpr_Prefix,  // call(...)
 	CallExpr_Postfix, // a'call
 	CallExpr_Infix,   // a ''call b
-};
+} CallExprKind;
 
 AstNodeArray make_ast_node_array(AstFile *f) {
 	AstNodeArray a;
@@ -320,11 +320,11 @@ AST_NODE_KIND(_TypeBegin, "", struct{}) \
 AST_NODE_KIND(_TypeEnd,  "", struct{}) \
 	AST_NODE_KIND(Count, "", struct{})
 
-enum AstNodeKind {
+typedef enum AstNodeKind {
 #define AST_NODE_KIND(_kind_name_, ...) GB_JOIN2(AstNode_, _kind_name_),
 	AST_NODE_KINDS
 #undef AST_NODE_KIND
-};
+} AstNodeKind;
 
 String const ast_node_strings[] = {
 #define AST_NODE_KIND(_kind_name_, name, ...) {cast(u8 *)name, gb_size_of(name)-1},
@@ -336,7 +336,7 @@ String const ast_node_strings[] = {
 	AST_NODE_KINDS
 #undef AST_NODE_KIND
 
-struct AstNode {
+typedef struct AstNode {
 	AstNodeKind kind;
 	// AstNode *prev, *next; // NOTE(bill): allow for Linked list
 	u32 stmt_state_flags;
@@ -345,7 +345,7 @@ struct AstNode {
 	AST_NODE_KINDS
 #undef AST_NODE_KIND
 	};
-};
+} AstNode;
 
 
 #define ast_node(n_, Kind_, node_) GB_JOIN2(AstNode, Kind_) *n_ = &(node_)->Kind_; GB_ASSERT((node_)->kind == GB_JOIN2(AstNode_, Kind_))

+ 86 - 85
src/ssa.cpp

@@ -15,7 +15,7 @@ typedef Array(ssaValue *) ssaValueArray;
 #define MAP_NAME MapSsaDebugInfo
 #include "map.c"
 
-struct ssaModule {
+typedef struct ssaModule {
 	CheckerInfo * info;
 	BaseTypeSizes sizes;
 	gbArena       arena;
@@ -41,17 +41,17 @@ struct ssaModule {
 
 	Array(ssaProcedure *) procs;             // NOTE(bill): All procedures with bodies
 	ssaValueArray         procs_to_generate; // NOTE(bill): Procedures to generate
-};
+} ssaModule;
 
 // NOTE(bill): For more info, see https://en.wikipedia.org/wiki/Dominator_(graph_theory)
-struct ssaDomNode {
+typedef struct ssaDomNode {
 	ssaBlock *        idom; // Parent (Immediate Dominator)
 	Array(ssaBlock *) children;
 	i32               pre, post; // Ordering in tree
-};
+} ssaDomNode;
 
 
-struct ssaBlock {
+typedef struct ssaBlock {
 	i32           index;
 	String        label;
 	ssaProcedure *parent;
@@ -66,8 +66,9 @@ struct ssaBlock {
 
 	Array(ssaBlock *) preds;
 	Array(ssaBlock *) succs;
-};
+} ssaBlock;
 
+typedef struct ssaTargetList ssaTargetList;
 struct ssaTargetList {
 	ssaTargetList *prev;
 	ssaBlock *     break_;
@@ -75,17 +76,17 @@ struct ssaTargetList {
 	ssaBlock *     fallthrough_;
 };
 
-enum ssaDeferExitKind {
+typedef enum ssaDeferExitKind {
 	ssaDeferExit_Default,
 	ssaDeferExit_Return,
 	ssaDeferExit_Branch,
-};
-enum ssaDeferKind {
+} ssaDeferExitKind;
+typedef enum ssaDeferKind {
 	ssaDefer_Node,
 	ssaDefer_Instr,
-};
+} ssaDeferKind;
 
-struct ssaDefer {
+typedef struct ssaDefer {
 	ssaDeferKind kind;
 	isize        scope_index;
 	ssaBlock *   block;
@@ -94,8 +95,9 @@ struct ssaDefer {
 		// NOTE(bill): `instr` will be copied every time to create a new one
 		ssaValue *instr;
 	};
-};
+} ssaDefer;
 
+typedef struct ssaProcedure ssaProcedure;
 struct ssaProcedure {
 	ssaProcedure *        parent;
 	Array(ssaProcedure *) children;
@@ -172,11 +174,11 @@ struct ssaProcedure {
 	SSA_CONV_KIND(inttoptr), \
 	SSA_CONV_KIND(bitcast),
 
-enum ssaInstrKind {
+typedef enum ssaInstrKind {
 #define SSA_INSTR_KIND(x) GB_JOIN2(ssaInstr_, x)
 	SSA_INSTR_KINDS
 #undef SSA_INSTR_KIND
-};
+} ssaInstrKind;
 
 String const ssa_instr_strings[] = {
 #define SSA_INSTR_KIND(x) {cast(u8 *)#x, gb_size_of(#x)-1}
@@ -184,11 +186,11 @@ String const ssa_instr_strings[] = {
 #undef SSA_INSTR_KIND
 };
 
-enum ssaConvKind {
+typedef enum ssaConvKind {
 #define SSA_CONV_KIND(x) GB_JOIN2(ssaConv_, x)
 	SSA_CONV_KINDS
 #undef SSA_CONV_KIND
-};
+} ssaConvKind;
 
 String const ssa_conv_strings[] = {
 #define SSA_CONV_KIND(x) {cast(u8 *)#x, gb_size_of(#x)-1}
@@ -196,6 +198,7 @@ String const ssa_conv_strings[] = {
 #undef SSA_CONV_KIND
 };
 
+typedef struct ssaInstr ssaInstr;
 struct ssaInstr {
 	ssaInstrKind kind;
 
@@ -330,7 +333,7 @@ struct ssaInstr {
 };
 
 
-enum ssaValueKind {
+typedef enum ssaValueKind {
 	ssaValue_Invalid,
 
 	ssaValue_Constant,
@@ -345,9 +348,9 @@ enum ssaValueKind {
 	ssaValue_Instr,
 
 	ssaValue_Count,
-};
+} ssaValueKind;
 
-struct ssaValue {
+typedef struct ssaValue {
 	ssaValueKind kind;
 	i32 index;
 	union {
@@ -387,7 +390,7 @@ struct ssaValue {
 		ssaBlock     Block;
 		ssaInstr     Instr;
 	};
-};
+} ssaValue;
 
 gb_global ssaValue *v_zero    = NULL;
 gb_global ssaValue *v_one     = NULL;
@@ -397,19 +400,19 @@ gb_global ssaValue *v_two32   = NULL;
 gb_global ssaValue *v_false   = NULL;
 gb_global ssaValue *v_true    = NULL;
 
-enum ssaAddrKind {
+typedef enum ssaAddrKind {
 	ssaAddr_Default,
 	ssaAddr_Vector,
-};
+} ssaAddrKind;
 
-struct ssaAddr {
+typedef struct ssaAddr {
 	ssaValue *  addr;
 	AstNode *   expr; // NOTE(bill): Just for testing - probably remove later
 	ssaAddrKind kind;
 	union {
 		struct { ssaValue *index; } Vector;
 	};
-};
+} ssaAddr;
 
 ssaAddr ssa_make_addr(ssaValue *addr, AstNode *expr) {
 	ssaAddr v = {addr, expr};
@@ -424,7 +427,7 @@ ssaAddr ssa_make_addr_vector(ssaValue *addr, ssaValue *index, AstNode *expr) {
 
 
 
-enum ssaDebugEncoding {
+typedef enum ssaDebugEncoding {
 	ssaDebugBasicEncoding_Invalid       = 0,
 
 	ssaDebugBasicEncoding_address       = 1,
@@ -444,9 +447,9 @@ enum ssaDebugEncoding {
 	ssaDebugBasicEncoding_structure_type   = 19,
 	ssaDebugBasicEncoding_union_type       = 23,
 
-};
+} ssaDebugEncoding;
 
-enum ssaDebugInfoKind {
+typedef enum ssaDebugInfoKind {
 	ssaDebugInfo_Invalid,
 
 	ssaDebugInfo_CompileUnit,
@@ -465,8 +468,9 @@ enum ssaDebugInfoKind {
 
 
 	ssaDebugInfo_Count,
-};
+} ssaDebugInfoKind;
 
+typedef struct ssaDebugInfo ssaDebugInfo;
 struct ssaDebugInfo {
 	ssaDebugInfoKind kind;
 	i32 id;
@@ -547,11 +551,11 @@ struct ssaDebugInfo {
 	};
 };
 
-struct ssaGen {
+typedef struct ssaGen {
 	ssaModule module;
 	gbFile    output_file;
 	bool       opt_called;
-};
+} ssaGen;
 
 ssaValue *ssa_lookup_member(ssaModule *m, String name) {
 	ssaValue **v = map_ssa_value_get(&m->members, hash_string(name));
@@ -2348,7 +2352,7 @@ isize ssa_type_info_index(CheckerInfo *info, Type *type) {
 		// NOTE(bill): Do manual search
 		// TODO(bill): This is O(n) and can be very slow
 		for_array(i, info->type_info_map.entries){
-			auto *e = &info->type_info_map.entries.e[i];
+			MapIsizeEntry *e = &info->type_info_map.entries.e[i];
 			Type *prev_type = cast(Type *)e->key.ptr;
 			if (are_types_identical(prev_type, type)) {
 				entry_index = e->value;
@@ -3277,6 +3281,18 @@ ssaValue *ssa_add_using_variable(ssaProcedure *proc, Entity *e) {
 	return var;
 }
 
+bool ssa_is_elem_const(ssaModule *m, AstNode *elem, Type *elem_type) {
+	if (base_type(elem_type) == t_any) {
+		return false;
+	}
+	if (elem->kind == AstNode_FieldValue) {
+		elem = elem->FieldValue.value;
+	}
+	TypeAndValue *tav = type_and_value_of_expression(m->info, elem);
+	GB_ASSERT(tav != NULL);
+	return tav->value.kind != ExactValue_Invalid;
+}
+
 ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 	switch (expr->kind) {
 	case_ast_node(i, Ident, expr);
@@ -3608,18 +3624,6 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 		case Type_Slice:  et = bt->Slice.elem;  break;
 		}
 
-		auto is_elem_const = [](ssaModule *m, AstNode *elem, Type *elem_type) -> bool {
-			if (base_type(elem_type) == t_any) {
-				return false;
-			}
-			if (elem->kind == AstNode_FieldValue) {
-				elem = elem->FieldValue.value;
-			}
-			TypeAndValue *tav = type_and_value_of_expression(m->info, elem);
-			GB_ASSERT(tav != NULL);
-			return tav->value.kind != ExactValue_Invalid;
-		};
-
 		switch (bt->kind) {
 		default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break;
 
@@ -3627,7 +3631,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 			ssaValue *result = ssa_add_module_constant(proc->module, type, make_exact_value_compound(expr));
 			for_array(index, cl->elems) {
 				AstNode *elem = cl->elems.e[index];
-				if (is_elem_const(proc->module, elem, et)) {
+				if (ssa_is_elem_const(proc->module, elem, et)) {
 					continue;
 				}
 				ssaValue *field_elem = ssa_build_expr(proc, elem);
@@ -3675,7 +3679,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 					}
 
 					field = st->fields[index];
-					if (is_elem_const(proc->module, elem, field->type)) {
+					if (ssa_is_elem_const(proc->module, elem, field->type)) {
 						continue;
 					}
 
@@ -3695,7 +3699,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 				ssa_emit_store(proc, v, ssa_add_module_constant(proc->module, type, make_exact_value_compound(expr)));
 				for_array(i, cl->elems) {
 					AstNode *elem = cl->elems.e[i];
-					if (is_elem_const(proc->module, elem, et)) {
+					if (ssa_is_elem_const(proc->module, elem, et)) {
 						continue;
 					}
 					ssaValue *field_expr = ssa_build_expr(proc, elem);
@@ -3719,7 +3723,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
 
 				for_array(i, cl->elems) {
 					AstNode *elem = cl->elems.e[i];
-					if (is_elem_const(proc->module, elem, et)) {
+					if (ssa_is_elem_const(proc->module, elem, et)) {
 						continue;
 					}
 
@@ -3911,7 +3915,7 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) {
 
 	case_ast_node(pd, ProcDecl, node);
 		if (pd->body != NULL) {
-			auto *info = proc->module->info;
+			CheckerInfo *info = proc->module->info;
 
 			Entity **found = map_entity_get(&info->definitions, hash_pointer(pd->name));
 			GB_ASSERT_MSG(found != NULL, "Unable to find: %.*s", LIT(pd->name->Ident.string));
@@ -3948,7 +3952,7 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) {
 			array_add(&proc->children, &value->Proc);
 			array_add(&proc->module->procs_to_generate, value);
 		} else {
-			auto *info = proc->module->info;
+			CheckerInfo *info = proc->module->info;
 
 			Entity **found = map_entity_get(&info->definitions, hash_pointer(pd->name));
 			GB_ASSERT_MSG(found != NULL, "Unable to find: %.*s", LIT(pd->name->Ident.string));
@@ -4709,7 +4713,7 @@ void ssa_init_module(ssaModule *m, Checker *c) {
 			isize count = 0;
 
 			for_array(entry_index, m->info->type_info_map.entries) {
-				auto *entry = &m->info->type_info_map.entries.e[entry_index];
+				MapIsizeEntry *entry = &m->info->type_info_map.entries.e[entry_index];
 				Type *t = cast(Type *)cast(uintptr)entry->key.key;
 
 				switch (t->kind) {
@@ -4824,6 +4828,17 @@ String ssa_mangle_name(ssaGen *s, String path, String name) {
 	return make_string(new_name, new_name_len-1);
 }
 
+ssaValue *ssa_get_type_info_ptr(ssaProcedure *proc, ssaValue *type_info_data, Type *type) {
+	i32 index = cast(i32)ssa_type_info_index(proc->module->info, type);
+	// gb_printf_err("%d %s\n", index, type_to_string(type));
+	return ssa_emit_array_ep(proc, type_info_data, index);
+}
+
+ssaValue *ssa_type_info_member_offset(ssaProcedure *proc, ssaValue *data, isize count, i32 *index) {
+	ssaValue *offset = ssa_emit_array_ep(proc, data, *index);
+	*index += count;
+	return offset;
+}
 
 void ssa_gen_tree(ssaGen *s) {
 	ssaModule *m = &s->module;
@@ -4844,7 +4859,7 @@ void ssa_gen_tree(ssaGen *s) {
 	Entity *entry_point = NULL;
 
 	for_array(i, info->entities.entries) {
-		auto *entry = &info->entities.entries.e[i];
+		MapDeclInfoEntry *entry = &info->entities.entries.e[i];
 		Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
 		String name = e->token.string;
 		if (e->kind == Entity_Variable) {
@@ -4866,7 +4881,7 @@ void ssa_gen_tree(ssaGen *s) {
 	m->min_dep_map = generate_minimum_dependency_map(info, entry_point);
 
 	for_array(i, info->entities.entries) {
-		auto *entry = &info->entities.entries.e[i];
+		MapDeclInfoEntry *entry = &info->entities.entries.e[i];
 		Entity *e = cast(Entity *)entry->key.ptr;
 		String name = e->token.string;
 		DeclInfo *decl = entry->value;
@@ -4948,7 +4963,7 @@ void ssa_gen_tree(ssaGen *s) {
 	}
 
 	for_array(i, m->members.entries) {
-		auto *entry = &m->members.entries.e[i];
+		MapSsaValueEntry *entry = &m->members.entries.e[i];
 		ssaValue *v = entry->value;
 		if (v->kind == ssaValue_Proc)
 			ssa_build_proc(v, NULL);
@@ -4960,7 +4975,7 @@ void ssa_gen_tree(ssaGen *s) {
 
 	isize all_proc_max_count = 0;
 	for_array(i, m->debug_info.entries) {
-		auto *entry = &m->debug_info.entries.e[i];
+		MapSsaDebugInfoEntry *entry = &m->debug_info.entries.e[i];
 		ssaDebugInfo *di = entry->value;
 		di->id = i;
 		if (di->kind == ssaDebugInfo_Proc) {
@@ -4974,7 +4989,7 @@ void ssa_gen_tree(ssaGen *s) {
 
 
 	for_array(i, m->debug_info.entries) {
-		auto *entry = &m->debug_info.entries.e[i];
+		MapSsaDebugInfoEntry *entry = &m->debug_info.entries.e[i];
 		ssaDebugInfo *di = entry->value;
 		di->id = i;
 		if (di->kind == ssaDebugInfo_Proc) {
@@ -5050,24 +5065,10 @@ void ssa_gen_tree(ssaGen *s) {
 			Type *t_i64_slice_ptr    = make_type_pointer(a, make_type_slice(a, t_i64));
 			Type *t_string_slice_ptr = make_type_pointer(a, make_type_slice(a, t_string));
 
-			auto get_type_info_ptr = [](ssaProcedure *proc, ssaValue *type_info_data, Type *type) -> ssaValue * {
-				i32 index = cast(i32)ssa_type_info_index(proc->module->info, type);
-				// gb_printf_err("%d %s\n", index, type_to_string(type));
-				return ssa_emit_array_ep(proc, type_info_data, index);
-			};
-
 			i32 type_info_member_index = 0;
 
-			auto type_info_member_offset = [](ssaProcedure *proc, ssaValue *data, isize count, i32 *index) -> ssaValue * {
-				ssaValue *offset = ssa_emit_array_ep(proc, data, *index);
-				*index += count;
-				return offset;
-			};
-
-
-
 			for_array(type_info_map_index, info->type_info_map.entries) {
-				auto *entry = &info->type_info_map.entries.e[type_info_map_index];
+				MapIsizeEntry *entry = &info->type_info_map.entries.e[type_info_map_index];
 				Type *t = cast(Type *)cast(uintptr)entry->key.key;
 				t = default_type(t);
 				isize entry_index = entry->value;
@@ -5080,7 +5081,7 @@ void ssa_gen_tree(ssaGen *s) {
 
 					// TODO(bill): Which is better? The mangled name or actual name?
 					ssaValue *name = ssa_make_const_string(a, t->Named.type_name->token.string);
-					ssaValue *gtip = get_type_info_ptr(proc, type_info_data, t->Named.base);
+					ssaValue *gtip = ssa_get_type_info_ptr(proc, type_info_data, t->Named.base);
 
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), name);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 1), gtip);
@@ -5137,17 +5138,17 @@ void ssa_gen_tree(ssaGen *s) {
 
 				case Type_Pointer: {
 					tag = ssa_add_local_generated(proc, t_type_info_pointer);
-					ssaValue *gep = get_type_info_ptr(proc, type_info_data, t->Pointer.elem);
+					ssaValue *gep = ssa_get_type_info_ptr(proc, type_info_data, t->Pointer.elem);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), gep);
 				} break;
 				case Type_Maybe: {
 					tag = ssa_add_local_generated(proc, t_type_info_maybe);
-					ssaValue *gep = get_type_info_ptr(proc, type_info_data, t->Maybe.elem);
+					ssaValue *gep = ssa_get_type_info_ptr(proc, type_info_data, t->Maybe.elem);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), gep);
 				} break;
 				case Type_Array: {
 					tag = ssa_add_local_generated(proc, t_type_info_array);
-					ssaValue *gep = get_type_info_ptr(proc, type_info_data, t->Array.elem);
+					ssaValue *gep = ssa_get_type_info_ptr(proc, type_info_data, t->Array.elem);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), gep);
 
 					isize ez = type_size_of(m->sizes, a, t->Array.elem);
@@ -5160,7 +5161,7 @@ void ssa_gen_tree(ssaGen *s) {
 				} break;
 				case Type_Slice: {
 					tag = ssa_add_local_generated(proc, t_type_info_slice);
-					ssaValue *gep = get_type_info_ptr(proc, type_info_data, t->Slice.elem);
+					ssaValue *gep = ssa_get_type_info_ptr(proc, type_info_data, t->Slice.elem);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), gep);
 
 					isize ez = type_size_of(m->sizes, a, t->Slice.elem);
@@ -5170,7 +5171,7 @@ void ssa_gen_tree(ssaGen *s) {
 				} break;
 				case Type_Vector: {
 					tag = ssa_add_local_generated(proc, t_type_info_vector);
-					ssaValue *gep = get_type_info_ptr(proc, type_info_data, t->Vector.elem);
+					ssaValue *gep = ssa_get_type_info_ptr(proc, type_info_data, t->Vector.elem);
 					ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), gep);
 
 					isize ez = type_size_of(m->sizes, a, t->Vector.elem);
@@ -5200,13 +5201,13 @@ void ssa_gen_tree(ssaGen *s) {
 							ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 4), ordered);
 						}
 
-						ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
+						ssaValue *memory = ssa_type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
 
 						type_set_offsets(m->sizes, a, t); // NOTE(bill): Just incase the offsets have not been set yet
 						for (isize source_index = 0; source_index < t->Record.field_count; source_index++) {
 							// TODO(bill): Order fields in source order not layout order
 							Entity *f = t->Record.fields_in_src_order[source_index];
-							ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
+							ssaValue *tip = ssa_get_type_info_ptr(proc, type_info_data, f->type);
 							i64 foffset = t->Record.struct_offsets[f->Variable.field_index];
 							GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
 
@@ -5253,7 +5254,7 @@ void ssa_gen_tree(ssaGen *s) {
 							ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 2),  align);
 						}
 
-						ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
+						ssaValue *memory = ssa_type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
 
 						for (isize i = 0; i < t->Record.field_count; i++) {
 							ssaValue *field     = ssa_emit_ptr_offset(proc, memory, ssa_make_const_int(a, i));
@@ -5262,7 +5263,7 @@ void ssa_gen_tree(ssaGen *s) {
 							ssaValue *offset    = ssa_emit_struct_ep(proc, field, 2);
 
 							Entity *f = t->Record.fields[i];
-							ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
+							ssaValue *tip = ssa_get_type_info_ptr(proc, type_info_data, f->type);
 
 							if (f->token.string.len > 0) {
 								ssa_emit_store(proc, name, ssa_make_const_string(a, f->token.string));
@@ -5291,7 +5292,7 @@ void ssa_gen_tree(ssaGen *s) {
 							enum_base = t_int;
 						}
 						ssaValue *base = ssa_emit_struct_ep(proc, tag, 0);
-						ssa_emit_store(proc, base, get_type_info_ptr(proc, type_info_data, enum_base));
+						ssa_emit_store(proc, base, ssa_get_type_info_ptr(proc, type_info_data, enum_base));
 
 						if (t->Record.other_field_count > 0) {
 							Entity **fields = t->Record.other_fields;
@@ -5368,7 +5369,7 @@ void ssa_gen_tree(ssaGen *s) {
 						ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 2), align);
 					}
 
-					ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Tuple.variable_count, &type_info_member_index);
+					ssaValue *memory = ssa_type_info_member_offset(proc, type_info_member_data, t->Tuple.variable_count, &type_info_member_index);
 
 					for (isize i = 0; i < t->Tuple.variable_count; i++) {
 						ssaValue *field     = ssa_emit_ptr_offset(proc, memory, ssa_make_const_int(a, i));
@@ -5377,7 +5378,7 @@ void ssa_gen_tree(ssaGen *s) {
 						// NOTE(bill): offset is not used for tuples
 
 						Entity *f = t->Tuple.variables[i];
-						ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
+						ssaValue *tip = ssa_get_type_info_ptr(proc, type_info_data, f->type);
 
 						if (f->token.string.len > 0) {
 							ssa_emit_store(proc, name, ssa_make_const_string(a, f->token.string));
@@ -5407,10 +5408,10 @@ void ssa_gen_tree(ssaGen *s) {
 					ssaValue *variadic = ssa_emit_struct_ep(proc, tag, 2);
 
 					if (t->Proc.params) {
-						ssa_emit_store(proc, params, get_type_info_ptr(proc, type_info_data, t->Proc.params));
+						ssa_emit_store(proc, params, ssa_get_type_info_ptr(proc, type_info_data, t->Proc.params));
 					}
 					if (t->Proc.results) {
-						ssa_emit_store(proc, results, get_type_info_ptr(proc, type_info_data, t->Proc.results));
+						ssa_emit_store(proc, results, ssa_get_type_info_ptr(proc, type_info_data, t->Proc.results));
 					}
 					ssa_emit_store(proc, variadic, ssa_make_const_bool(a, t->Proc.variadic));
 

+ 9 - 10
src/ssa_opt.cpp

@@ -142,7 +142,7 @@ ssaValueArray ssa_get_block_phi_nodes(ssaBlock *b) {
 }
 
 void ssa_remove_pred(ssaBlock *b, ssaBlock *p) {
-	auto phis = ssa_get_block_phi_nodes(b);
+	ssaValueArray phis = ssa_get_block_phi_nodes(b);
 	isize i = 0;
 	for_array(j, b->preds) {
 		ssaBlock *pred = b->preds.e[j];
@@ -288,7 +288,7 @@ void ssa_opt_build_referrers(ssaProcedure *proc) {
 				if (op == NULL) {
 					continue;
 				}
-				auto *refs = ssa_value_referrers(op);
+				ssaValueArray *refs = ssa_value_referrers(op);
 				if (refs != NULL) {
 					array_add(refs, instr);
 				}
@@ -307,13 +307,13 @@ void ssa_opt_build_referrers(ssaProcedure *proc) {
 
 // State of Lengauer-Tarjan algorithm
 // Based on this paper: http://jgaa.info/accepted/2006/GeorgiadisTarjanWerneck2006.10.1.pdf
-struct ssaLTState {
+typedef struct ssaLTState {
 	isize count;
 	// NOTE(bill): These are arrays
 	ssaBlock **sdom;     // Semidominator
 	ssaBlock **parent;   // Parent in DFS traversal of CFG
 	ssaBlock **ancestor;
-};
+} ssaLTState;
 
 // §2.2 - bottom of page
 void ssa_lt_link(ssaLTState *lt, ssaBlock *p, ssaBlock *q) {
@@ -347,9 +347,9 @@ ssaBlock *ssa_lt_eval(ssaLTState *lt, ssaBlock *v) {
 	return u;
 }
 
-struct ssaDomPrePost {
+typedef struct ssaDomPrePost {
 	i32 pre, post;
-};
+} ssaDomPrePost;
 
 ssaDomPrePost ssa_opt_number_dom_tree(ssaBlock *v, i32 pre, i32 post) {
 	ssaDomPrePost result = {pre, post};
@@ -440,12 +440,11 @@ void ssa_opt_build_dom_tree(ssaProcedure *proc) {
 			}
 
 			// Calculate children relation as inverse of idom
-			auto *children = &w->dom.idom->dom.children;
-			if (children->e == NULL) {
+			if (w->dom.idom->dom.children.e == NULL) {
 				// TODO(bill): Is this good enough for memory allocations?
-				array_init(children, heap_allocator());
+				array_init(&w->dom.idom->dom.children, heap_allocator());
 			}
-			array_add(children, w);
+			array_add(&w->dom.idom->dom.children, w);
 		}
 	}
 

+ 2 - 2
src/ssa_print.cpp

@@ -1,8 +1,8 @@
-struct ssaFileBuffer {
+typedef struct ssaFileBuffer {
 	gbVirtualMemory vm;
 	isize           offset;
 	gbFile *        output;
-};
+} ssaFileBuffer;
 
 void ssa_file_buffer_init(ssaFileBuffer *f, gbFile *output) {
 	isize size = 8*gb_virtual_memory_page_size(NULL);

+ 4 - 4
src/timings.cpp

@@ -1,14 +1,14 @@
-struct TimeStamp {
+typedef struct TimeStamp {
 	u64    start;
 	u64    finish;
 	String label;
-};
+} TimeStamp;
 
-struct Timings {
+typedef struct Timings {
 	TimeStamp        total;
 	Array(TimeStamp) sections;
 	u64              freq;
-};
+} Timings;
 
 
 u64 win32_time_stamp_time_now(void) {

+ 12 - 12
src/tokenizer.cpp

@@ -113,11 +113,11 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
 TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
 	TOKEN_KIND(Token_Count, "")
 
-enum TokenKind {
+typedef enum TokenKind {
 #define TOKEN_KIND(e, s) e
 	TOKEN_KINDS
 #undef TOKEN_KIND
-};
+} TokenKind;
 
 String const token_strings[] = {
 #define TOKEN_KIND(e, s) {cast(u8 *)s, gb_size_of(s)-1}
@@ -126,11 +126,11 @@ String const token_strings[] = {
 };
 
 
-struct TokenPos {
+typedef struct TokenPos {
 	String file;
 	isize  line;
 	isize  column;
-};
+} TokenPos;
 
 i32 token_pos_cmp(TokenPos a, TokenPos b) {
 	if (a.line == b.line) {
@@ -149,11 +149,11 @@ bool token_pos_are_equal(TokenPos a, TokenPos b) {
 }
 
 // NOTE(bill): Text is UTF-8, thus why u8 and not char
-struct Token {
+typedef struct Token {
 	TokenKind kind;
 	String string;
 	TokenPos pos;
-};
+} Token;
 
 Token empty_token = {Token_Invalid};
 Token blank_token = {Token_Identifier, {cast(u8 *)"_", 1}};
@@ -164,12 +164,12 @@ Token make_token_ident(String s) {
 }
 
 
-struct ErrorCollector {
+typedef struct ErrorCollector {
 	TokenPos prev;
 	i64 count;
 	i64 warning_count;
 	gbMutex mutex;
-};
+} ErrorCollector;
 
 gb_global ErrorCollector global_error_collector;
 
@@ -272,7 +272,7 @@ gb_inline bool token_is_shift(Token t) {
 gb_inline void print_token(Token t) { gb_printf("%.*s\n", LIT(t.string)); }
 
 
-enum TokenizerInitError {
+typedef enum TokenizerInitError {
 	TokenizerInit_None,
 
 	TokenizerInit_Invalid,
@@ -281,10 +281,10 @@ enum TokenizerInitError {
 	TokenizerInit_Empty,
 
 	TokenizerInit_Count,
-};
+} TokenizerInitError;
 
 
-struct Tokenizer {
+typedef struct Tokenizer {
 	String fullpath;
 	u8 *start;
 	u8 *end;
@@ -297,7 +297,7 @@ struct Tokenizer {
 
 	isize error_count;
 	Array(String) allocated_strings;
-};
+} Tokenizer;
 
 
 void tokenizer_err(Tokenizer *t, char *msg, ...) {