2024-11-17 07:54:10 -08:00
|
|
|
//===-- ClangOpcodesEmitter.cpp - constexpr interpreter opcodes -----------===//
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These tablegen backends emit Clang AST node tables
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-10-01 23:12:57 +00:00
|
|
|
#include "TableGenBackends.h"
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/StringMatcher.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ClangOpcodesEmitter {
|
2024-09-11 10:51:23 -07:00
|
|
|
const RecordKeeper &Records;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
unsigned NumTypes;
|
|
|
|
|
|
|
|
public:
|
2024-09-11 10:51:23 -07:00
|
|
|
ClangOpcodesEmitter(const RecordKeeper &R)
|
2024-01-28 16:01:32 +01:00
|
|
|
: Records(R), NumTypes(Records.getAllDerivedDefinitions("Type").size()) {}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
void run(raw_ostream &OS);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Emits the opcode name for the opcode enum.
|
|
|
|
/// The name is obtained by concatenating the name with the list of types.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitEnum(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the switch case and the invocation in the interpreter.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitInterp(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the disassembler.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitDisasm(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the byte code emitter method.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitEmitter(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the prototype.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitProto(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the prototype to dispatch from a type.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitGroup(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
/// Emits the evaluator method.
|
2023-05-19 09:30:24 +02:00
|
|
|
void EmitEval(raw_ostream &OS, StringRef N, const Record *R);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void PrintTypes(raw_ostream &OS, ArrayRef<const Record *> Types);
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
};
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void Enumerate(const Record *R, StringRef N,
|
|
|
|
std::function<void(ArrayRef<const Record *>, Twine)> &&F) {
|
2024-09-16 06:35:34 -07:00
|
|
|
SmallVector<const Record *, 2> TypePath;
|
2024-01-28 15:36:20 +01:00
|
|
|
const auto *Types = R->getValueAsListInit("Types");
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
std::function<void(size_t, const Twine &)> Rec;
|
|
|
|
Rec = [&TypePath, Types, &Rec, &F](size_t I, const Twine &ID) {
|
|
|
|
if (I >= Types->size()) {
|
|
|
|
F(TypePath, ID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-28 15:36:20 +01:00
|
|
|
if (const auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
|
|
|
|
for (const auto *Type :
|
2024-10-01 14:30:38 -07:00
|
|
|
TypeClass->getDef()->getValueAsListOfDefs("Types")) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
TypePath.push_back(Type);
|
|
|
|
Rec(I + 1, ID + Type->getName());
|
|
|
|
TypePath.pop_back();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintFatalError("Expected a type class");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Rec(0, N);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void ClangOpcodesEmitter::run(raw_ostream &OS) {
|
2024-01-28 16:01:32 +01:00
|
|
|
for (const auto *Opcode : Records.getAllDerivedDefinitions("Opcode")) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
// The name is the record name, unless overriden.
|
|
|
|
StringRef N = Opcode->getValueAsString("Name");
|
|
|
|
if (N.empty())
|
|
|
|
N = Opcode->getName();
|
|
|
|
|
|
|
|
EmitEnum(OS, N, Opcode);
|
|
|
|
EmitInterp(OS, N, Opcode);
|
|
|
|
EmitDisasm(OS, N, Opcode);
|
|
|
|
EmitProto(OS, N, Opcode);
|
|
|
|
EmitGroup(OS, N, Opcode);
|
|
|
|
EmitEmitter(OS, N, Opcode);
|
|
|
|
EmitEval(OS, N, Opcode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitEnum(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#ifdef GET_OPCODE_NAMES\n";
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N, [&OS](ArrayRef<const Record *>, const Twine &ID) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "OP_" << ID << ",\n";
|
|
|
|
});
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#ifdef GET_INTERP\n";
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N,
|
|
|
|
[this, R, &OS, &N](ArrayRef<const Record *> TS, const Twine &ID) {
|
|
|
|
bool CanReturn = R->getValueAsBit("CanReturn");
|
|
|
|
bool ChangesPC = R->getValueAsBit("ChangesPC");
|
2024-10-01 14:30:38 -07:00
|
|
|
const auto &Args = R->getValueAsListOfDefs("Args");
|
2023-05-19 09:30:24 +02:00
|
|
|
|
|
|
|
OS << "case OP_" << ID << ": {\n";
|
|
|
|
|
|
|
|
if (CanReturn)
|
|
|
|
OS << " bool DoReturn = (S.Current == StartFrame);\n";
|
|
|
|
|
|
|
|
// Emit calls to read arguments.
|
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
2024-02-21 14:15:39 +01:00
|
|
|
const auto *Arg = Args[I];
|
|
|
|
bool AsRef = Arg->getValueAsBit("AsRef");
|
|
|
|
|
|
|
|
if (AsRef)
|
|
|
|
OS << " const auto &V" << I;
|
|
|
|
else
|
|
|
|
OS << " const auto V" << I;
|
2023-05-19 09:30:24 +02:00
|
|
|
OS << " = ";
|
2024-02-21 14:15:39 +01:00
|
|
|
OS << "ReadArg<" << Arg->getValueAsString("Name")
|
2023-05-19 09:30:24 +02:00
|
|
|
<< ">(S, PC);\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit a call to the template method and pass arguments.
|
|
|
|
OS << " if (!" << N;
|
|
|
|
PrintTypes(OS, TS);
|
|
|
|
OS << "(S";
|
|
|
|
if (ChangesPC)
|
|
|
|
OS << ", PC";
|
|
|
|
else
|
|
|
|
OS << ", OpPC";
|
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I)
|
|
|
|
OS << ", V" << I;
|
|
|
|
OS << "))\n";
|
|
|
|
OS << " return false;\n";
|
|
|
|
|
|
|
|
// Bail out if interpreter returned.
|
|
|
|
if (CanReturn) {
|
|
|
|
OS << " if (!S.Current || S.Current->isRoot())\n";
|
|
|
|
OS << " return true;\n";
|
|
|
|
|
|
|
|
OS << " if (DoReturn)\n";
|
|
|
|
OS << " return true;\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " continue;\n";
|
|
|
|
OS << "}\n";
|
|
|
|
});
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#ifdef GET_DISASM\n";
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "case OP_" << ID << ":\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " PrintName(\"" << ID << "\");\n";
|
|
|
|
OS << " OS << \"\\t\"";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2024-10-01 14:30:38 -07:00
|
|
|
for (const auto *Arg : R->getValueAsListOfDefs("Args")) {
|
[Clang interpreter] Avoid storing pointers at unaligned locations
The Clang interpreter's bytecode uses a packed stream of bytes
representation, but also wants to have some opcodes take pointers as
arguments, which are currently embedded in the bytecode directly.
However, CHERI, and thus Arm's upcoming experimental Morello prototype,
provide spatial memory safety for C/C++ by implementing language-level
(and sub-language-level) pointers as capabilities, which track bounds,
permissions and validity in hardware. This uses tagged memory with a
single tag bit at every capability-aligned address, and so storing
pointers to unaligned addresses results in the tag being stripped,
leading to a tag fault when the pointer is ultimately dereferenced at a
later point.
In order to support a stricter C/C++ implementation like CHERI, we no
longer store pointers directly in the bytecode, instead storing them in
a table and embedding the index in the bytecode.
Reviewed By: nand
Differential Revision: https://reviews.llvm.org/D97606
2021-07-28 14:49:37 +01:00
|
|
|
OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)";
|
|
|
|
OS << " << \" \"";
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " << \"\\n\";\n";
|
|
|
|
OS << " continue;\n";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
});
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
if (R->getValueAsBit("HasCustomLink"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "#ifdef GET_LINK_IMPL\n";
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) {
|
2024-10-01 14:30:38 -07:00
|
|
|
const auto &Args = R->getValueAsListOfDefs("Args");
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
// Emit the list of arguments.
|
|
|
|
OS << "bool ByteCodeEmitter::emit" << ID << "(";
|
2024-02-21 14:15:39 +01:00
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
|
|
|
const auto *Arg = Args[I];
|
|
|
|
bool AsRef = Arg->getValueAsBit("AsRef");
|
|
|
|
auto Name = Arg->getValueAsString("Name");
|
|
|
|
|
|
|
|
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
|
|
|
|
<< I << ", ";
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "const SourceInfo &L) {\n";
|
|
|
|
|
|
|
|
// Emit a call to write the opcodes.
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " return emitOp<";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
|
|
|
if (I != 0)
|
|
|
|
OS << ", ";
|
|
|
|
OS << Args[I]->getValueAsString("Name");
|
|
|
|
}
|
|
|
|
OS << ">(OP_" << ID;
|
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I)
|
|
|
|
OS << ", A" << I;
|
|
|
|
OS << ", L);\n";
|
|
|
|
OS << "}\n";
|
|
|
|
});
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#if defined(GET_EVAL_PROTO) || defined(GET_LINK_PROTO)\n";
|
2024-10-01 14:30:38 -07:00
|
|
|
auto Args = R->getValueAsListOfDefs("Args");
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N, [&OS, &Args](ArrayRef<const Record *> TS, const Twine &ID) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "bool emit" << ID << "(";
|
2024-02-21 14:15:39 +01:00
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
|
|
|
const auto *Arg = Args[I];
|
|
|
|
bool AsRef = Arg->getValueAsBit("AsRef");
|
|
|
|
auto Name = Arg->getValueAsString("Name");
|
|
|
|
|
|
|
|
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "")
|
|
|
|
<< ", ";
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "const SourceInfo &);\n";
|
|
|
|
});
|
|
|
|
|
|
|
|
// Emit a template method for custom emitters to have less to implement.
|
|
|
|
auto TypeCount = R->getValueAsListInit("Types")->size();
|
|
|
|
if (R->getValueAsBit("HasCustomEval") && TypeCount) {
|
|
|
|
OS << "#if defined(GET_EVAL_PROTO)\n";
|
|
|
|
OS << "template<";
|
|
|
|
for (size_t I = 0; I < TypeCount; ++I) {
|
|
|
|
if (I != 0)
|
|
|
|
OS << ", ";
|
|
|
|
OS << "PrimType";
|
|
|
|
}
|
|
|
|
OS << ">\n";
|
|
|
|
OS << "bool emit" << N << "(";
|
2024-01-28 15:36:20 +01:00
|
|
|
for (const auto *Arg : Args)
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << Arg->getValueAsString("Name") << ", ";
|
|
|
|
OS << "const SourceInfo &);\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
if (!R->getValueAsBit("HasGroup"))
|
|
|
|
return;
|
|
|
|
|
2024-01-28 15:36:20 +01:00
|
|
|
const auto *Types = R->getValueAsListInit("Types");
|
2024-10-01 14:30:38 -07:00
|
|
|
const auto &Args = R->getValueAsListOfDefs("Args");
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
Twine EmitFuncName = "emit" + N;
|
|
|
|
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
// Emit the prototype of the group emitter in the header.
|
|
|
|
OS << "#if defined(GET_EVAL_PROTO) || defined(GET_LINK_PROTO)\n";
|
2024-03-07 19:37:24 +01:00
|
|
|
OS << "[[nodiscard]] bool " << EmitFuncName << "(";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
for (size_t I = 0, N = Types->size(); I < N; ++I)
|
|
|
|
OS << "PrimType, ";
|
|
|
|
for (auto *Arg : Args)
|
|
|
|
OS << Arg->getValueAsString("Name") << ", ";
|
|
|
|
OS << "const SourceInfo &I);\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
|
|
|
|
// Emit the dispatch implementation in the source.
|
|
|
|
OS << "#if defined(GET_EVAL_IMPL) || defined(GET_LINK_IMPL)\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << "bool\n";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#if defined(GET_EVAL_IMPL)\n";
|
|
|
|
OS << "EvalEmitter\n";
|
|
|
|
OS << "#else\n";
|
|
|
|
OS << "ByteCodeEmitter\n";
|
|
|
|
OS << "#endif\n";
|
2023-05-19 09:30:24 +02:00
|
|
|
OS << "::" << EmitFuncName << "(";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
for (size_t I = 0, N = Types->size(); I < N; ++I)
|
|
|
|
OS << "PrimType T" << I << ", ";
|
2024-02-21 14:15:39 +01:00
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
|
|
|
const auto *Arg = Args[I];
|
|
|
|
bool AsRef = Arg->getValueAsBit("AsRef");
|
|
|
|
auto Name = Arg->getValueAsString("Name");
|
|
|
|
|
|
|
|
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
|
|
|
|
<< I << ", ";
|
|
|
|
}
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "const SourceInfo &I) {\n";
|
|
|
|
|
|
|
|
std::function<void(size_t, const Twine &)> Rec;
|
2024-09-16 06:35:34 -07:00
|
|
|
SmallVector<const Record *, 2> TS;
|
2023-05-19 09:30:24 +02:00
|
|
|
Rec = [this, &Rec, &OS, Types, &Args, R, &TS, N,
|
|
|
|
EmitFuncName](size_t I, const Twine &ID) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
if (I >= Types->size()) {
|
|
|
|
// Print a call to the emitter method.
|
|
|
|
// Custom evaluator methods dispatch to template methods.
|
|
|
|
if (R->getValueAsBit("HasCustomEval")) {
|
|
|
|
OS << "#ifdef GET_LINK_IMPL\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " return emit" << ID << "\n";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
OS << "#else\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " return emit" << N;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
PrintTypes(OS, TS);
|
|
|
|
OS << "\n#endif\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " ";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
} else {
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " return emit" << ID;
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << "(";
|
|
|
|
for (size_t I = 0; I < Args.size(); ++I) {
|
|
|
|
OS << "A" << I << ", ";
|
|
|
|
}
|
|
|
|
OS << "I);\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a switch statement selecting T.
|
|
|
|
if (auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " switch (T" << I << ") {\n";
|
2024-10-01 14:30:38 -07:00
|
|
|
auto Cases = TypeClass->getDef()->getValueAsListOfDefs("Types");
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
for (auto *Case : Cases) {
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " case PT_" << Case->getName() << ":\n";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
TS.push_back(Case);
|
|
|
|
Rec(I + 1, ID + Case->getName());
|
|
|
|
TS.pop_back();
|
|
|
|
}
|
|
|
|
// Emit a default case if not all types are present.
|
|
|
|
if (Cases.size() < NumTypes)
|
2023-05-19 09:30:24 +02:00
|
|
|
OS << " default: llvm_unreachable(\"invalid type: " << EmitFuncName
|
|
|
|
<< "\");\n";
|
2021-02-27 01:26:26 +00:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " llvm_unreachable(\"invalid enum value\");\n";
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
} else {
|
|
|
|
PrintFatalError("Expected a type class");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Rec(0, N);
|
|
|
|
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
|
|
|
|
const Record *R) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
if (R->getValueAsBit("HasCustomEval"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "#ifdef GET_EVAL_IMPL\n";
|
2023-05-19 09:30:24 +02:00
|
|
|
Enumerate(R, N,
|
|
|
|
[this, R, &N, &OS](ArrayRef<const Record *> TS, const Twine &ID) {
|
2024-10-01 14:30:38 -07:00
|
|
|
auto Args = R->getValueAsListOfDefs("Args");
|
2023-05-19 09:30:24 +02:00
|
|
|
|
|
|
|
OS << "bool EvalEmitter::emit" << ID << "(";
|
2024-02-21 14:15:39 +01:00
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I) {
|
|
|
|
const auto *Arg = Args[I];
|
|
|
|
bool AsRef = Arg->getValueAsBit("AsRef");
|
|
|
|
auto Name = Arg->getValueAsString("Name");
|
|
|
|
|
|
|
|
OS << (AsRef ? "const " : " ") << Name << " "
|
|
|
|
<< (AsRef ? "&" : "") << "A" << I << ", ";
|
|
|
|
}
|
2023-05-19 09:30:24 +02:00
|
|
|
OS << "const SourceInfo &L) {\n";
|
|
|
|
OS << " if (!isActive()) return true;\n";
|
|
|
|
OS << " CurrentSource = L;\n";
|
|
|
|
|
|
|
|
OS << " return " << N;
|
|
|
|
PrintTypes(OS, TS);
|
|
|
|
OS << "(S, OpPC";
|
|
|
|
for (size_t I = 0, N = Args.size(); I < N; ++I)
|
|
|
|
OS << ", A" << I;
|
|
|
|
OS << ");\n";
|
|
|
|
OS << "}\n";
|
|
|
|
});
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
|
|
|
|
OS << "#endif\n";
|
|
|
|
}
|
|
|
|
|
2023-05-19 09:30:24 +02:00
|
|
|
void ClangOpcodesEmitter::PrintTypes(raw_ostream &OS,
|
|
|
|
ArrayRef<const Record *> Types) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
if (Types.empty())
|
|
|
|
return;
|
|
|
|
OS << "<";
|
|
|
|
for (size_t I = 0, N = Types.size(); I < N; ++I) {
|
|
|
|
if (I != 0)
|
|
|
|
OS << ", ";
|
|
|
|
OS << "PT_" << Types[I]->getName();
|
|
|
|
}
|
|
|
|
OS << ">";
|
|
|
|
}
|
|
|
|
|
2024-09-11 10:51:23 -07:00
|
|
|
void clang::EmitClangOpcodes(const RecordKeeper &Records, raw_ostream &OS) {
|
[Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.
Reviewers: Bigcheese, jfb, rsmith
Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64146
llvm-svn: 371834
2019-09-13 09:46:16 +00:00
|
|
|
ClangOpcodesEmitter(Records).run(OS);
|
|
|
|
}
|