Skip to content

Commit 80ec095

Browse files
committed
fix sorcerer build
1 parent bd80b0a commit 80ec095

File tree

6 files changed

+54
-65
lines changed

6 files changed

+54
-65
lines changed

port/texasinstruments/msp430/patches/common.zon renamed to port/texasinstruments/msp430/patches/msp430f5529.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.name = "WDTPW",
55
.size_bits = 8,
66
.offset_bits = 8,
7-
.access = .@"write-only",
7+
.access = .write_only,
88
.type = .{ .uint = 8 },
99
} },
1010
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.{
2+
.{ .add_struct_field = .{
3+
.parent = "types.peripherals.Watchdog_Timer.WDTCTL",
4+
.name = "WDTPW",
5+
.size_bits = 8,
6+
.offset_bits = 8,
7+
.access = .write_only,
8+
.type = .{ .uint = 8 },
9+
} },
10+
}

port/texasinstruments/msp430/src/Chips.zig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ pub fn init(dep: *std.Build.Dependency) Self {
4141
.{ .tag = .ram, .offset = 0x2400, .length = 0x2000, .access = .rwx },
4242
.{ .name = "isr_vector", .tag = .none, .offset = 0xFF80, .length = 0x80, .access = .rx },
4343
},
44-
.patch_files = &.{
45-
b.path("patches/common.zon"),
46-
},
44+
// Adding patches here breaks building sorcerer 🤡
45+
// .patch_files = &.{
46+
// b.path("patches/msp430f5529.zon"),
47+
// },
4748
},
4849
.bundle_compiler_rt = false,
4950
.bundle_ubsan_rt = false,
@@ -76,9 +77,10 @@ pub fn init(dep: *std.Build.Dependency) Self {
7677
.{ .tag = .ram, .offset = 0x200, .length = 0x200, .access = .rwx },
7778
.{ .name = "isr_vector", .tag = .none, .offset = 0xFFE0, .length = 0x20, .access = .rx },
7879
},
79-
.patch_files = &.{
80-
b.path("patches/common.zon"),
81-
},
80+
// Adding patches here breaks building sorcerer 🤡
81+
// .patch_files = &.{
82+
// b.path("patches/msp430g2553.zon"),
83+
// },
8284
},
8385
.bundle_compiler_rt = false,
8486
.bundle_ubsan_rt = false,

tools/regz/src/root.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub const Arch = @import("arch.zig").Arch;
33
pub const arm = @import("arch/arm.zig");
44
pub const Database = @import("Database.zig");
55
pub const Directory = @import("Directory.zig");
6-
pub const embassy = @import("embassy.zig");
6+
pub const embassy = @import("format/embassy.zig");
7+
pub const gen = @import("gen.zig");
78
pub const Patch = @import("patch.zig").Patch;
89
pub const VirtualFilesystem = @import("VirtualFilesystem.zig");

tools/sorcerer/src/RegzWindow.zig

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn create(
268268
.register_schema_usages = register_schema_usages,
269269
};
270270

271-
try db.to_zig(window.vfs.dir(), .{});
271+
try regz.gen.to_zig(db, window.vfs.dir(), .{});
272272

273273
count += 1;
274274

@@ -941,7 +941,7 @@ fn load_patch_files(w: *RegzWindow) void {
941941

942942
// Apply patches to the database so analysis reflects them
943943
for (patches) |patch| {
944-
apply_single_patch(w.db, alloc, patch) catch continue;
944+
w.db.apply_patch(patch) catch continue;
945945
}
946946

947947
const owned_path = alloc.dupe(u8, path) catch continue;
@@ -1062,6 +1062,7 @@ fn get_patch_label(patch: regz.Patch, arena: Allocator) []const u8 {
10621062
.set_enum_type => |p| std.fmt.allocPrint(arena, "set_enum_type: {s}", .{p.of}) catch "set_enum_type",
10631063
.add_interrupt => |p| std.fmt.allocPrint(arena, "add_interrupt: {s}", .{p.name}) catch "add_interrupt",
10641064
.add_type_and_apply => |p| std.fmt.allocPrint(arena, "add_type_and_apply: {t} {s}", .{ p.type, p.type_name }) catch "add_type_and_apply",
1065+
.add_struct_field => |p| std.fmt.allocPrint(arena, "add_struct_field: {t} {s}", .{ p.type, p.name }) catch "add_struct_field",
10651066
};
10661067
}
10671068

