mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
autodoc: add cmpxchg_strong/weak
This commit is contained in:
parent
4530b446b1
commit
f13db1ce18
@ -1113,6 +1113,44 @@ var zigAnalysis;
|
||||
const sliceIndex = zigAnalysis.exprs[expr.sliceIndex];
|
||||
return exprName(sliceIndex, opts);
|
||||
}
|
||||
case "cmpxchg":{
|
||||
console.log(expr);
|
||||
const typeIndex = zigAnalysis.exprs[expr.cmpxchg.type];
|
||||
const ptrIndex = zigAnalysis.exprs[expr.cmpxchg.ptr];
|
||||
const expectedValueIndex = zigAnalysis.exprs[expr.cmpxchg.expected_value];
|
||||
const newValueIndex = zigAnalysis.exprs[expr.cmpxchg.new_value];
|
||||
const successOrderIndex = zigAnalysis.exprs[expr.cmpxchg.success_order];
|
||||
const failureOrderIndex = zigAnalysis.exprs[expr.cmpxchg.failure_order];
|
||||
|
||||
const type = exprName(typeIndex, opts);
|
||||
const ptr = exprName(ptrIndex, opts);
|
||||
const expectedValue = exprName(expectedValueIndex, opts);
|
||||
const newValue = exprName(newValueIndex, opts);
|
||||
const successOrder = exprName(successOrderIndex, opts);
|
||||
const failureOrder = exprName(failureOrderIndex, opts);
|
||||
|
||||
let fnName = "@";
|
||||
|
||||
switch (expr.cmpxchg.name) {
|
||||
case "cmpxchg_strong": {
|
||||
fnName += "cmpxchgStrong"
|
||||
break;
|
||||
}
|
||||
case "cmpxchg_weak": {
|
||||
fnName += "cmpxchgWeak"
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.log("There's only cmpxchg_strong and cmpxchg_weak");
|
||||
}
|
||||
}
|
||||
|
||||
return fnName + "(" + type + ", " + ptr + ", " + expectedValue + ", "+ newValue + ", "+"." +successOrder + ", "+ "." +failureOrder + ")";
|
||||
}
|
||||
case "cmpxchgIndex": {
|
||||
const cmpxchgIndex = zigAnalysis.exprs[expr.cmpxchgIndex];
|
||||
return exprName(cmpxchgIndex, opts);
|
||||
}
|
||||
case "switchOp":{
|
||||
let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];
|
||||
let node_name_ = expr.switchOp.node_name;
|
||||
|
@ -675,6 +675,8 @@ const DocData = struct {
|
||||
string: []const u8, // direct value
|
||||
sliceIndex: usize,
|
||||
slice: Slice,
|
||||
cmpxchgIndex: usize,
|
||||
cmpxchg: Cmpxchg,
|
||||
builtin: Builtin,
|
||||
builtinIndex: usize,
|
||||
builtinBin: BuiltinBin,
|
||||
@ -709,6 +711,7 @@ const DocData = struct {
|
||||
end: ?usize = null,
|
||||
sentinel: ?usize = null, // index in `exprs`
|
||||
};
|
||||
const Cmpxchg = struct { name: []const u8, type: usize, ptr: usize, expected_value: usize, new_value: usize, success_order: usize, failure_order: usize };
|
||||
const As = struct {
|
||||
typeRefArg: ?usize, // index in `exprs`
|
||||
exprArg: usize, // index in `exprs`
|
||||
@ -814,6 +817,16 @@ const DocData = struct {
|
||||
options,
|
||||
w,
|
||||
),
|
||||
.cmpxchg => |v| try std.json.stringify(
|
||||
struct { cmpxchg: Cmpxchg }{ .cmpxchg = v },
|
||||
options,
|
||||
w,
|
||||
),
|
||||
.cmpxchgIndex => |v| try std.json.stringify(
|
||||
struct { cmpxchgIndex: usize }{ .cmpxchgIndex = v },
|
||||
options,
|
||||
w,
|
||||
),
|
||||
.binOp => |v| try std.json.stringify(
|
||||
struct { binOp: BinOp }{ .binOp = v },
|
||||
options,
|
||||
@ -990,6 +1003,67 @@ fn walkInstruction(
|
||||
need_type,
|
||||
);
|
||||
},
|
||||
.cmpxchg_strong, .cmpxchg_weak => {
|
||||
const pl_node = data[inst_index].pl_node;
|
||||
const extra = file.zir.extraData(Zir.Inst.Cmpxchg, pl_node.payload_index);
|
||||
|
||||
const last_type_index = self.exprs.items.len;
|
||||
const last_type = self.exprs.items[last_type_index - 1];
|
||||
const type_index = self.exprs.items.len;
|
||||
try self.exprs.append(self.arena, last_type);
|
||||
|
||||
const ptr_index = self.exprs.items.len;
|
||||
var ptr: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
parent_scope,
|
||||
extra.data.ptr,
|
||||
false,
|
||||
);
|
||||
try self.exprs.append(self.arena, ptr.expr);
|
||||
|
||||
const expected_value_index = self.exprs.items.len;
|
||||
var expected_value: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
parent_scope,
|
||||
extra.data.expected_value,
|
||||
false,
|
||||
);
|
||||
try self.exprs.append(self.arena, expected_value.expr);
|
||||
|
||||
const new_value_index = self.exprs.items.len;
|
||||
var new_value: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
parent_scope,
|
||||
extra.data.new_value,
|
||||
false,
|
||||
);
|
||||
try self.exprs.append(self.arena, new_value.expr);
|
||||
|
||||
const success_order_index = self.exprs.items.len;
|
||||
var success_order: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
parent_scope,
|
||||
extra.data.success_order,
|
||||
false,
|
||||
);
|
||||
try self.exprs.append(self.arena, success_order.expr);
|
||||
|
||||
const failure_order_index = self.exprs.items.len;
|
||||
var failure_order: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
parent_scope,
|
||||
extra.data.failure_order,
|
||||
false,
|
||||
);
|
||||
try self.exprs.append(self.arena, failure_order.expr);
|
||||
|
||||
const cmpxchg_index = self.exprs.items.len;
|
||||
try self.exprs.append(self.arena, .{ .cmpxchg = .{ .name = @tagName(tags[inst_index]), .type = type_index, .ptr = ptr_index, .expected_value = expected_value_index, .new_value = new_value_index, .success_order = success_order_index, .failure_order = failure_order_index } });
|
||||
return DocData.WalkResult{
|
||||
.typeRef = .{ .type = @enumToInt(Ref.type_type) },
|
||||
.expr = .{ .cmpxchgIndex = cmpxchg_index },
|
||||
};
|
||||
},
|
||||
.str => {
|
||||
const str = data[inst_index].str.get(file.zir);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user