//===-- W65816MCAsmInfo.cpp - W65816 asm properties -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the implementation of the W65816MCAsmInfo class.
//
//===----------------------------------------------------------------------===//

#include "W65816MCAsmInfo.h"
#include "llvm/MC/MCDwarf.h"
using namespace llvm;

void W65816MCAsmInfo::anchor() {}

W65816MCAsmInfo::W65816MCAsmInfo(const Triple &TT) {
  // The 65816 address space is 24 bits but LLVM's ELF writer emits 32-bit
  // pointer-sized DWARF entries; store pointers as 32 bits for DWARF.
  CodePointerSize = 4;
  CalleeSaveStackSlotSize = 2;

  CommentString = ";";

  AlignmentIsInBytes = false;
  UsesELFSectionDirectiveForBSS = true;

  // Recognize the 65xx-traditional `$XX` hex prefix and `%bbb` binary
  // prefix.  Without this the lexer emits a bare `$` Dollar token
  // (which parseExpression treats as the current PC) and silently
  // assembles `lda $42` to `lda 0` (caught hand-testing 2026-05-14).
  // C-style `0x42` continues to work.
  UseMotorolaIntegers = true;

  SupportsDebugInformation = true;

  // C++ exceptions use the SJLJ model.  Selecting SJLJ here makes
  // TargetPassConfig::addPassesToHandleExceptions add SjLjEHPrepare,
  // which converts invoke/landingpad/resume IR into eh.sjlj.* intrinsics
  // + a function-context struct in the function's prologue.  The
  // backend then lowers those intrinsics in W65816ISelLowering, and
  // the runtime side lives in runtime/src/libcxxabiSjlj.c.
  ExceptionsType = ExceptionHandling::SjLj;
}
