DoxigAlpha

writeConst

Function parameters

Parameters

#
writer:anytype
T:type
value:T

Expressions can be evaluated in different contexts, each requiring its own set of inputs.

Types

#
Context
Expressions can be evaluated in different contexts, each requiring its own set of inputs.

A stack machine that can decode and run DWARF expressions.

Functions

#
StackMachine
A stack machine that can decode and run DWARF expressions.

Error sets in this namespace

Error Sets

#

Source

Implementation

#
pub fn writeConst(writer: anytype, comptime T: type, value: T) !void {
    if (@typeInfo(T) != .int) @compileError("Constants must be integers");

    switch (T) {
        u8, i8, u16, i16, u32, i32, u64, i64 => {
            try writer.writeByte(switch (T) {
                u8 => OP.const1u,
                i8 => OP.const1s,
                u16 => OP.const2u,
                i16 => OP.const2s,
                u32 => OP.const4u,
                i32 => OP.const4s,
                u64 => OP.const8u,
                i64 => OP.const8s,
                else => unreachable,
            });

            try writer.writeInt(T, value, options.endian);
        },
        else => switch (@typeInfo(T).int.signedness) {
            .unsigned => {
                try writer.writeByte(OP.constu);
                try leb.writeUleb128(writer, value);
            },
            .signed => {
                try writer.writeByte(OP.consts);
                try leb.writeIleb128(writer, value);
            },
        },
    }
}