2015-06-30 07:51:55 +08:00
|
|
|
//===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file provides WebAssembly-specific target descriptions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "WebAssemblyMCTargetDesc.h"
|
|
|
|
#include "InstPrinter/WebAssemblyInstPrinter.h"
|
|
|
|
#include "WebAssemblyMCAsmInfo.h"
|
2016-01-13 04:30:51 +08:00
|
|
|
#include "WebAssemblyTargetStreamer.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "wasm-mc-target-desc"
|
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "WebAssemblyGenInstrInfo.inc"
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "WebAssemblyGenSubtargetInfo.inc"
|
|
|
|
|
2015-07-11 02:23:10 +08:00
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "WebAssemblyGenRegisterInfo.inc"
|
|
|
|
|
2016-01-08 08:43:54 +08:00
|
|
|
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
|
|
|
|
const Triple &TT) {
|
2015-07-29 01:23:07 +08:00
|
|
|
return new WebAssemblyMCAsmInfo(TT);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
2016-07-01 02:25:11 +08:00
|
|
|
static void adjustCodeGenOpts(const Triple & /*TT*/, Reloc::Model /*RM*/,
|
|
|
|
CodeModel::Model &CM) {
|
2016-02-18 07:20:43 +08:00
|
|
|
CodeModel::Model M = (CM == CodeModel::Default || CM == CodeModel::JITDefault)
|
|
|
|
? CodeModel::Large
|
|
|
|
: CM;
|
|
|
|
if (M != CodeModel::Large)
|
|
|
|
report_fatal_error("Non-large code models are not supported yet");
|
|
|
|
}
|
|
|
|
|
2016-01-08 08:43:54 +08:00
|
|
|
static MCInstrInfo *createMCInstrInfo() {
|
2015-11-06 03:28:16 +08:00
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitWebAssemblyMCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2016-01-13 05:27:55 +08:00
|
|
|
static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
|
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitWebAssemblyMCRegisterInfo(X, 0);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2016-01-08 08:43:54 +08:00
|
|
|
static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
|
|
|
|
unsigned SyntaxVariant,
|
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
const MCInstrInfo &MII,
|
|
|
|
const MCRegisterInfo &MRI) {
|
2016-01-20 13:54:22 +08:00
|
|
|
assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
|
2015-07-29 01:23:07 +08:00
|
|
|
return new WebAssemblyInstPrinter(MAI, MII, MRI);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
2016-01-08 08:43:54 +08:00
|
|
|
static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
|
|
|
|
const MCRegisterInfo & /*MRI*/,
|
2016-01-20 05:31:41 +08:00
|
|
|
MCContext & /*Ctx*/) {
|
|
|
|
return createWebAssemblyMCCodeEmitter(MCII);
|
2016-01-08 08:43:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MCAsmBackend *createAsmBackend(const Target & /*T*/,
|
|
|
|
const MCRegisterInfo & /*MRI*/,
|
2016-07-26 05:41:42 +08:00
|
|
|
const Triple &TT, StringRef /*CPU*/,
|
|
|
|
const MCTargetOptions & /*Options*/) {
|
2016-01-08 08:43:54 +08:00
|
|
|
return createWebAssemblyAsmBackend(TT);
|
|
|
|
}
|
|
|
|
|
2016-01-12 11:30:06 +08:00
|
|
|
static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
|
|
|
|
StringRef FS) {
|
|
|
|
return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
|
|
|
|
}
|
|
|
|
|
2016-01-13 04:30:51 +08:00
|
|
|
static MCTargetStreamer *
|
|
|
|
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) {
|
|
|
|
return new WebAssemblyTargetELFStreamer(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
|
|
|
|
formatted_raw_ostream &OS,
|
|
|
|
MCInstPrinter * /*InstPrint*/,
|
|
|
|
bool /*isVerboseAsm*/) {
|
|
|
|
return new WebAssemblyTargetAsmStreamer(S, OS);
|
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeWebAssemblyTargetMC() {
|
2015-07-02 05:42:34 +08:00
|
|
|
for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
|
2015-06-30 07:51:55 +08:00
|
|
|
// Register the MC asm info.
|
2016-01-08 08:43:54 +08:00
|
|
|
RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2015-11-06 03:28:16 +08:00
|
|
|
// Register the MC instruction info.
|
2016-01-08 08:43:54 +08:00
|
|
|
TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
|
2015-11-06 03:28:16 +08:00
|
|
|
|
2016-02-18 07:20:43 +08:00
|
|
|
// Register the MC codegen info.
|
2016-07-01 02:25:11 +08:00
|
|
|
TargetRegistry::registerMCAdjustCodeGenOpts(*T, adjustCodeGenOpts);
|
2016-02-18 07:20:43 +08:00
|
|
|
|
2016-01-13 05:27:55 +08:00
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
// Register the MCInstPrinter.
|
2016-01-08 08:43:54 +08:00
|
|
|
TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
|
2015-12-17 09:39:00 +08:00
|
|
|
|
2016-01-08 09:18:00 +08:00
|
|
|
// Register the MC code emitter.
|
2016-01-08 08:43:54 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
|
2015-12-17 09:39:00 +08:00
|
|
|
|
2016-01-08 09:18:00 +08:00
|
|
|
// Register the ASM Backend.
|
2016-01-08 08:43:54 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
|
2016-01-12 11:30:06 +08:00
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
|
2016-01-13 04:30:51 +08:00
|
|
|
|
|
|
|
// Register the object target streamer.
|
|
|
|
TargetRegistry::RegisterObjectTargetStreamer(*T,
|
|
|
|
createObjectTargetStreamer);
|
|
|
|
// Register the asm target streamer.
|
|
|
|
TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
}
|