Skip to content

Commit 2b9478c

Browse files
vesim987Vexu
andcommitted
Sema: implement AVR address spaces
Co-authored-by: Veikka Tuominen <git@vexu.eu>
1 parent fd0fb26 commit 2b9478c

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

lib/std/builtin.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ pub const AddressSpace = enum {
174174
param,
175175
shared,
176176
local,
177+
178+
// AVR address spaces.
179+
flash,
180+
flash1,
181+
flash2,
182+
flash3,
183+
flash4,
184+
flash5,
177185
};
178186

179187
/// This data structure is used by the Zig language code generation and

lib/std/target.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,8 @@ pub const Target = struct {
11861186
.fs, .gs, .ss => arch == .x86_64 or arch == .x86,
11871187
.global, .constant, .local, .shared => is_gpu,
11881188
.param => is_nvptx,
1189+
// TODO this should also check how many flash banks the cpu has
1190+
.flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
11891191
};
11901192
}
11911193

src/Sema.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31938,6 +31938,8 @@ pub fn analyzeAddressSpace(
3193831938
.param => is_nv,
3193931939
.global, .shared, .local => is_gpu,
3194031940
.constant => is_gpu and (ctx == .constant),
31941+
// TODO this should also check how many flash banks the cpu has
31942+
.flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
3194131943
};
3194231944

3194331945
if (!supported) {

src/codegen/llvm.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10241,6 +10241,16 @@ fn toLlvmAddressSpace(address_space: std.builtin.AddressSpace, target: std.Targe
1024110241
.local => llvm.address_space.amdgpu.private,
1024210242
else => unreachable,
1024310243
},
10244+
.avr => switch (address_space) {
10245+
.generic => llvm.address_space.default,
10246+
.flash => llvm.address_space.avr.flash,
10247+
.flash1 => llvm.address_space.avr.flash1,
10248+
.flash2 => llvm.address_space.avr.flash2,
10249+
.flash3 => llvm.address_space.avr.flash3,
10250+
.flash4 => llvm.address_space.avr.flash4,
10251+
.flash5 => llvm.address_space.avr.flash5,
10252+
else => unreachable,
10253+
},
1024410254
else => switch (address_space) {
1024510255
.generic => llvm.address_space.default,
1024610256
else => unreachable,

src/codegen/llvm/bindings.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,8 +1530,12 @@ pub const address_space = struct {
15301530

15311531
// See llvm/lib/Target/AVR/AVR.h
15321532
pub const avr = struct {
1533-
pub const data_memory: c_uint = 0;
1534-
pub const program_memory: c_uint = 1;
1533+
pub const flash: c_uint = 1;
1534+
pub const flash1: c_uint = 2;
1535+
pub const flash2: c_uint = 3;
1536+
pub const flash3: c_uint = 4;
1537+
pub const flash4: c_uint = 5;
1538+
pub const flash5: c_uint = 6;
15351539
};
15361540

15371541
// See llvm/lib/Target/NVPTX/NVPTX.h

src/codegen/spirv.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ pub const DeclGen = struct {
548548
.gs, .fs, .ss => unreachable,
549549
.shared => .Workgroup,
550550
.local => .Private,
551-
.global, .param, .constant => unreachable,
551+
.global, .param, .constant, .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => unreachable,
552552
};
553553
}
554554

0 commit comments

Comments
 (0)