Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5c9d98

Browse filesBrowse files
committed
introduce align keyword
* remove `@setGlobalAlign` * add align keyword for setting alignment on functions and variables. * loads and stores use alignment from pointer * memcpy, memset use alignment from pointer * add syntax for pointer alignment * slices can have volatile * add u2, i2 primitives * ignore preferred align and use abi align everywhere * back to only having alignOf builtin. preferredAlignOf is too tricky to be useful. See ziglang#432. Partial revert of e726925. See ziglang#37
1 parent b8ed0cb commit c5c9d98
Copy full SHA for c5c9d98
Expand file treeCollapse file tree

20 files changed

+931
-715
lines changed
Open diff view settings
Collapse file

‎src/all_types.hpp‎

Copy file name to clipboardExpand all lines: src/all_types.hpp
+51-36Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ struct TldVar {
303303
Tld base;
304304

305305
VariableTableEntry *var;
306-
AstNode *set_global_align_node;
307-
uint32_t alignment;
308306
AstNode *set_global_section_node;
309307
Buf *section_name;
310308
AstNode *set_global_linkage_node;
@@ -358,6 +356,7 @@ enum NodeType {
358356
NodeTypeCharLiteral,
359357
NodeTypeSymbol,
360358
NodeTypePrefixOpExpr,
359+
NodeTypeAddrOfExpr,
361360
NodeTypeFnCallExpr,
362361
NodeTypeArrayAccessExpr,
363362
NodeTypeSliceExpr,
@@ -415,6 +414,8 @@ struct AstNodeFnProto {
415414
AstNode *fn_def_node;
416415
// populated if this is an extern declaration
417416
Buf *lib_name;
417+
// populated if the "align A" is present
418+
AstNode *align_expr;
418419
};
419420

420421
struct AstNodeFnDef {
@@ -470,6 +471,8 @@ struct AstNodeVariableDeclaration {
470471
AstNode *expr;
471472
// populated if this is an extern declaration
472473
Buf *lib_name;
474+
// populated if the "align A" is present
475+
AstNode *align_expr;
473476
};
474477

475478
struct AstNodeErrorValueDecl {
@@ -579,10 +582,6 @@ enum PrefixOp {
579582
PrefixOpBinNot,
580583
PrefixOpNegation,
581584
PrefixOpNegationWrap,
582-
PrefixOpAddressOf,
583-
PrefixOpConstAddressOf,
584-
PrefixOpVolatileAddressOf,
585-
PrefixOpConstVolatileAddressOf,
586585
PrefixOpDereference,
587586
PrefixOpMaybe,
588587
PrefixOpError,
@@ -595,6 +594,23 @@ struct AstNodePrefixOpExpr {
595594
AstNode *primary_expr;
596595
};
597596

597+
struct AstNodeAddrOfExpr {
598+
AstNode *align_expr;
599+
BigInt *bit_offset_start;
600+
BigInt *bit_offset_end;
601+
bool is_const;
602+
bool is_volatile;
603+
AstNode *op_expr;
604+
};
605+
606+
struct AstNodeArrayType {
607+
AstNode *size;
608+
AstNode *child_type;
609+
AstNode *align_expr;
610+
bool is_const;
611+
bool is_volatile;
612+
};
613+
598614
struct AstNodeUse {
599615
VisibMod visib_mod;
600616
AstNode *expr;
@@ -807,12 +823,6 @@ struct AstNodeUnreachableExpr {
807823
};
808824

809825

810-
struct AstNodeArrayType {
811-
AstNode *size;
812-
AstNode *child_type;
813-
bool is_const;
814-
};
815-
816826
struct AstNodeErrorType {
817827
};
818828

@@ -841,6 +851,7 @@ struct AstNode {
841851
AstNodeBinOpExpr bin_op_expr;
842852
AstNodeUnwrapErrorExpr unwrap_err_expr;
843853
AstNodePrefixOpExpr prefix_op_expr;
854+
AstNodeAddrOfExpr addr_of_expr;
844855
AstNodeFnCallExpr fn_call_expr;
845856
AstNodeArrayAccessExpr array_access_expr;
846857
AstNodeSliceExpr slice_expr;
@@ -911,8 +922,10 @@ struct TypeTableEntryPointer {
911922
TypeTableEntry *child_type;
912923
bool is_const;
913924
bool is_volatile;
925+
uint32_t alignment;
914926
uint32_t bit_offset;
915927
uint32_t unaligned_bit_count;
928+
TypeTableEntry *slice_parent;
916929
};
917930

918931
struct TypeTableEntryInt {
@@ -958,6 +971,7 @@ struct TypeTableEntryStruct {
958971

959972
bool zero_bits_loop_flag;
960973
bool zero_bits_known;
974+
uint32_t abi_alignment; // also figured out with zero_bits pass
961975
};
962976

963977
struct TypeTableEntryMaybe {
@@ -989,6 +1003,7 @@ struct TypeTableEntryEnum {
9891003

9901004
bool zero_bits_loop_flag;
9911005
bool zero_bits_known;
1006+
uint32_t abi_alignment; // also figured out with zero_bits pass
9921007

9931008
size_t gen_union_index;
9941009
size_t gen_tag_index;
@@ -1101,7 +1116,6 @@ struct TypeTableEntry {
11011116

11021117
// use these fields to make sure we don't duplicate type table entries for the same type
11031118
TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const]
1104-
TypeTableEntry *slice_parent[2]; // [0 - mut, 1 - const]
11051119
TypeTableEntry *maybe_parent;
11061120
TypeTableEntry *error_parent;
11071121
// If we generate a constant name value for this type, we memoize it here.
@@ -1164,15 +1178,14 @@ struct FnTableEntry {
11641178
size_t prealloc_bbc;
11651179
AstNode **param_source_nodes;
11661180
Buf **param_names;
1181+
uint32_t align_bytes;
11671182

11681183
AstNode *fn_no_inline_set_node;
11691184
AstNode *fn_static_eval_set_node;
11701185

11711186
ZigList<IrInstruction *> alloca_list;
11721187
ZigList<VariableTableEntry *> variable_list;
11731188

1174-
AstNode *set_global_align_node;
1175-
uint32_t alignment;
11761189
AstNode *set_global_section_node;
11771190
Buf *section_name;
11781191
AstNode *set_global_linkage_node;
@@ -1187,8 +1200,7 @@ enum BuiltinFnId {
11871200
BuiltinFnIdMemcpy,
11881201
BuiltinFnIdMemset,
11891202
BuiltinFnIdSizeof,
1190-
BuiltinFnIdPreferredAlignOf,
1191-
BuiltinFnIdAbiAlignOf,
1203+
BuiltinFnIdAlignOf,
11921204
BuiltinFnIdMaxValue,
11931205
BuiltinFnIdMinValue,
11941206
BuiltinFnIdMemberCount,
@@ -1224,7 +1236,6 @@ enum BuiltinFnId {
12241236
BuiltinFnIdSetFloatMode,
12251237
BuiltinFnIdTypeName,
12261238
BuiltinFnIdCanImplicitCast,
1227-
BuiltinFnIdSetGlobalAlign,
12281239
BuiltinFnIdSetGlobalSection,
12291240
BuiltinFnIdSetGlobalLinkage,
12301241
BuiltinFnIdPanic,
@@ -1277,6 +1288,7 @@ struct TypeId {
12771288
TypeTableEntry *child_type;
12781289
bool is_const;
12791290
bool is_volatile;
1291+
uint32_t alignment;
12801292
uint32_t bit_offset;
12811293
uint32_t unaligned_bit_count;
12821294
} pointer;
@@ -1392,7 +1404,7 @@ struct CodeGen {
13921404

13931405
struct {
13941406
TypeTableEntry *entry_bool;
1395-
TypeTableEntry *entry_int[2][10]; // [signed,unsigned][3,4,5,6,7,8,16,32,64,128]
1407+
TypeTableEntry *entry_int[2][11]; // [signed,unsigned][2,3,4,5,6,7,8,16,32,64,128]
13961408
TypeTableEntry *entry_c_int[CIntTypeCount];
13971409
TypeTableEntry *entry_c_longdouble;
13981410
TypeTableEntry *entry_c_void;
@@ -1547,6 +1559,8 @@ struct CodeGen {
15471559

15481560
ZigList<FnTableEntry *> inline_fns;
15491561
ZigList<AstNode *> tld_ref_source_node_stack;
1562+
1563+
TypeTableEntry *align_amt_type;
15501564
};
15511565

15521566
enum VarLinkage {
@@ -1575,6 +1589,7 @@ struct VariableTableEntry {
15751589
size_t ref_count;
15761590
VarLinkage linkage;
15771591
IrInstruction *decl_instruction;
1592+
uint32_t align_bytes;
15781593
};
15791594

15801595
struct ErrorTableEntry {
@@ -1808,8 +1823,7 @@ enum IrInstructionId {
18081823
IrInstructionIdBreakpoint,
18091824
IrInstructionIdReturnAddress,
18101825
IrInstructionIdFrameAddress,
1811-
IrInstructionIdPreferredAlignOf,
1812-
IrInstructionIdAbiAlignOf,
1826+
IrInstructionIdAlignOf,
18131827
IrInstructionIdOverflowOp,
18141828
IrInstructionIdTestErr,
18151829
IrInstructionIdUnwrapErrCode,
@@ -1831,7 +1845,6 @@ enum IrInstructionId {
18311845
IrInstructionIdCheckStatementIsVoid,
18321846
IrInstructionIdTypeName,
18331847
IrInstructionIdCanImplicitCast,
1834-
IrInstructionIdSetGlobalAlign,
18351848
IrInstructionIdSetGlobalSection,
18361849
IrInstructionIdSetGlobalLinkage,
18371850
IrInstructionIdDeclRef,
@@ -1841,6 +1854,7 @@ enum IrInstructionId {
18411854
IrInstructionIdOffsetOf,
18421855
IrInstructionIdTypeId,
18431856
IrInstructionIdSetEvalBranchQuota,
1857+
IrInstructionIdPtrTypeOf,
18441858
};
18451859

18461860
struct IrInstruction {
@@ -1976,6 +1990,7 @@ struct IrInstructionDeclVar {
19761990

19771991
VariableTableEntry *var;
19781992
IrInstruction *var_type;
1993+
IrInstruction *align_value;
19791994
IrInstruction *init_value;
19801995
};
19811996

@@ -2152,7 +2167,9 @@ struct IrInstructionArrayType {
21522167
struct IrInstructionSliceType {
21532168
IrInstruction base;
21542169

2170+
IrInstruction *align_value;
21552171
bool is_const;
2172+
bool is_volatile;
21562173
IrInstruction *child_type;
21572174
};
21582175

@@ -2393,13 +2410,7 @@ struct IrInstructionOverflowOp {
23932410
TypeTableEntry *result_ptr_type;
23942411
};
23952412

2396-
struct IrInstructionPreferredAlignOf {
2397-
IrInstruction base;
2398-
2399-
IrInstruction *type_value;
2400-
};
2401-
2402-
struct IrInstructionAbiAlignOf {
2413+
struct IrInstructionAlignOf {
24032414
IrInstruction base;
24042415

24052416
IrInstruction *type_value;
@@ -2554,13 +2565,6 @@ struct IrInstructionCanImplicitCast {
25542565
IrInstruction *target_value;
25552566
};
25562567

2557-
struct IrInstructionSetGlobalAlign {
2558-
IrInstruction base;
2559-
2560-
Tld *tld;
2561-
IrInstruction *value;
2562-
};
2563-
25642568
struct IrInstructionSetGlobalSection {
25652569
IrInstruction base;
25662570

@@ -2622,6 +2626,17 @@ struct IrInstructionSetEvalBranchQuota {
26222626
IrInstruction *new_quota;
26232627
};
26242628

2629+
struct IrInstructionPtrTypeOf {
2630+
IrInstruction base;
2631+
2632+
IrInstruction *align_value;
2633+
IrInstruction *child_type;
2634+
uint32_t bit_offset_start;
2635+
uint32_t bit_offset_end;
2636+
bool is_const;
2637+
bool is_volatile;
2638+
};
2639+
26252640
static const size_t slice_ptr_index = 0;
26262641
static const size_t slice_len_index = 1;
26272642

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.