Skip to content

Commit

Permalink
Refactor type handling in CodeGen (#29)
Browse files Browse the repository at this point in the history
* Refactor codegen types

* Namespace cleanup, add function test case that was previously not possible
  • Loading branch information
wpmed92 authored Sep 10, 2024
1 parent 5fa67f7 commit b8b2a5a
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 190 deletions.
8 changes: 3 additions & 5 deletions include/CodeGen/MLIRCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "llvm/ADT/ScopedHashTable.h"
#include <vector>
#include <map>
#include <utility>
#include <functional>
#include <unordered_map>

Expand Down Expand Up @@ -85,7 +84,7 @@ class MLIRCodeGen : public ASTVisitor {
bool inGlobalScope = true;
llvm::StringMap<spirv::FuncOp> functionMap;
llvm::StringMap<StructDeclaration*> structDeclarations;
std::vector<std::pair<shaderpulse::Type*, Value>> expressionStack;
std::vector<mlir::Value> expressionStack;
StructDeclaration* currentBaseComposite = nullptr;

llvm::ScopedHashTable<llvm::StringRef, SymbolTableEntry>
Expand All @@ -104,10 +103,9 @@ class MLIRCodeGen : public ASTVisitor {
void initBuiltinFuncMap();
bool callBuiltIn(CallExpression* exp);
mlir::Value load(mlir::Value);

std::pair<shaderpulse::Type*, Value> popExpressionStack();
mlir::Value popExpressionStack();
mlir::Value currentBasePointer;
mlir::Value convertOp(ConstructorExpression* constructorExp, std::pair<shaderpulse::Type*, mlir::Value> operand);
mlir::Value convertOp(ConstructorExpression* constructorExp, mlir::Value val);
};

}; // namespace codegen
Expand Down
14 changes: 11 additions & 3 deletions include/CodeGen/TypeConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ namespace shaderpulse {

namespace codegen {

mlir::Type convertShaderPulseType(mlir::MLIRContext *, Type *, llvm::StringMap<ast::StructDeclaration*> &);
std::optional<mlir::spirv::StorageClass> getSpirvStorageClass(TypeQualifier *);
std::optional<mlir::IntegerAttr> getLocationFromTypeQualifier(mlir::MLIRContext *ctx, TypeQualifier *);
mlir::Type convertShaderPulseType(mlir::MLIRContext *, shaderpulse::Type *, llvm::StringMap<ast::StructDeclaration*> &);
std::optional<mlir::spirv::StorageClass> getSpirvStorageClass(shaderpulse::TypeQualifier *);
std::optional<mlir::IntegerAttr> getLocationFromTypeQualifier(mlir::MLIRContext *ctx, shaderpulse::TypeQualifier *);
mlir::Type getElementType(mlir::Type type);
bool isBoolLike(mlir::Type type);
bool isIntLike(mlir::Type type);
bool isSIntLike(mlir::Type type);
bool isUIntLike(mlir::Type type);
bool isFloatLike(mlir::Type type);
bool isF32Like(mlir::Type type);
bool isF64Like(mlir::Type type);

}; // namespace codegen
}; // namespace shaderpulse
Loading

0 comments on commit b8b2a5a

Please sign in to comment.