@zigc/lib 0.16.0-dev.3041 → 0.16.0-dev.3059
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/compiler_rt/mulo.zig +6 -1
- package/package.json +1 -1
- package/std/crypto/codecs/base64_hex_ct.zig +12 -2
- package/std/zig/llvm/Builder.zig +107 -48
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Nurul Huda (Apon).
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/compiler_rt/mulo.zig
CHANGED
|
@@ -19,7 +19,12 @@ comptime {
|
|
|
19
19
|
inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
|
|
20
20
|
overflow.* = 0;
|
|
21
21
|
const min = math.minInt(ST);
|
|
22
|
-
const res: ST =
|
|
22
|
+
const res: ST = if (ST == i128 and builtin.target.cpu.arch.isWasm()) res: {
|
|
23
|
+
// Despite compiler-rt being built with `-fno-builtin`, LLVM still converts this function to
|
|
24
|
+
// a call to `__muloti4` on WASM. This is an upstream bug: circumvent it by directly calling
|
|
25
|
+
// the "lower-level" compiler-rt routine for this wrapping multiplication.
|
|
26
|
+
break :res @import("mulXi3.zig").__multi3(a, b);
|
|
27
|
+
} else a *% b;
|
|
23
28
|
// Hacker's Delight section Overflow subsection Multiplication
|
|
24
29
|
// case a=-2^{31}, b=-1 problem, because
|
|
25
30
|
// on some machines a*b = -2^{31} with overflow
|
package/package.json
CHANGED
|
@@ -304,7 +304,7 @@ pub const base64 = struct {
|
|
|
304
304
|
return (lt(x, 26) & (x +% 'A')) |
|
|
305
305
|
(ge(x, 26) & lt(x, 52) & (x +% 'a' -% 26)) |
|
|
306
306
|
(ge(x, 52) & lt(x, 62) & (x +% '0' -% 52)) |
|
|
307
|
-
(eq(x, 62) & '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
|
|
307
|
+
(eq(x, 62) & if (urlsafe) '-' else '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
fn byteFromChar(c: u8, comptime urlsafe: bool) u8 {
|
|
@@ -312,7 +312,7 @@ pub const base64 = struct {
|
|
|
312
312
|
(ge(c, 'A') & le(c, 'Z') & (c -% 'A')) |
|
|
313
313
|
(ge(c, 'a') & le(c, 'z') & (c -% 'a' +% 26)) |
|
|
314
314
|
(ge(c, '0') & le(c, '9') & (c -% '0' +% 52)) |
|
|
315
|
-
(eq(c, '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
|
|
315
|
+
(eq(c, if (urlsafe) '-' else '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
|
|
316
316
|
return x | (eq(x, 0) & ~eq(c, 'A'));
|
|
317
317
|
}
|
|
318
318
|
|
|
@@ -453,6 +453,16 @@ test "hex with ignored chars" {
|
|
|
453
453
|
try testing.expectEqualSlices(u8, &expected, bin);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
test "base64 urlsafe" {
|
|
457
|
+
const input = [_]u8{ 0xfb, 0xff };
|
|
458
|
+
var enc_buf: [4]u8 = undefined;
|
|
459
|
+
var dec_buf: [2]u8 = undefined;
|
|
460
|
+
const encoded = try base64.encode(&enc_buf, &input, .urlsafe);
|
|
461
|
+
try testing.expectEqualSlices(u8, "-_8=", encoded);
|
|
462
|
+
const decoded = try base64.decode(&dec_buf, encoded, .urlsafe);
|
|
463
|
+
try testing.expectEqualSlices(u8, &input, decoded);
|
|
464
|
+
}
|
|
465
|
+
|
|
456
466
|
test "base64 with ignored chars" {
|
|
457
467
|
const encoded = "dGVzdCBi\r\nYXNlNjQ=\n";
|
|
458
468
|
const expected = "test base64";
|
package/std/zig/llvm/Builder.zig
CHANGED
|
@@ -2343,12 +2343,13 @@ pub const Global = struct {
|
|
|
2343
2343
|
none = maxInt(u32),
|
|
2344
2344
|
_,
|
|
2345
2345
|
|
|
2346
|
-
pub fn unwrap(
|
|
2347
|
-
var cur =
|
|
2346
|
+
pub fn unwrap(orig_index: Index, builder: *const Builder) Index {
|
|
2347
|
+
var cur = orig_index;
|
|
2348
2348
|
while (true) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2349
|
+
switch (builder.globals.values()[@intFromEnum(cur)].kind) {
|
|
2350
|
+
.replaced => |replacement| cur = replacement,
|
|
2351
|
+
else => return cur,
|
|
2352
|
+
}
|
|
2352
2353
|
}
|
|
2353
2354
|
}
|
|
2354
2355
|
|
|
@@ -2388,8 +2389,12 @@ pub const Global = struct {
|
|
|
2388
2389
|
return self.ptrConst(builder).type;
|
|
2389
2390
|
}
|
|
2390
2391
|
|
|
2391
|
-
pub fn toConst(
|
|
2392
|
-
return @enumFromInt(@intFromEnum(Constant.first_global) + @intFromEnum(
|
|
2392
|
+
pub fn toConst(global: Index) Constant {
|
|
2393
|
+
return @enumFromInt(@intFromEnum(Constant.first_global) + @intFromEnum(global));
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
pub fn toValue(global: Index) Value {
|
|
2397
|
+
return global.toConst().toValue();
|
|
2393
2398
|
}
|
|
2394
2399
|
|
|
2395
2400
|
pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
|
|
@@ -2450,6 +2455,42 @@ pub const Global = struct {
|
|
|
2450
2455
|
self.ptr(builder).kind = .{ .replaced = .none };
|
|
2451
2456
|
}
|
|
2452
2457
|
|
|
2458
|
+
/// Replaces whatever this `Global` currently contains with a new `Function`. Similar to
|
|
2459
|
+
/// `Builder.addFunction`, but the same `Global` is reused.
|
|
2460
|
+
pub fn toNewFunction(global: Index, builder: *Builder) Allocator.Error!Function.Index {
|
|
2461
|
+
try builder.functions.ensureUnusedCapacity(builder.gpa, 1);
|
|
2462
|
+
errdefer comptime unreachable;
|
|
2463
|
+
const function: Function.Index = @enumFromInt(builder.functions.items.len);
|
|
2464
|
+
builder.functions.appendAssumeCapacity(.{
|
|
2465
|
+
.global = global,
|
|
2466
|
+
.strip = undefined,
|
|
2467
|
+
});
|
|
2468
|
+
global.ptr(builder).kind = .{ .function = function };
|
|
2469
|
+
return function;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/// Replaces whatever this `Global` currently contains with a new `Variable`. Similar to
|
|
2473
|
+
/// `Builder.addVariable`, but the same `Global` is reused.
|
|
2474
|
+
pub fn toNewVariable(global: Index, builder: *Builder) Allocator.Error!Variable.Index {
|
|
2475
|
+
try builder.variables.ensureUnusedCapacity(builder.gpa, 1);
|
|
2476
|
+
errdefer comptime unreachable;
|
|
2477
|
+
const variable: Variable.Index = @enumFromInt(builder.variables.items.len);
|
|
2478
|
+
builder.variables.appendAssumeCapacity(.{ .global = global });
|
|
2479
|
+
global.ptr(builder).kind = .{ .variable = variable };
|
|
2480
|
+
return variable;
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
/// Replaces whatever this `Global` currently contains with a new `Alias`. Similar to
|
|
2484
|
+
/// `Builder.addAlias`, but the same `Global` is reused.
|
|
2485
|
+
pub fn toNewAlias(global: Index, builder: *Builder) Allocator.Error!Alias.Index {
|
|
2486
|
+
try builder.aliases.ensureUnusedCapacity(builder.gpa, 1);
|
|
2487
|
+
errdefer comptime unreachable;
|
|
2488
|
+
const alias: Alias.Index = @enumFromInt(builder.aliases.items.len);
|
|
2489
|
+
builder.aliass.appendAssumeCapacity(.{ .global = global, .aliasee = .none });
|
|
2490
|
+
global.ptr(builder).kind = .{ .alias = alias };
|
|
2491
|
+
return alias;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2453
2494
|
fn updateDsoLocal(self: Index, builder: *Builder) void {
|
|
2454
2495
|
const self_ptr = self.ptr(builder);
|
|
2455
2496
|
switch (self_ptr.linkage) {
|
|
@@ -2494,13 +2535,6 @@ pub const Global = struct {
|
|
|
2494
2535
|
self.renameAssumeCapacity(builder.next_replaced_global, builder);
|
|
2495
2536
|
self.ptr(builder).kind = .{ .replaced = other.unwrap(builder) };
|
|
2496
2537
|
}
|
|
2497
|
-
|
|
2498
|
-
fn getReplacement(self: Index, builder: *const Builder) Index {
|
|
2499
|
-
return switch (builder.globals.values()[@intFromEnum(self)].kind) {
|
|
2500
|
-
.replaced => |replacement| replacement,
|
|
2501
|
-
else => .none,
|
|
2502
|
-
};
|
|
2503
|
-
}
|
|
2504
2538
|
};
|
|
2505
2539
|
};
|
|
2506
2540
|
|
|
@@ -2593,22 +2627,6 @@ pub const Variable = struct {
|
|
|
2593
2627
|
return self.toConst(builder).toValue();
|
|
2594
2628
|
}
|
|
2595
2629
|
|
|
2596
|
-
pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
|
|
2597
|
-
return self.ptrConst(builder).global.setLinkage(linkage, builder);
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2600
|
-
pub fn setVisibility(self: Index, visibility: Visibility, builder: *Builder) void {
|
|
2601
|
-
return self.ptrConst(builder).global.setVisibility(visibility, builder);
|
|
2602
|
-
}
|
|
2603
|
-
|
|
2604
|
-
pub fn setDllStorageClass(self: Index, class: DllStorageClass, builder: *Builder) void {
|
|
2605
|
-
return self.ptrConst(builder).global.setDllStorageClass(class, builder);
|
|
2606
|
-
}
|
|
2607
|
-
|
|
2608
|
-
pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void {
|
|
2609
|
-
return self.ptrConst(builder).global.setUnnamedAddr(unnamed_addr, builder);
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
2630
|
pub fn setThreadLocal(self: Index, thread_local: ThreadLocal, builder: *Builder) void {
|
|
2613
2631
|
self.ptr(builder).thread_local = thread_local;
|
|
2614
2632
|
}
|
|
@@ -9692,8 +9710,12 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9692
9710
|
|
|
9693
9711
|
if (self.variables.items.len > 0) {
|
|
9694
9712
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9695
|
-
for (self.variables.items) |variable| {
|
|
9696
|
-
if
|
|
9713
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
9714
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
9715
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
9716
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
9717
|
+
else => continue,
|
|
9718
|
+
}
|
|
9697
9719
|
const global = variable.global.ptrConst(self);
|
|
9698
9720
|
metadata_formatter.need_comma = true;
|
|
9699
9721
|
defer metadata_formatter.need_comma = undefined;
|
|
@@ -9723,8 +9745,12 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9723
9745
|
|
|
9724
9746
|
if (self.aliases.items.len > 0) {
|
|
9725
9747
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9726
|
-
for (self.aliases.items) |alias| {
|
|
9727
|
-
if
|
|
9748
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
9749
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
9750
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
9751
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
9752
|
+
else => continue,
|
|
9753
|
+
}
|
|
9728
9754
|
const global = alias.global.ptrConst(self);
|
|
9729
9755
|
metadata_formatter.need_comma = true;
|
|
9730
9756
|
defer metadata_formatter.need_comma = undefined;
|
|
@@ -9750,7 +9776,11 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
9750
9776
|
defer attribute_groups.deinit(self.gpa);
|
|
9751
9777
|
|
|
9752
9778
|
for (0.., self.functions.items) |function_i, function| {
|
|
9753
|
-
if
|
|
9779
|
+
// Skip the function if its global has been repurposed for something else.
|
|
9780
|
+
switch (function.global.ptrConst(self).kind) {
|
|
9781
|
+
.function => |f| if (@intFromEnum(f) != function_i) continue,
|
|
9782
|
+
else => continue,
|
|
9783
|
+
}
|
|
9754
9784
|
if (need_newline) try w.writeByte('\n') else need_newline = true;
|
|
9755
9785
|
const function_index: Function.Index = @enumFromInt(function_i);
|
|
9756
9786
|
const global = function.global.ptrConst(self);
|
|
@@ -13687,20 +13717,32 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13687
13717
|
self.aliases.items.len,
|
|
13688
13718
|
);
|
|
13689
13719
|
|
|
13690
|
-
for (self.variables.items) |variable| {
|
|
13691
|
-
if
|
|
13720
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
13721
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
13722
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
13723
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
13724
|
+
else => continue,
|
|
13725
|
+
}
|
|
13692
13726
|
|
|
13693
13727
|
globals.putAssumeCapacity(variable.global, {});
|
|
13694
13728
|
}
|
|
13695
13729
|
|
|
13696
|
-
for (self.functions.items) |function| {
|
|
13697
|
-
if
|
|
13730
|
+
for (self.functions.items, 0..) |function, function_i| {
|
|
13731
|
+
// Skip the function if its global has been repurposed for something else.
|
|
13732
|
+
switch (function.global.ptrConst(self).kind) {
|
|
13733
|
+
.function => |f| if (@intFromEnum(f) != function_i) continue,
|
|
13734
|
+
else => continue,
|
|
13735
|
+
}
|
|
13698
13736
|
|
|
13699
13737
|
globals.putAssumeCapacity(function.global, {});
|
|
13700
13738
|
}
|
|
13701
13739
|
|
|
13702
|
-
for (self.aliases.items) |alias| {
|
|
13703
|
-
if
|
|
13740
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
13741
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
13742
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
13743
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
13744
|
+
else => continue,
|
|
13745
|
+
}
|
|
13704
13746
|
|
|
13705
13747
|
globals.putAssumeCapacity(alias.global, {});
|
|
13706
13748
|
}
|
|
@@ -13742,8 +13784,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13742
13784
|
defer section_map.deinit(self.gpa);
|
|
13743
13785
|
try section_map.ensureUnusedCapacity(self.gpa, globals.count());
|
|
13744
13786
|
|
|
13745
|
-
for (self.variables.items) |variable| {
|
|
13746
|
-
if
|
|
13787
|
+
for (self.variables.items, 0..) |variable, variable_i| {
|
|
13788
|
+
// Skip the variable if its global has been repurposed for something else.
|
|
13789
|
+
switch (variable.global.ptrConst(self).kind) {
|
|
13790
|
+
.variable => |v| if (@intFromEnum(v) != variable_i) continue,
|
|
13791
|
+
else => continue,
|
|
13792
|
+
}
|
|
13747
13793
|
|
|
13748
13794
|
const section = blk: {
|
|
13749
13795
|
if (variable.section == .none) break :blk 0;
|
|
@@ -13789,8 +13835,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13789
13835
|
});
|
|
13790
13836
|
}
|
|
13791
13837
|
|
|
13792
|
-
for (self.functions.items) |func| {
|
|
13793
|
-
if
|
|
13838
|
+
for (self.functions.items, 0..) |func, func_i| {
|
|
13839
|
+
// Skip the function if its global has been repurposed for something else.
|
|
13840
|
+
switch (func.global.ptrConst(self).kind) {
|
|
13841
|
+
.function => |f| if (@intFromEnum(f) != func_i) continue,
|
|
13842
|
+
else => continue,
|
|
13843
|
+
}
|
|
13794
13844
|
|
|
13795
13845
|
const section = blk: {
|
|
13796
13846
|
if (func.section == .none) break :blk 0;
|
|
@@ -13830,8 +13880,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
13830
13880
|
});
|
|
13831
13881
|
}
|
|
13832
13882
|
|
|
13833
|
-
for (self.aliases.items) |alias| {
|
|
13834
|
-
if
|
|
13883
|
+
for (self.aliases.items, 0..) |alias, alias_i| {
|
|
13884
|
+
// Skip the alias if its global has been repurposed for something else.
|
|
13885
|
+
switch (alias.global.ptrConst(self).kind) {
|
|
13886
|
+
.alias => |a| if (@intFromEnum(a) != alias_i) continue,
|
|
13887
|
+
else => continue,
|
|
13888
|
+
}
|
|
13835
13889
|
|
|
13836
13890
|
const strtab = alias.global.strtab(self);
|
|
13837
13891
|
|
|
@@ -14635,8 +14689,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
|
|
|
14635
14689
|
};
|
|
14636
14690
|
|
|
14637
14691
|
for (self.functions.items, 0..) |func, func_index| {
|
|
14692
|
+
// Skip the function if its global has been repurposed for something else.
|
|
14693
|
+
switch (func.global.ptrConst(self).kind) {
|
|
14694
|
+
.function => |f| if (@intFromEnum(f) != func_index) continue,
|
|
14695
|
+
else => continue,
|
|
14696
|
+
}
|
|
14697
|
+
|
|
14638
14698
|
const FunctionBlock = ir.ModuleBlock.FunctionBlock;
|
|
14639
|
-
if (func.global.getReplacement(self) != .none) continue;
|
|
14640
14699
|
|
|
14641
14700
|
if (func.instructions.len == 0) continue;
|
|
14642
14701
|
|