Sign in

    x64_target

    x64 target pipeline from semantic MachV to native code

    x64
    x86-64
    compiler
    codegen
    Download zip
    Author
    Version
    0.4.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    208

    #x64_target

    x64 backend for target-neutral MachV.

    This module owns x64 instruction selection, validation and lowering of an embedding-provided internal ABI contract, register allocation policy, frame layout, machine-code emission, relocations, and final linking. Verified MilkIR first becomes target-neutral MachV; this package then lowers that semantic function into x64 Target VCode.

    #Package

    • Milky2018/x64_target: x64 Target VCode, lowering, allocation, frame layout, emission, and linking.

    #When to use it

    Use this module after producing a verified Milky2018/machv.Function and before installing generated bytes into executable memory.

    #Example: define the internal ABI

    ///|
    test "validate the x64 internal ABI" {
    InternalAbi::new(7, 10, [6, 2, 1, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7], [0, 2], [
    0, 1,
    ])
    |> ignore
    }

    #Integration

    Use lower followed by compile for the efficient aggregate path, or call allocate, plan_frame, and emit individually when inspecting checkpoints. The returned UnlinkedCodeObject contains bytes, relocations, and safepoints; the embedding application supplies symbol addresses and executable memory.

    compile accepts an optional on_event callback that reports generic stage boundaries and a read-only allocation summary. This lets an embedding collect metrics without coupling the target to a product metrics system. The callback must not mutate compiler inputs.

    InternalAbiError

    pub suberror InternalAbiError {
    InvalidRegister(role~ : String, index~ : Int)
    DuplicateRegister(role~ : String, index~ : Int)
    ContextRegisterReused(index~ : Int)
    ResultAreaRegisterReused(index~ : Int)
    InvalidSignature(message~ : String)
    } derive(Eq,
    Debug
    )

    TargetVCodeVerifyError

    pub suberror TargetVCodeVerifyError {
    CommonFailure(cause~ :
    VCodeVerifyError
    )
    InvalidInstruction(instruction~ :
    Instruction
    , message~ : String)
    } derive(Eq,
    Debug
    )

    X64AllocationError

    X64CompileError

    pub suberror X64CompileError {
    TargetValidationFailed(cause~ : TargetVCodeVerifyError)
    AllocationFailed(cause~ : X64AllocationError)
    FramePlanningFailed(cause~ : X64FrameError)
    EmissionFailed(cause~ : X64EmitError)
    } derive(
    Debug
    )

    X64EmitError

    pub suberror X64EmitError {
    InvalidFrame(cause~ : X64FrameError)
    InvalidCodeObject(cause~ :
    CodeObjectVerifyError
    )
    InvalidParallelMove(cause~ :
    MoveResolveError
    )
    InvalidCallTransfer(cause~ :
    CallTransferError
    )
    UnresolvedStackMove
    MissingStackObjectArea
    MissingResultArea
    UnexpectedStackOperand(instruction~ :
    Instruction
    , operand~ : Int)
    FrameOffsetOutOfRange(offset~ : Int)
    InvalidScalarMemoryAccess
    InvalidFloatInstruction
    InvalidVectorInstruction
    ScratchRegisterUnavailable
    InvalidConversionInstruction
    BranchTargetMissing(block~ :
    Block
    )
    BranchOutOfRange(offset~ : Int, bits~ : Int)
    } derive(
    Debug
    )

    X64FrameError

    pub suberror X64FrameError {
    InvalidAllocation(cause~ : X64AllocationError)
    InvalidGenericFrame(cause~ :
    FrameVerifyError
    )
    InvalidSavedRegister(reg~ :
    PhysicalReg
    , offset~ : Int)
    InvalidStackSlot(slot~ :
    StackSlot
    )
    OutgoingAreaMismatch(expected~ : Int, actual~ : Int)
    ResultAreaMismatch(expected~ : Int, actual~ : Int)
    TailAreaMismatch(expected_incoming~ : Int, actual_incoming~ : Int, expected_tail~ : Int, actual_tail~ : Int)
    InvalidStackObjectArea(message~ : String)
    SavedRegisterSetMismatch
    } derive(
    Debug
    )

    X64LinkError

    pub suberror X64LinkError {
    InvalidCodeObject(message~ : String)
    InvalidCodeBase(address~ : Int64)
    UnresolvedRelocation(index~ : Int)
    RelocationOutOfRange(index~ : Int)
    UnsupportedRelocation(index~ : Int)
    } derive(Eq,
    Debug
    )

    X64LowerError

    pub suberror X64LowerError {
    InvalidSemantic(cause~ :
    MachVVerifyError
    )
    MissingMappedValue(value_index~ : Int)
    UnsupportedOperation(block_index~ : Int, instruction_index~ : Int, operation~ :
    Operation
    )
    UnsupportedAbi(message~ : String)
    BuildFailure(cause~ :
    VCodeBuildError
    )
    InvalidTarget(cause~ : TargetVCodeVerifyError)
    } derive(
    Debug
    )

    CallArgumentLocation

    type CallArgumentLocation derive(Eq,
    Debug
    )

    CallLayout

    type CallLayout derive(Eq,
    Debug
    )

    CallResultLocation

    type CallResultLocation derive(Eq,
    Debug
    )

    GprWidth

    pub(all) enum GprWidth {
    W32
    W64
    } derive(Eq,
    Debug
    )

    InternalAbi

    pub struct InternalAbi {
    // private fields
    }

    InternalAbi::new

    fn InternalAbi::new(context_argument : Int, result_area_argument : Int, integer_arguments : Array[Int], fp_arguments : Array[Int], integer_results : Array[Int], fp_results : Array[Int]) -> InternalAbi raise InternalAbiError

    InternalCallPlan

    pub struct InternalCallPlan {
    // private fields
    } derive(Eq,
    Debug
    )

    LoweringContext

    pub struct LoweringContext {
    // private fields
    }

    LoweringContext::new

    fn LoweringContext::new(internal_abi : InternalAbi) -> LoweringContext

    LoweringContext::with_environment_field

    fn LoweringContext::with_environment_field(self : LoweringContext, field :
    EnvironmentField
    , offsets : Array[Int]) -> LoweringContext

    X64Condition

    pub(all) enum X64Condition {
    Eq
    Ne
    Lt
    Le
    Gt
    Ge
    Lo
    Ls
    Hi
    Hs
    } derive(Eq,
    Debug
    )

    X64FloatBinary

    pub(all) enum X64FloatBinary {
    Add
    Sub
    Mul
    Div
    Min
    Max
    CopySign
    } derive(Eq,
    Debug
    )

    X64FloatCondition

    pub(all) enum X64FloatCondition {
    Equal
    NotEqual
    LessThan
    LessOrEqual
    GreaterThan
    GreaterOrEqual
    Ordered
    Unordered
    } derive(Eq,
    Debug
    )

    X64FloatTernary

    pub(all) enum X64FloatTernary {
    Fmadd
    Fmsub
    Fnmadd
    Fnmsub
    } derive(Eq,
    Debug
    )

    X64FloatTrapCondition

    pub(all) enum X64FloatTrapCondition {
    Unordered
    LessThan
    LessOrEqual
    GreaterOrEqual
    } derive(Eq,
    Debug
    )

    X64FloatUnary

    pub(all) enum X64FloatUnary {
    Negate
    Absolute
    SquareRoot
    Ceil
    Floor
    Truncate
    Nearest
    } derive(Eq,
    Debug
    )

    X64Frame

    pub struct X64Frame {
    // private fields
    }

    X64Frame::alignment

    fn X64Frame::alignment(self : X64Frame) -> Int

    X64Frame::frame_size

    fn X64Frame::frame_size(self : X64Frame) -> Int

    X64Frame::incoming_args_size

    fn X64Frame::incoming_args_size(self : X64Frame) -> Int

    X64Frame::outgoing_args_size

    fn X64Frame::outgoing_args_size(self : X64Frame) -> Int

    X64Frame::saved_registers

    X64Frame::slot_offset

    fn X64Frame::slot_offset(self : X64Frame, slot :
    StackSlot
    ) -> Int?

    X64Frame::stack_object_offset

    fn X64Frame::stack_object_offset(self : X64Frame, object : X64StackObject) -> Int?

    X64Frame::summary

    fn X64Frame::summary(self : X64Frame) -> String

    X64Frame::tail_args_size

    fn X64Frame::tail_args_size(self : X64Frame) -> Int

    X64Inst

    pub(all) enum X64Inst {
    IncomingReg(
    ValueType
    ,
    PhysicalReg
    )
    IncomingStack(
    ValueType
    , Int)
    IncomingResultArea(
    PhysicalReg
    )
    IncomingCallResult(
    ValueType
    ,
    PhysicalReg
    )
    IncomingCallAreaResult(
    ValueType
    , Int)
    OutgoingReg(
    ValueType
    ,
    PhysicalReg
    )
    OutgoingAreaResult(
    ValueType
    , Int)
    KeepAlive(
    ValueType
    )
    LoadConstant(GprWidth, UInt64)
    LoadVectorConstant(UInt64, UInt64)
    LoadNull(
    ValueType
    )
    LoadAddress(X64Address)
    StackAddress(X64StackObject)
    LoadFloatConstant(
    ValueType
    , UInt64)
    Move(
    ValueType
    )
    CarrierMove(
    ValueType
    ,
    ValueType
    )
    Select(
    ValueType
    )
    VectorSelect
    VectorSplat(
    VectorLane
    )
    VectorExtractLane(
    VectorLane
    , Int,
    Signedness
    ?)
    VectorReplaceLane(
    VectorLane
    , Int)
    VectorShuffle(FixedArray[Int])
    VectorSwizzle
    VectorBitwise(
    VectorBitwiseOp
    )
    VectorIntUnary(
    VectorLane
    , X64VectorIntUnary)
    VectorIntBinary(
    VectorLane
    , X64VectorIntBinary)
    VectorIntShift(
    VectorLane
    ,
    VectorIntShiftOp
    )
    VectorIntCompare(
    VectorLane
    ,
    VectorIntComparison
    )
    VectorConvert(X64VectorConversion)
    VectorPredicate(X64VectorPredicate)
    VectorFloatUnary(
    VectorLane
    ,
    VectorFloatUnaryOp
    )
    VectorFloatBinary(
    VectorLane
    ,
    VectorFloatBinaryOp
    )
    VectorFloatTernary(
    VectorLane
    ,
    FloatTernaryOp
    )
    VectorFloatCompare(
    VectorLane
    ,
    VectorFloatComparison
    )
    VectorPairwiseAddI16x8
    VectorRelaxedDot8To16
    IntUnary(GprWidth, X64IntUnary)
    IntBinary(GprWidth, X64IntBinary)
    PopulationCount(GprWidth)
    IntHighMultiply(GprWidth,
    Signedness
    )
    IntWithOverflow(GprWidth,
    IntOverflowOp
    )
    IntRemainder(GprWidth,
    Signedness
    )
    TrapIfZero(GprWidth)
    TrapIfSignedDivOverflow(GprWidth)
    CompareSet(GprWidth, X64Condition)
    ReferenceCompareSet(
    ValueType
    , X64Condition)
    FloatUnary(
    ValueType
    , X64FloatUnary)
    FloatBinary(
    ValueType
    , X64FloatBinary)
    FloatTernary(
    ValueType
    , X64FloatTernary)
    FloatCompareSet(
    ValueType
    , X64FloatCondition)
    TrapIfFloat(
    ValueType
    , X64FloatTrapCondition)
    Convert(X64Conversion)
    AddAddress
    ScalarLoad(
    AccessWidth
    ,
    LoadExtension
    ,
    ValueType
    , UInt64)
    ScalarStore(
    AccessWidth
    ,
    ValueType
    , UInt64)
    VectorLoad128(UInt64)
    VectorStore128(UInt64)
    VectorLoadSplat(
    VectorLane
    , UInt64)
    VectorLoadExtend(
    VectorLane
    ,
    Signedness
    , UInt64)
    VectorLoadZero(
    AccessWidth
    , UInt64)
    VectorLoadLane(
    VectorLane
    , Int, UInt64)
    VectorStoreLane(
    VectorLane
    , Int, UInt64)
    AtomicLoad(
    AccessWidth
    ,
    ValueType
    )
    AtomicStore(
    AccessWidth
    ,
    ValueType
    )
    AtomicRmw(
    AccessWidth
    ,
    ValueType
    ,
    AtomicRmwOp
    )
    AtomicCompareExchange(
    AccessWidth
    ,
    ValueType
    )
    AtomicFence
    SafepointMarker
    PlatformCall(
    ExternalSymbol
    ,
    Signature
    )
    ReturnsTwicePlatformCall(
    ExternalSymbol
    ,
    Signature
    )
    InternalCall(
    CodeSymbol
    ,
    Signature
    , InternalCallPlan)
    InternalCallIndirect(
    Signature
    , InternalCallPlan)
    TailCallDirect(
    CodeSymbol
    ,
    Signature
    , InternalCallPlan)
    TailCallIndirect(
    Signature
    , InternalCallPlan)
    Jump
    BranchNonZero32
    Switch(GprWidth, Array[UInt64])
    Trap(
    TrapReason
    )
    Return
    } derive(Eq,
    Debug
    )

    X64IntBinary

    pub(all) enum X64IntBinary {
    Add
    Sub
    Mul
    And
    Orr
    Eor
    Lsl
    Asr
    Lsr
    Ror
    Sdiv
    Udiv
    } derive(Eq,
    Debug
    )

    X64IntUnary

    pub(all) enum X64IntUnary {
    Mvn
    Clz
    Rbit
    Neg
    } derive(Eq,
    Debug
    )

    X64LinkPlan

    pub struct X64LinkPlan {
    // private fields
    } derive(
    Debug
    )

    X64LinkPlan::code

    fn X64LinkPlan::code(self : X64LinkPlan) -> Array[Byte]

    fn X64LinkPlan::link(self : X64LinkPlan, code_address : Int64, resolve : (
    RelocationTarget
    ) -> Int64?) -> Array[Byte] raise X64LinkError

    X64LinkPlan::veneer_offsets

    fn X64LinkPlan::veneer_offsets(self : X64LinkPlan) -> Array[Int]

    X64StackObject

    pub struct X64StackObject {
    offset : Int
    size : Int
    alignment : Int
    area_size : Int
    area_alignment : Int
    } derive(Eq,
    Debug
    )

    X64StackObject::new

    fn X64StackObject::new(offset : Int, size : Int, alignment : Int, area_size : Int, area_alignment : Int) -> X64StackObject

    X64VectorIntBinary

    pub(all) enum X64VectorIntBinary {
    Add
    Sub
    Mul
    AverageUnsigned
    Min(
    Signedness
    )
    Max(
    Signedness
    )
    SaturatingAdd(
    Signedness
    )
    SaturatingSub(
    Signedness
    )
    ExtendMultiply(
    VectorHalf
    ,
    Signedness
    )
    Dot16To32Signed
    Q15MultiplyRoundedSaturating
    } derive(Eq,
    Debug
    )

    X64VectorIntUnary

    pub(all) enum X64VectorIntUnary {
    Absolute
    Negate
    PopulationCount
    ExtendAddPairwise(
    Signedness
    )
    } derive(Eq,
    Debug
    )

    X64VectorPredicate

    pub(all) enum X64VectorPredicate {
    AnyTrue
    AllTrue(
    VectorLane
    )
    BitMask(
    VectorLane
    )
    } derive(Eq,
    Debug
    )

    compile

    Compiles selected x64 VCode through allocation, frame planning, and emission. Each stage validates the invariant it introduces without revalidating invariants already established by this pipeline.

    on_event is an observation-only seam. It must not mutate function or any compiler object reachable while the callback runs.

    verify_allocation

    verify_frame

    verify_vcode

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io