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) {
|
2017-02-22 09:23:18 +08:00
|
|
|
if (TT.isOSBinFormatELF())
|
|
|
|
return new WebAssemblyMCAsmInfoELF(TT);
|
2015-07-29 01:23:07 +08:00
|
|
|
return new WebAssemblyMCAsmInfo(TT);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
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*/,
|
2017-02-10 08:14:42 +08:00
|
|
|
MCContext &Ctx) {
|
2017-06-17 07:59:10 +08:00
|
|
|
return createWebAssemblyMCCodeEmitter(MCII);
|
2016-01-08 08:43:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MCAsmBackend *createAsmBackend(const Target & /*T*/,
|
2018-01-03 17:30:39 +08:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-01-08 08:43:54 +08:00
|
|
|
const MCRegisterInfo & /*MRI*/,
|
2016-07-26 05:41:42 +08:00
|
|
|
const MCTargetOptions & /*Options*/) {
|
2018-01-03 17:30:39 +08:00
|
|
|
return createWebAssemblyAsmBackend(STI.getTargetTriple());
|
2016-01-08 08:43:54 +08:00
|
|
|
}
|
|
|
|
|
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 *
|
2017-02-22 09:23:18 +08:00
|
|
|
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
|
|
|
const Triple &TT = STI.getTargetTriple();
|
|
|
|
if (TT.isOSBinFormatELF())
|
|
|
|
return new WebAssemblyTargetELFStreamer(S);
|
|
|
|
|
|
|
|
return new WebAssemblyTargetWasmStreamer(S);
|
2016-01-13 04:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T :
|
|
|
|
{&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
|
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-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
|
|
|
}
|
|
|
|
}
|
2016-10-25 07:27:49 +08:00
|
|
|
|
2017-03-15 04:23:22 +08:00
|
|
|
wasm::ValType WebAssembly::toValType(const MVT &Ty) {
|
2016-10-25 07:27:49 +08:00
|
|
|
switch (Ty.SimpleTy) {
|
2017-03-15 04:23:22 +08:00
|
|
|
case MVT::i32: return wasm::ValType::I32;
|
|
|
|
case MVT::i64: return wasm::ValType::I64;
|
|
|
|
case MVT::f32: return wasm::ValType::F32;
|
|
|
|
case MVT::f64: return wasm::ValType::F64;
|
2018-03-08 12:05:37 +08:00
|
|
|
case MVT::ExceptRef: return wasm::ValType::EXCEPT_REF;
|
2016-10-25 07:27:49 +08:00
|
|
|
default: llvm_unreachable("unexpected type");
|
|
|
|
}
|
|
|
|
}
|