@@ -1201,15 +1202,16 @@ fn show_patch_details(w: *RegzWindow, arena: Allocator) void {
12011202
.set_enum_type => |p| show_set_enum_type_widget(p),
12021203
.add_interrupt => |p| show_add_interrupt_widget(p),
12031204
.add_type_and_apply => |p| show_add_type_and_apply_widget(p, arena),
1205+
.add_struct_field => |p| show_add_struct_field_widget(p),
12041206
}
12051207
},
12061208
.diff => {
1207-
w.show_patch_diff(arena, sel, patch);
1209+
w.show_patch_diff(sel, patch);
12081210
},
12091211
}
12101212
}
12111213

1212-
fn show_patch_diff(w: *RegzWindow, arena: Allocator, sel: SelectedPatch, patch: regz.Patch) void {
1214+
fn show_patch_diff(w: *RegzWindow, sel: SelectedPatch, patch: regz.Patch) void {
12131215
// Check if cache is valid
12141216
if (w.cached_diff) |cached| {
12151217
if (cached.file_index == sel.file_index and cached.patch_index == sel.patch_index) {
@@ -1227,7 +1229,7 @@ fn show_patch_diff(w: *RegzWindow, arena: Allocator, sel: SelectedPatch, patch:
12271229
}
12281230

12291231
// Compute new diff
1230-
w.compute_patch_diff(arena, sel, patch);
1232+
w.compute_patch_diff(sel, patch);
12311233

12321234
// Display the newly computed diff
12331235
if (w.cached_diff) |cached| {
@@ -1343,7 +1345,7 @@ fn display_diff(w: *RegzWindow, file_diffs: []const FileDiff, sel: SelectedPatch
13431345
}
13441346
}
13451347

1346-
fn compute_patch_diff(w: *RegzWindow, temp_arena: Allocator, sel: SelectedPatch, patch: regz.Patch) void {
1348+
fn compute_patch_diff(w: *RegzWindow, sel: SelectedPatch, patch: regz.Patch) void {
13471349
_ = patch; // We'll get the patch from the loaded patches instead
13481350
// Use window's persistent arena for cached data
13491351
const arena = w.arena.allocator();
@@ -1395,23 +1397,17 @@ fn compute_patch_diff(w: *RegzWindow, temp_arena: Allocator, sel: SelectedPatch,
13951397
const is_selected_or_before = (file_idx < sel.file_index) or
13961398
(file_idx == sel.file_index and patch_idx <= sel.patch_index);
13971399

1398-
// Serialize this patch
1399-
var zon_buf: std.Io.Writer.Allocating = .init(temp_arena);
1400-
const patch_array: []const regz.Patch = &.{p};
1401-
std.zon.stringify.serialize(patch_array, .{}, &zon_buf.writer) catch continue;
1402-
const zon_text = temp_arena.dupeZ(u8, zon_buf.written()) catch continue;
1403-
14041400
var diags: std.zon.parse.Diagnostics = .{};
14051401

14061402
// Apply to before_db if this patch comes before the selected one
14071403
if (is_before_selected) {
1408-
before_db.apply_patch(zon_text, &diags) catch continue;
1404+
before_db.apply_patch(p) catch continue;
14091405
}
14101406

14111407
// Apply to after_db if this patch is the selected one or comes before it
14121408
if (is_selected_or_before) {
14131409
diags = .{};
1414-
after_db.apply_patch(zon_text, &diags) catch continue;
1410+
after_db.apply_patch(p) catch continue;
14151411
}
14161412
}
14171413
}
@@ -1425,23 +1421,14 @@ fn compute_patch_diff(w: *RegzWindow, temp_arena: Allocator, sel: SelectedPatch,
14251421
const is_selected_or_before = (file_idx < sel.file_index) or
14261422
(file_idx == sel.file_index and full_idx <= sel.patch_index);
14271423

1428-
// Serialize this patch
1429-
var zon_buf: std.Io.Writer.Allocating = .init(temp_arena);
1430-
const patch_array: []const regz.Patch = &.{p};
1431-
std.zon.stringify.serialize(patch_array, .{}, &zon_buf.writer) catch continue;
1432-
const zon_text = temp_arena.dupeZ(u8, zon_buf.written()) catch continue;
1433-
1434-
var diags: std.zon.parse.Diagnostics = .{};
1435-
14361424
// Apply to before_db if this patch comes before the selected one
14371425
if (is_before_selected) {
1438-
before_db.apply_patch(zon_text, &diags) catch continue;
1426+
before_db.apply_patch(p) catch continue;
14391427
}
14401428

14411429
// Apply to after_db if this patch is the selected one or comes before it
14421430
if (is_selected_or_before) {
1443-
diags = .{};
1444-
after_db.apply_patch(zon_text, &diags) catch continue;
1431+
after_db.apply_patch(p) catch continue;
14451432
}
14461433
}
14471434
}
@@ -1450,7 +1437,7 @@ fn compute_patch_diff(w: *RegzWindow, temp_arena: Allocator, sel: SelectedPatch,
14501437
var before_vfs: VirtualFilesystem = .init(w.gpa);
14511438
defer before_vfs.deinit();
14521439

1453-
before_db.to_zig(before_vfs.dir(), .{}) catch |err| {
1440+
regz.gen.to_zig(before_db, before_vfs.dir(), .{}) catch |err| {
14541441
w.cached_diff = .{
14551442
.file_index = sel.file_index,
14561443
.patch_index = sel.patch_index,
@@ -1464,7 +1451,7 @@ fn compute_patch_diff(w: *RegzWindow, temp_arena: Allocator, sel: SelectedPatch,
14641451
var after_vfs: VirtualFilesystem = .init(w.gpa);
14651452
defer after_vfs.deinit();
14661453

1467-
after_db.to_zig(after_vfs.dir(), .{}) catch |err| {
1454+
regz.gen.to_zig(after_db, after_vfs.dir(), .{}) catch |err| {
14681455
w.cached_diff = .{
14691456
.file_index = sel.file_index,
14701457
.patch_index = sel.patch_index,
@@ -1812,6 +1799,12 @@ fn show_add_type_and_apply_widget(p: anytype, arena: Allocator) void {
18121799
}
18131800
}
18141801

1802+
fn show_add_struct_field_widget(p: anytype) void {
1803+
labeled_field("Parent", p.parent);
1804+
labeled_field("Name", p.name);
1805+
// TODO: more
1806+
}
1807+
18151808
fn labeled_field(label_text: []const u8, value: []const u8) void {
18161809
// Use hash of label text as unique ID to avoid duplicate widget IDs
18171810
const label_hash = std.hash.Wyhash.hash(0, label_text);
@@ -2135,7 +2128,7 @@ fn show_create_patch_dialog_ui(w: *RegzWindow, arena: Allocator) void {
21352128
.color_text = if (can_create) dvui.Color.fromHex("1C1B19") else dvui.Color.fromHex("918175"),
21362129
}) and can_create) {
21372130
// Create the patch
2138-
w.create_patch_from_group(arena, pending.*) catch |err| {
2131+
w.create_patch_from_group(pending.*) catch |err| {
21392132
w.validation_error_message = std.fmt.allocPrint(w.arena.allocator(), "Failed to create patch: {s}", .{@errorName(err)}) catch "Failed to create patch";
21402133
w.show_validation_error = true;
21412134
};
@@ -2146,7 +2139,7 @@ fn show_create_patch_dialog_ui(w: *RegzWindow, arena: Allocator) void {
21462139
}
21472140

21482141
/// Create a patch from an equivalence group
2149-
fn create_patch_from_group(w: *RegzWindow, arena: Allocator, pending: PendingPatchCreation) !void {
2142+
fn create_patch_from_group(w: *RegzWindow, pending: PendingPatchCreation) !void {
21502143
// Get the cached analysis result
21512144
const cached = w.cached_analysis orelse return error.NoAnalysis;
21522145

@@ -2192,7 +2185,7 @@ fn create_patch_from_group(w: *RegzWindow, arena: Allocator, pending: PendingPat
21922185
w.has_unsaved_patches = true;
21932186

21942187
// Apply the patch to the database so analysis reflects the change
2195-
try apply_single_patch(w.db, arena, patch);
2188+
try w.db.apply_patch(patch);
21962189

21972190
// Refresh all views that depend on the database
21982191
w.on_database_changed();
@@ -2248,21 +2241,17 @@ fn rebuild_database_with_patches(w: *RegzWindow) void {
22482241
return;
22492242
};
22502243

2251-
const alloc = w.arena.allocator();
2252-
22532244
// Reapply all non-deleted patches from all files
22542245
for (w.loaded_patches.values()) |loaded| {
22552246
if (loaded.patches) |patches| {
22562247
for (patches, 0..) |patch, idx| {
2257-
if (!loaded.is_patch_deleted(idx)) {
2258-
apply_single_patch(w.db, alloc, patch) catch continue;
2259-
}
2248+
if (!loaded.is_patch_deleted(idx))
2249+
w.db.apply_patch(patch) catch continue;
22602250
}
22612251
}
22622252
// Reapply pending patches
2263-
for (loaded.pending_patches.items) |patch| {
2264-
apply_single_patch(w.db, alloc, patch) catch continue;
2265-
}
2253+
for (loaded.pending_patches.items) |patch|
2254+
w.db.apply_patch(patch) catch continue;
22662255
}
22672256

22682257
// Refresh all views that depend on the database
@@ -2276,7 +2265,7 @@ fn on_database_changed(w: *RegzWindow) void {
22762265
// Deinit old VFS and create new one
22772266
w.vfs.deinit();
22782267
w.vfs = .init(w.gpa);
2279-
w.db.to_zig(w.vfs.dir(), .{}) catch |err| {
2268+
regz.gen.to_zig(w.db, w.vfs.dir(), .{}) catch |err| {
22802269
std.log.err("Failed to regenerate code: {}", .{err});
22812270
};
22822271

@@ -2561,27 +2550,14 @@ fn validate_patch_file(w: *RegzWindow, arena: Allocator, patch_path: []const u8,
25612550
// Apply original patches (excluding deleted ones)
25622551
if (loaded.patches) |patches| {
25632552
for (patches, 0..) |patch, idx| {
2564-
if (!loaded.is_patch_deleted(idx)) {
2565-
try apply_single_patch(db, arena, patch);
2566-
}
2553+
if (!loaded.is_patch_deleted(idx))
2554+
try db.apply_patch(patch);
25672555
}
25682556
}
25692557

25702558
// Apply pending patches
2571-
for (loaded.pending_patches.items) |patch| {
2572-
try apply_single_patch(db, arena, patch);
2573-
}
2574-
}
2575-
2576-
/// Apply a single patch to a database
2577-
fn apply_single_patch(db: *regz.Database, arena: Allocator, patch: regz.Patch) !void {
2578-
var zon_buf: std.Io.Writer.Allocating = .init(arena);
2579-
const patch_array: []const regz.Patch = &.{patch};
2580-
try std.zon.stringify.serialize(patch_array, .{}, &zon_buf.writer);
2581-
const zon_text = try arena.dupeZ(u8, zon_buf.written());
2582-
2583-
var diags: std.zon.parse.Diagnostics = .{};
2584-
try db.apply_patch(zon_text, &diags);
2559+
for (loaded.pending_patches.items) |patch|
2560+
try db.apply_patch(patch);
25852561
}
25862562

25872563
/// Write a patch file combining original (non-deleted) and pending patches

tools/sorcerer/src/cli.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ fn generate_code(
365365
var vfs = regz.VirtualFilesystem.init(allocator);
366366
defer vfs.deinit();
367367

368-
db.to_zig(vfs.dir(), .{}) catch |err| {
368+
regz.gen.to_zig(db, vfs.dir(), .{}) catch |err| {
369369
try stderr.print("Error generating Zig code: {}\n", .{err});
370370
try stderr.flush();
371371
return error.Explained;

0 commit comments

Comments
 (0)