[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
tbaederr wrote: That failure looks like it's just a case of https://github.com/llvm/llvm-project/issues/54972 https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `ppc64le-lld-multistage-test` running on `ppc64le-lld-multistage-test` while building `clang` at step 7 "test-build-stage1-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/168/builds/446 Here is the relevant piece of the build log for the reference: ``` Step 7 (test-build-stage1-unified-tree-check-all) failure: test (failure) TEST 'Clang :: Driver/cl-inputs.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 4: /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin/clang --driver-mode=cl /TC -### -- /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c 2>&1 | /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin/FileCheck -check-prefix=TC /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c + /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin/clang --driver-mode=cl /TC -### -- /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c + /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin/FileCheck -check-prefix=TC /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c:7:12: error: TC-NOT: excluded string found in input // TC-NOT: note ^ :8:99: note: found here "link.exe" "-out:cl-inputs.exe" "-libpath:lib" "-libpath:atlmfc/lib" "-nologo" "/tmp/lit-tmp-hoegnote/cl-inputs-72e484.obj" ^~~~ Input file: Check file: /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c -dump-input=help explains the following input dump. Input was: << 1: clang version 19.0.0git (https://github.com/llvm/llvm-project.git 468d668c5c4031366ae38804927b450f9faf409c) 2: Target: powerpc64le-pc-windows-msvc 3: Thread model: posix 4: InstalledDir: /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin 5: Build config: +assertions 6: clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found] 7: "/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/bin/clang-19" "-cc1" "-triple" "powerpc64le-pc-windows-msvc19.33.0" "-emit-obj" "-mincremental-linker-compatible" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "cl-inputs.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-relaxed-aliasing" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-target-cpu" "ppc64le" "-mfloat-abi" "hard" "-target-abi" "elfv2" "-D_MT" "-flto-visibility-public-std" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-stack-protector" "2" "-fdiagnostics-format" "msvc" "-fdebug-compilation-dir=/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/tools/clang/test/Driver" "-fcoverage-compilation-dir=/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/tools/clang/test/Driver" "-resource-dir" "/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/lib/clang/19" "-internal-isystem" "/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage1/lib/clang/19/include" "-ferror-limit" "19" "-fno-signed-char" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.33" "-fskip-odr-check-in-gmf" "-fdelayed-template-parsing" "-faddrsig" "-o" "/tmp/lit-tmp-hoegnote/cl-inputs-72e484.obj" "-x" "c" "/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/test/Driver/cl-inputs.c" 8: "link.exe" "-out:cl-inputs.exe" "-libpath:lib" "-libpath:atlmfc/lib" "-nologo" "/tmp/lit-tmp-hoegnote/cl-inputs-72e484.obj" not:7
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/83683 >From 74550f244eed465d4f0db1787eecb73a09d5881a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 2 Mar 2024 17:00:26 +0100 Subject: [PATCH] [clang][Interp] Merge ByteCode{Stmt,Expr}Gen --- clang/lib/AST/CMakeLists.txt |3 +- clang/lib/AST/Interp/ByteCodeStmtGen.cpp | 734 clang/lib/AST/Interp/ByteCodeStmtGen.h| 91 -- .../{ByteCodeExprGen.cpp => Compiler.cpp} | 1002 ++--- .../Interp/{ByteCodeExprGen.h => Compiler.h} | 93 +- clang/lib/AST/Interp/Context.cpp | 13 +- clang/lib/AST/Interp/EvalEmitter.h|1 + clang/lib/AST/Interp/Program.cpp |1 - 8 files changed, 911 insertions(+), 1027 deletions(-) delete mode 100644 clang/lib/AST/Interp/ByteCodeStmtGen.cpp delete mode 100644 clang/lib/AST/Interp/ByteCodeStmtGen.h rename clang/lib/AST/Interp/{ByteCodeExprGen.cpp => Compiler.cpp} (81%) rename clang/lib/AST/Interp/{ByteCodeExprGen.h => Compiler.h} (87%) diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt index 0328666d59b1f..ceaad8d3c5a86 100644 --- a/clang/lib/AST/CMakeLists.txt +++ b/clang/lib/AST/CMakeLists.txt @@ -65,8 +65,7 @@ add_clang_library(clangAST FormatString.cpp InheritViz.cpp Interp/ByteCodeEmitter.cpp - Interp/ByteCodeExprGen.cpp - Interp/ByteCodeStmtGen.cpp + Interp/Compiler.cpp Interp/Context.cpp Interp/Descriptor.cpp Interp/Disasm.cpp diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp deleted file mode 100644 index 0618ec1aa8f58..0 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ /dev/null @@ -1,734 +0,0 @@ -//===--- ByteCodeStmtGen.cpp - Code generator for expressions ---*- 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 -// -//===--===// - -#include "ByteCodeStmtGen.h" -#include "ByteCodeEmitter.h" -#include "Context.h" -#include "Function.h" -#include "PrimType.h" - -using namespace clang; -using namespace clang::interp; - -namespace clang { -namespace interp { - -/// Scope managing label targets. -template class LabelScope { -public: - virtual ~LabelScope() { } - -protected: - LabelScope(ByteCodeStmtGen *Ctx) : Ctx(Ctx) {} - /// ByteCodeStmtGen instance. - ByteCodeStmtGen *Ctx; -}; - -/// Sets the context for break/continue statements. -template class LoopScope final : public LabelScope { -public: - using LabelTy = typename ByteCodeStmtGen::LabelTy; - using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy; - - LoopScope(ByteCodeStmtGen *Ctx, LabelTy BreakLabel, -LabelTy ContinueLabel) - : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel), -OldContinueLabel(Ctx->ContinueLabel) { -this->Ctx->BreakLabel = BreakLabel; -this->Ctx->ContinueLabel = ContinueLabel; - } - - ~LoopScope() { -this->Ctx->BreakLabel = OldBreakLabel; -this->Ctx->ContinueLabel = OldContinueLabel; - } - -private: - OptLabelTy OldBreakLabel; - OptLabelTy OldContinueLabel; -}; - -// Sets the context for a switch scope, mapping labels. -template class SwitchScope final : public LabelScope { -public: - using LabelTy = typename ByteCodeStmtGen::LabelTy; - using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy; - using CaseMap = typename ByteCodeStmtGen::CaseMap; - - SwitchScope(ByteCodeStmtGen *Ctx, CaseMap &, - LabelTy BreakLabel, OptLabelTy DefaultLabel) - : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel), -OldDefaultLabel(this->Ctx->DefaultLabel), -OldCaseLabels(std::move(this->Ctx->CaseLabels)) { -this->Ctx->BreakLabel = BreakLabel; -this->Ctx->DefaultLabel = DefaultLabel; -this->Ctx->CaseLabels = std::move(CaseLabels); - } - - ~SwitchScope() { -this->Ctx->BreakLabel = OldBreakLabel; -this->Ctx->DefaultLabel = OldDefaultLabel; -this->Ctx->CaseLabels = std::move(OldCaseLabels); - } - -private: - OptLabelTy OldBreakLabel; - OptLabelTy OldDefaultLabel; - CaseMap OldCaseLabels; -}; - -} // namespace interp -} // namespace clang - -template -bool ByteCodeStmtGen::emitLambdaStaticInvokerBody( -const CXXMethodDecl *MD) { - assert(MD->isLambdaStaticInvoker()); - assert(MD->hasBody()); - assert(cast(MD->getBody())->body_empty()); - - const CXXRecordDecl *ClosureClass = MD->getParent(); - const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator(); - assert(ClosureClass->captures_begin() == ClosureClass->captures_end()); - const Function *Func = this->getFunction(LambdaCallOp); - if (!Func) -return false; - assert(Func->hasThisPointer()); - assert(Func->getNumParams() == (MD->getNumParams() + 1 +
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: https://github.com/AaronBallman approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/AaronBallman commented: Splitting the code across a few implementation files might be a reasonable approach, but in general, I'm fine with how this is proceeding. I reviewed the changes as best I could and they seem reasonable to me. https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: Ping https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 5143a1241362616840af826d18c067025dae bac423c77cd62604f6bd27d258a91832fc0bc0d2 -- clang/lib/AST/Interp/Context.cpp clang/lib/AST/Interp/EvalEmitter.h clang/lib/AST/Interp/Program.cpp clang/test/AST/Interp/literals.cpp clang/lib/AST/Interp/Compiler.cpp clang/lib/AST/Interp/Compiler.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 60d3d899d2..e04c04cd73 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -1815,8 +1815,7 @@ bool Compiler::VisitTypeTraitExpr(const TypeTraitExpr *E) { } template -bool Compiler::VisitArrayTypeTraitExpr( -const ArrayTypeTraitExpr *E) { +bool Compiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) { if (DiscardResult) return true; return this->emitConst(E->getValue(), E); @@ -2290,8 +2289,7 @@ bool Compiler::VisitPseudoObjectExpr(const PseudoObjectExpr *E) { } template -bool Compiler::VisitPackIndexingExpr( -const PackIndexingExpr *E) { +bool Compiler::VisitPackIndexingExpr(const PackIndexingExpr *E) { return this->delegate(E->getSelectedExpr()); } @@ -3815,8 +3813,7 @@ bool Compiler::VisitUnaryOperator(const UnaryOperator *E) { } template -bool Compiler::VisitComplexUnaryOperator( -const UnaryOperator *E) { +bool Compiler::VisitComplexUnaryOperator(const UnaryOperator *E) { const Expr *SubExpr = E->getSubExpr(); assert(SubExpr->getType()->isAnyComplexType()); @@ -4129,9 +4126,8 @@ bool Compiler::emitComplexBoolCast(const Expr *E) { } template -bool Compiler::emitComplexComparison(const Expr *LHS, - const Expr *RHS, - const BinaryOperator *E) { +bool Compiler::emitComplexComparison(const Expr *LHS, const Expr *RHS, + const BinaryOperator *E) { assert(E->isComparisonOp()); assert(!Initializing); assert(!DiscardResult); `` https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: tbaederr wrote: > Sorry, I thought you were still doing some investigation. Ah, sorry, I was just trying to say that this is how far I'm going to investigate at that point. :) > I can live with either approach; the CRTP way doesn't seem too awful to me > and retains the separation. But the unified interface also doesn't seem too > awful to me given the relationship between `Stmt` and `Expr` in our AST. > Given your preference for the unified interface, I'd be okay moving forward > with that. I would probably merge them but then split the implementation into different files, e.g. one for common expressions, one for statements, but also one for `_Complex` stuff, etc. Does that sound better? https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: AaronBallman wrote: > Ping Sorry, I thought you were still doing some investigation. I can live with either approach; the CRTP way doesn't seem too awful to me and retains the separation. But the unified interface also doesn't seem too awful to me given the relationship between `Stmt` and `Expr` in our AST. Given your preference for the unified interface, I'd be okay moving forward with that. Any other opinions @erichkeane @cor3ntin @shafik ? https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: Ping https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: tbaederr wrote: > How ugly does CRTP get though? Looks like this: https://github.com/tbaederr/llvm-project/commit/ae37a17e30978cbe8e42799d26308b2e4e7b0115 Not really a big fan. But I'm now stuck with ``` mold: error: undefined symbol: lib/libclangAST.a(ByteCodeExprGen.cpp.o): clang::interp::ByteCodeStmtGen::visitStmt(clang::Stmt const*) ``` and need to investigate something else. https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: AaronBallman wrote: > But that's not the problem I have in mind. My problem is the other way > around: when `ByteCodeExprGen` needs to generate code for statements. It has > no `visitStmt` function, because that's only implemented in the subclass. Ah, so the choices boil down to using a single interface like this, or doing something like CRTP (or virtual dispatch)? I like the separation of concerns between the stmt and expr emitters, but I'm not opposed to unifying them. How ugly does CRTP get though? https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: tbaederr wrote: > So ByteCodeExprGen can definitely visit statements and expressions. Well yes, the possibility is there, but it doesn't implement any of the functionality when visiting statements. :) > Can't ByteCodeStmtGen call ByteCodeExprGen::VisitBlah() so that the base > class could also handle situations the subclass wasn't prepared to handle? That's what's happening in `ByteCodeStmtGen::visitStmt()` in case the statement is an `Expr` - `ByteCodeStmtGen` just calls `ByteCodeExprGen::discard()`. But that's not the problem I have in mind. My problem is the other way around: when `ByteCodeExprGen` needs to generate code for statements. It has no `visitStmt` function, because that's only implemented in the subclass. https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: AaronBallman wrote: > When implementing support for `StmtExpr`, I ran into a problem: there is no > way for `ByteCodeExprGen` to visit a statement. Previously, `ByteCodeStmtGen` > inherited from `ByteCodeExprGen`, so the former could visit expressions, but > the latter couldn't visit statements. I'm a bit confused. ``` class ByteCodeExprGen : public ConstStmtVisitor, bool>, public Emitter { ``` So `ByteCodeExprGen` can definitely visit statements and expressions. Can't `ByteCodeStmtGen` call `ByteCodeExprGen::VisitBlah()` so that the base class could also handle situations the subclass wasn't prepared to handle? https://github.com/llvm/llvm-project/pull/83683 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes When implementing support for `StmtExpr`, I ran into a problem: there is no way for `ByteCodeExprGen` to visit a statement. Previously, `ByteCodeStmtGen` inherited from `ByteCodeExprGen`, so the former could visit expressions, but the latter couldn't visit statements. This branch merges the two, renames the result to `Compiler` and uses it to implement `StmtExpr` support. Apart from implementing `StmtExpr` support, this entire branch is NFC of course, but I was wondering if this makes sense for everyone involved. --- Patch is 91.90 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/83683.diff 9 Files Affected: - (modified) clang/lib/AST/CMakeLists.txt (+1-2) - (removed) clang/lib/AST/Interp/ByteCodeStmtGen.cpp (-684) - (removed) clang/lib/AST/Interp/ByteCodeStmtGen.h (-91) - (renamed) clang/lib/AST/Interp/Compiler.cpp (+785-136) - (renamed) clang/lib/AST/Interp/Compiler.h (+64-23) - (modified) clang/lib/AST/Interp/Context.cpp (+6-7) - (modified) clang/lib/AST/Interp/EvalEmitter.h (+1) - (modified) clang/lib/AST/Interp/Program.cpp (-1) - (modified) clang/test/AST/Interp/literals.cpp (+14) ``diff diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt index 6ea1ca3e76cf33..9a17e6b6a3b462 100644 --- a/clang/lib/AST/CMakeLists.txt +++ b/clang/lib/AST/CMakeLists.txt @@ -65,9 +65,8 @@ add_clang_library(clangAST FormatString.cpp InheritViz.cpp Interp/ByteCodeEmitter.cpp - Interp/ByteCodeExprGen.cpp + Interp/Compiler.cpp Interp/ByteCodeGenError.cpp - Interp/ByteCodeStmtGen.cpp Interp/Context.cpp Interp/Descriptor.cpp Interp/Disasm.cpp diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp deleted file mode 100644 index d9213b12cbd08b..00 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ /dev/null @@ -1,684 +0,0 @@ -//===--- ByteCodeStmtGen.cpp - Code generator for expressions ---*- 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 -// -//===--===// - -#include "ByteCodeStmtGen.h" -#include "ByteCodeEmitter.h" -#include "ByteCodeGenError.h" -#include "Context.h" -#include "Function.h" -#include "PrimType.h" - -using namespace clang; -using namespace clang::interp; - -namespace clang { -namespace interp { - -/// Scope managing label targets. -template class LabelScope { -public: - virtual ~LabelScope() { } - -protected: - LabelScope(ByteCodeStmtGen *Ctx) : Ctx(Ctx) {} - /// ByteCodeStmtGen instance. - ByteCodeStmtGen *Ctx; -}; - -/// Sets the context for break/continue statements. -template class LoopScope final : public LabelScope { -public: - using LabelTy = typename ByteCodeStmtGen::LabelTy; - using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy; - - LoopScope(ByteCodeStmtGen *Ctx, LabelTy BreakLabel, -LabelTy ContinueLabel) - : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel), -OldContinueLabel(Ctx->ContinueLabel) { -this->Ctx->BreakLabel = BreakLabel; -this->Ctx->ContinueLabel = ContinueLabel; - } - - ~LoopScope() { -this->Ctx->BreakLabel = OldBreakLabel; -this->Ctx->ContinueLabel = OldContinueLabel; - } - -private: - OptLabelTy OldBreakLabel; - OptLabelTy OldContinueLabel; -}; - -// Sets the context for a switch scope, mapping labels. -template class SwitchScope final : public LabelScope { -public: - using LabelTy = typename ByteCodeStmtGen::LabelTy; - using OptLabelTy = typename ByteCodeStmtGen::OptLabelTy; - using CaseMap = typename ByteCodeStmtGen::CaseMap; - - SwitchScope(ByteCodeStmtGen *Ctx, CaseMap &, - LabelTy BreakLabel, OptLabelTy DefaultLabel) - : LabelScope(Ctx), OldBreakLabel(Ctx->BreakLabel), -OldDefaultLabel(this->Ctx->DefaultLabel), -OldCaseLabels(std::move(this->Ctx->CaseLabels)) { -this->Ctx->BreakLabel = BreakLabel; -this->Ctx->DefaultLabel = DefaultLabel; -this->Ctx->CaseLabels = std::move(CaseLabels); - } - - ~SwitchScope() { -this->Ctx->BreakLabel = OldBreakLabel; -this->Ctx->DefaultLabel = OldDefaultLabel; -this->Ctx->CaseLabels = std::move(OldCaseLabels); - } - -private: - OptLabelTy OldBreakLabel; - OptLabelTy OldDefaultLabel; - CaseMap OldCaseLabels; -}; - -} // namespace interp -} // namespace clang - -template -bool ByteCodeStmtGen::emitLambdaStaticInvokerBody( -const CXXMethodDecl *MD) { - assert(MD->isLambdaStaticInvoker()); - assert(MD->hasBody()); - assert(cast(MD->getBody())->body_empty()); - - const CXXRecordDecl *ClosureClass = MD->getParent(); - const CXXMethodDecl