Skip to content

Commit feb8a0b

Browse files
committed
Add LLVMTypes class
1 parent ec698eb commit feb8a0b

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

src/dev/engine/internal/llvm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ target_sources(scratchcpp
99
llvmcoroutine.h
1010
llvmvariableptr.h
1111
llvmprocedure.h
12+
llvmtypes.cpp
13+
llvmtypes.h
1214
llvmexecutablecode.cpp
1315
llvmexecutablecode.h
1416
llvmexecutioncontext.cpp

src/dev/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvmexecutablecode.h"
1414
#include "llvmifstatement.h"
1515
#include "llvmloop.h"
16+
#include "llvmtypes.h"
1617

1718
using namespace libscratchcpp;
1819

@@ -976,14 +977,7 @@ void LLVMCodeBuilder::yield()
976977

977978
void LLVMCodeBuilder::initTypes()
978979
{
979-
// Create the ValueData struct
980-
llvm::Type *unionType = m_builder.getInt64Ty(); // 64 bits is the largest size
981-
982-
llvm::Type *valueType = llvm::Type::getInt32Ty(m_ctx); // Assuming ValueType is a 32-bit enum
983-
llvm::Type *sizeType = llvm::Type::getInt64Ty(m_ctx); // size_t
984-
985-
m_valueDataType = llvm::StructType::create(m_ctx, "ValueData");
986-
m_valueDataType->setBody({ unionType, valueType, sizeType });
980+
m_valueDataType = LLVMTypes::createValueDataType(&m_builder);
987981
}
988982

989983
void LLVMCodeBuilder::createVariableMap()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include <llvm/IR/IRBuilder.h>
4+
5+
#include "llvmtypes.h"
6+
7+
using namespace libscratchcpp;
8+
9+
llvm::StructType *LLVMTypes::createValueDataType(llvm::IRBuilder<> *builder)
10+
{
11+
llvm::LLVMContext &ctx = builder->getContext();
12+
13+
// Create the ValueData struct
14+
llvm::Type *unionType = builder->getInt64Ty(); // 64 bits is the largest size
15+
16+
llvm::Type *valueType = llvm::Type::getInt32Ty(ctx); // Assuming ValueType is a 32-bit enum
17+
llvm::Type *sizeType = llvm::Type::getInt64Ty(ctx); // size_t
18+
19+
llvm::StructType *ret = llvm::StructType::create(ctx, "ValueData");
20+
ret->setBody({ unionType, valueType, sizeType });
21+
22+
return ret;
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <llvm/IR/IRBuilder.h>
6+
7+
namespace llvm
8+
{
9+
10+
class StructValue;
11+
12+
}
13+
14+
namespace libscratchcpp
15+
{
16+
17+
class LLVMTypes
18+
{
19+
public:
20+
static llvm::StructType *createValueDataType(llvm::IRBuilder<> *builder);
21+
};
22+
23+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)