1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (c) 2015 Andrew Kelley
*
* This file is part of zig, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#ifndef ZIG_SEMANTIC_INFO_HPP
#define ZIG_SEMANTIC_INFO_HPP
#include "codegen.hpp"
#include "hash_map.hpp"
#include "zig_llvm.hpp"
#include "errmsg.hpp"
struct FnTableEntry;
struct TypeTableEntry {
LLVMTypeRef type_ref;
LLVMZigDIType *di_type;
TypeTableEntry *pointer_child;
bool pointer_is_const;
int user_defined_id;
Buf name;
TypeTableEntry *pointer_const_parent;
TypeTableEntry *pointer_mut_parent;
};
struct ImportTableEntry {
AstNode *root;
Buf *path; // relative to root_source_dir
LLVMZigDIFile *di_file;
Buf *source_code;
ZigList<int> *line_offsets;
// reminder: hash tables must be initialized before use
HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;
};
struct FnTableEntry {
LLVMValueRef fn_value;
AstNode *proto_node;
AstNode *fn_def_node;
bool is_extern;
bool internal_linkage;
unsigned calling_convention;
ImportTableEntry *import_entry;
};
struct CodeGen {
LLVMModuleRef module;
ZigList<ErrorMsg*> errors;
LLVMBuilderRef builder;
LLVMZigDIBuilder *dbuilder;
LLVMZigDICompileUnit *compile_unit;
// reminder: hash tables must be initialized before use
HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;
HashMap<Buf *, LLVMValueRef, buf_hash, buf_eql_buf> str_table;
HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> type_table;
HashMap<Buf *, bool, buf_hash, buf_eql_buf> link_table;
HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
struct {
TypeTableEntry *entry_u8;
TypeTableEntry *entry_i32;
TypeTableEntry *entry_void;
TypeTableEntry *entry_unreachable;
TypeTableEntry *entry_invalid;
} builtin_types;
LLVMTargetDataRef target_data_ref;
unsigned pointer_size_bytes;
bool is_static;
bool strip_debug_symbols;
CodeGenBuildType build_type;
LLVMTargetMachineRef target_machine;
bool is_native_target;
Buf *root_source_dir;
Buf *root_out_name;
ZigList<LLVMZigDIScope *> block_scopes;
// The function definitions this module includes. There must be a corresponding
// fn_protos entry.
ZigList<FnTableEntry *> fn_defs;
// The function prototypes this module includes. In the case of external declarations,
// there will not be a corresponding fn_defs entry.
ZigList<FnTableEntry *> fn_protos;
OutType out_type;
FnTableEntry *cur_fn;
bool c_stdint_used;
AstNode *root_export_decl;
int version_major;
int version_minor;
int version_patch;
bool verbose;
ErrColor err_color;
ImportTableEntry *root_import;
};
struct TypeNode {
TypeTableEntry *entry;
};
struct FnDefNode {
bool add_implicit_return;
bool skip;
LLVMValueRef *params;
};
struct CodeGenNode {
union {
TypeNode type_node; // for NodeTypeType
FnDefNode fn_def_node; // for NodeTypeFnDef
} data;
};
static inline Buf *hack_get_fn_call_name(CodeGen *g, AstNode *node) {
// Assume that the expression evaluates to a simple name and return the buf
// TODO after type checking works we should be able to remove this hack
assert(node->type == NodeTypeSymbol);
return &node->data.symbol;
}
#endif
|