Skip to content

Commit 84c9c8d

Browse files
Some fixes to logic and debug info generation (#156)
* some fixes to debug info * update vs template * added test for uint cmp bug * fixed issue with uint cmp * more fixes to process class with default generic params * progress of fixing element offset * fixes to debug info * fix * implementing any type ops * some update * added any compare op * added any type tests * more fixes * fixed reference issue * update build scripts
1 parent 2ea8318 commit 84c9c8d

21 files changed

Lines changed: 499 additions & 108 deletions

tag.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
git tag -a v0.0-pre-alpha67 -m "pre alpha v0.0-67"
1+
git tag -a v0.0-pre-alpha68 -m "pre alpha v0.0-68"
22
git push origin --tags

tag_del.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
git push --delete origin v0.0-pre-alpha67
2-
git tag -d v0.0-pre-alpha67
1+
git push --delete origin v0.0-pre-alpha68
2+
git tag -d v0.0-pre-alpha68

tsc/include/TypeScript/Defines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
#define UNION_TAG_INDEX 0
9090
#define UNION_VALUE_INDEX 1
9191

92+
#define ANY_SIZE 0
93+
#define ANY_TYPE 1
94+
#define ANY_DATA 2
95+
9296
#define DEFAULT_LIB_DIR "defaultlib"
9397
#define DEFAULT_LIB_NAME "TypeScriptDefaultLib"
9498

tsc/include/TypeScript/LowerToLLVM/AnyLogic.h

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ class AnyLogic
3333
protected:
3434
mlir::Type indexType;
3535
mlir::Type llvmIndexType;
36-
mlir::Type valuePtrType;
36+
mlir::Type ptrTy;
3737

3838
public:
3939
AnyLogic(Operation *op, PatternRewriter &rewriter, TypeConverterHelper &tch, Location loc, CompileOptions &compileOptions)
4040
: op(op), rewriter(rewriter), tch(tch), th(rewriter), ch(op, rewriter, tch.typeConverter, compileOptions), clh(op, rewriter), loc(loc)
4141
{
4242
indexType = th.getIndexType();
4343
llvmIndexType = tch.convertType(indexType);
44-
valuePtrType = th.getPtrType();
44+
ptrTy = th.getPtrType();
4545
}
4646

4747
LLVM::LLVMStructType getStorageAnyType(mlir::Type llvmStorageType)
4848
{
49-
return LLVM::LLVMStructType::getLiteral(rewriter.getContext(), {llvmIndexType, valuePtrType, llvmStorageType}, false);
49+
return LLVM::LLVMStructType::getLiteral(rewriter.getContext(), {llvmIndexType, ptrTy, llvmStorageType}, false);
5050
}
5151

5252
mlir::Value castToAny(mlir::Value in, mlir::Type inType, mlir::Type inLLVMType)
@@ -61,7 +61,6 @@ class AnyLogic
6161
mlir::Value castToAny(mlir::Value in, mlir::Value typeOfValue, mlir::Type inLLVMType)
6262
{
6363
// TODO: add type id to track data type
64-
auto ptrTy = th.getPtrType();
6564
auto llvmStorageType = inLLVMType;
6665
auto dataWithSizeType = getStorageAnyType(llvmStorageType);
6766

@@ -71,9 +70,9 @@ class AnyLogic
7170
auto sizeMLIR = rewriter.create<mlir_ts::SizeOfOp>(loc, indexType, llvmStorageType);
7271
auto size = rewriter.create<mlir_ts::DialectCastOp>(loc, llvmIndexType, sizeMLIR);
7372

74-
auto zero = clh.createI32ConstantOf(0);
75-
auto one = clh.createI32ConstantOf(1);
76-
auto two = clh.createI32ConstantOf(2);
73+
auto zero = clh.createI32ConstantOf(ANY_SIZE);
74+
auto one = clh.createI32ConstantOf(ANY_TYPE);
75+
auto two = clh.createI32ConstantOf(ANY_DATA);
7776

7877
auto ptrSize = rewriter.create<LLVM::GEPOp>(loc, ptrTy, dataWithSizeType, memValue, ValueRange{zero, zero});
7978
rewriter.create<LLVM::StoreOp>(loc, size, ptrSize);
@@ -92,15 +91,14 @@ class AnyLogic
9291
{
9392
// TODO: add type id to track data type
9493
// TODO: add data size check
95-
auto ptrTy = th.getPtrType();
9694
auto llvmStorageType = resLLVMType;
9795
auto dataWithSizeType = getStorageAnyType(llvmStorageType);
9896

9997
auto inDataWithSizeTypedValue = rewriter.create<LLVM::BitcastOp>(loc, ptrTy, in);
10098

101-
auto zero = clh.createI32ConstantOf(0);
102-
// auto one = clh.createI32ConstantOf(1);
103-
auto two = clh.createI32ConstantOf(2);
99+
auto zero = clh.createI32ConstantOf(ANY_SIZE);
100+
//auto one = clh.createI32ConstantOf(ANY_TYPE);
101+
auto two = clh.createI32ConstantOf(ANY_DATA);
104102

105103
// set actual value
106104
auto ptrValue =
@@ -113,21 +111,60 @@ class AnyLogic
113111
// TODO: add type id to track data type
114112
// TODO: add data size check
115113
// any random type
116-
auto ptrTy = th.getPtrType();
117114
auto llvmStorageType = th.getI8Type();
118115
auto dataWithSizeType = getStorageAnyType(llvmStorageType);
119116

120117
auto inDataWithSizeTypedValue = rewriter.create<LLVM::BitcastOp>(loc, ptrTy, in);
121118

122-
auto zero = clh.createI32ConstantOf(0);
123-
auto one = clh.createI32ConstantOf(1);
124-
// auto two = clh.createI32ConstantOf(2);
119+
auto zero = clh.createI32ConstantOf(ANY_SIZE);
120+
auto one = clh.createI32ConstantOf(ANY_TYPE);
121+
//auto two = clh.createI32ConstantOf(ANY_DATA);
125122

126123
// set actual value
127124
auto ptrValue = rewriter.create<LLVM::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
128125
ValueRange{zero, one});
129-
return rewriter.create<LLVM::LoadOp>(loc, valuePtrType, ptrValue);
126+
return rewriter.create<LLVM::LoadOp>(loc, ptrTy, ptrValue);
130127
}
128+
129+
mlir::Value getDataSizeOfAny(mlir::Value in)
130+
{
131+
// TODO: add type id to track data type
132+
// TODO: add data size check
133+
// any random type
134+
auto llvmStorageType = th.getI8Type();
135+
auto dataWithSizeType = getStorageAnyType(llvmStorageType);
136+
137+
auto inDataWithSizeTypedValue = rewriter.create<LLVM::BitcastOp>(loc, ptrTy, in);
138+
139+
auto zero = clh.createI32ConstantOf(ANY_SIZE);
140+
//auto one = clh.createI32ConstantOf(ANY_TYPE);
141+
//auto two = clh.createI32ConstantOf(ANY_DATA);
142+
143+
// set actual value
144+
auto ptrValue = rewriter.create<LLVM::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
145+
ValueRange{zero, zero});
146+
return rewriter.create<LLVM::LoadOp>(loc, llvmIndexType, ptrValue);
147+
}
148+
149+
mlir::Value getDataPtrOfAny(mlir::Value in)
150+
{
151+
// TODO: add type id to track data type
152+
// TODO: add data size check
153+
// any random type
154+
auto llvmStorageType = th.getI8Type();
155+
auto dataWithSizeType = getStorageAnyType(llvmStorageType);
156+
157+
auto inDataWithSizeTypedValue = rewriter.create<LLVM::BitcastOp>(loc, ptrTy, in);
158+
159+
auto zero = clh.createI32ConstantOf(ANY_SIZE);
160+
//auto one = clh.createI32ConstantOf(ANY_TYPE);
161+
auto two = clh.createI32ConstantOf(ANY_DATA);
162+
163+
// set actual value
164+
auto ptrValue = rewriter.create<LLVM::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
165+
ValueRange{zero, two});
166+
return ptrValue;
167+
}
131168
};
132169
} // namespace typescript
133170

0 commit comments

Comments
 (0)