Hash :
5a4bfd61
Author :
Date :
2024-01-12T17:15:39
Metal: Separate struct definition from function return
The EmitMetal pass in shader translator does not handle writing the
defintion of a structure that is declared in the return type of a
function, such as:
struct Foo { float val; } foo() {
...
}
This change adds a new pass, SeparateStructFromFunctionDeclarations, to
separate the definition and declaration of struct variables in function
prototypes into two statements, such as:
struct Foo { float val; } foo();
struct Bar { int val; } bar() { ... }
void main() { ... }
Foo foo() { ... }
into:
struct Foo { float val; };
Foo foo();
struct Bar { int val; };
Bar bar() { ... }
void main() { ... }
Foo foo() { ... }
Fixed: angleproject:8302
Change-Id: Id8b6ba256d3c8375dd889facd70e4715261c1ca3
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5191644
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SeparateStructFromFunctionDeclarations: Separate struct declarations from
// function declaration return type. If necessary gives nameless structs
// internal names.
//
// For example:
// struct Foo { int a; } foo();
// becomes:
// struct Foo { int a; };
// Foo foo();
//
#ifndef COMPILER_TRANSLATOR_TREEOPS_SEPARATESTRUCTFROMFUNCTIONDECLARATIONS_H_
#define COMPILER_TRANSLATOR_TREEOPS_SEPARATESTRUCTFROMFUNCTIONDECLARATIONS_H_
#include "common/angleutils.h"
namespace sh
{
class TCompiler;
class TIntermBlock;
class TSymbolTable;
[[nodiscard]] bool SeparateStructFromFunctionDeclarations(TCompiler *compiler,
TIntermBlock *root,
TSymbolTable *symbolTable);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEOPS_SEPARATESTRUCTFROMFUNCTIONDECLARATIONS_H_