llvm-project/llvm/utils/TableGen/WebAssemblyStackifierEmitter.cpp
Thomas Lively 211874d2f3 [WebAssembly] TableGen backend for stackifying instructions
Summary:
The new stackification backend generates the giant switch statement
used to translate instructions to their stackified forms. I did this
because it was more interesting than adding all the different vector
versions of the various SIMD instructions to the switch statment
manually.

Reviewers: aardappel, aheejin, dschuff

Subscribers: mgorny, sbc100, jgravelle-google, sunfish, jfb, llvm-commits

Differential Revision: https://reviews.llvm.org/D51318

llvm-svn: 340781
2018-08-27 22:02:09 +00:00

32 lines
1.1 KiB
C++

//===- WebAssemblyStackifierEmitter.cpp - Stackifier cases ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file emits the switch statement cases to translate WebAssembly
// instructions to their stack forms.
//
//===----------------------------------------------------------------------===//
#include "WebAssemblyDisassemblerEmitter.h"
#include "llvm/TableGen/Record.h"
namespace llvm {
void EmitWebAssemblyStackifier(RecordKeeper &RK, raw_ostream &OS) {
Record *InstrClass = RK.getClass("WebAssemblyInst");
for (auto &RecordPair : RK.getDefs()) {
if (!RecordPair.second->isSubClassOf(InstrClass)) continue;
bool IsStackBased = RecordPair.second->getValueAsBit("StackBased");
if (IsStackBased) continue;
OS << " case WebAssembly::" << RecordPair.first << ": return "
<< "WebAssembly::" << RecordPair.first << "_S; break;\n";
}
}
} // namespace llvm