//===-- W65816Subtarget.h - Define Subtarget for the W65816 ----*- C++ -*--===//
//
// 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 declares the W65816 specific subclass of TargetSubtargetInfo.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_W65816_W65816SUBTARGET_H
#define LLVM_LIB_TARGET_W65816_W65816SUBTARGET_H

#include "W65816FrameLowering.h"
#include "W65816ISelLowering.h"
#include "W65816InstrInfo.h"
#include "W65816RegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DataLayout.h"
#include <memory>
#include <string>

#define GET_SUBTARGETINFO_HEADER
#include "W65816GenSubtargetInfo.inc"

namespace llvm {

class StringRef;

class W65816Subtarget : public W65816GenSubtargetInfo {
  virtual void anchor();

  W65816InstrInfo InstrInfo;
  W65816TargetLowering TLInfo;
  std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
  W65816FrameLowering FrameLowering;

  // Assembler-side M/X processor-status mode bits.  Backing fields for the
  // FeatureMLow/MHigh/XLow/XHigh SubtargetFeatures in W65816.td.  These
  // gate the AsmMatcher between the _Imm8 and _Imm16 forms of width-
  // sensitive instructions (LDA/CMP/.../LDX/.../CPY) when the user toggles
  // the mode via the .a8/.a16/.i8/.i16 (and .as/.al/.xs/.xl) directives.
  // Default subtarget has MLow + XLow set (matches the C ABI).  Not used
  // by codegen — clang emits LDA_Imm8 etc. via direct BuildMI().
public:
  bool MLow  = false;
  bool MHigh = false;
  bool XLow  = false;
  bool XHigh = false;

public:
  W65816Subtarget(const Triple &TT, const std::string &CPU,
                  const std::string &FS, const TargetMachine &TM);

  ~W65816Subtarget() override;

  W65816Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);

  /// Parses features string setting specified subtarget options.  Generated
  /// by TableGen.
  void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);

  const TargetFrameLowering *getFrameLowering() const override {
    return &FrameLowering;
  }
  const W65816InstrInfo *getInstrInfo() const override { return &InstrInfo; }
  const W65816RegisterInfo *getRegisterInfo() const override {
    return &getInstrInfo()->getRegisterInfo();
  }
  const W65816TargetLowering *getTargetLowering() const override {
    return &TLInfo;
  }
  const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
};

} // namespace llvm

#endif
