Skip to content

Improving generation of debug information for executable #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fa9b63b
adding abs path for source code to load file in debug mode
ASDAlexander77 Oct 3, 2024
15cee31
added RegularExpressionLiteral
ASDAlexander77 Oct 3, 2024
f99d742
restore commented code
ASDAlexander77 Oct 5, 2024
78ac716
update
ASDAlexander77 Oct 6, 2024
f1a045f
fixes to forward declaration of statements
ASDAlexander77 Oct 6, 2024
932bd18
fixed issue with not showing all errors
ASDAlexander77 Oct 7, 2024
4081d8a
progress of fixes
ASDAlexander77 Oct 7, 2024
ae95c54
fixes to position parser
ASDAlexander77 Oct 7, 2024
369da28
updated parser to track texp position better
ASDAlexander77 Oct 8, 2024
7f32fcc
added DebugVariableOp
ASDAlexander77 Oct 8, 2024
5b93742
fixed isse with DI type for debug var op
ASDAlexander77 Oct 8, 2024
875ab65
progress of refactoring debug info
ASDAlexander77 Oct 9, 2024
234d3b0
progress of refactoring debug info
ASDAlexander77 Oct 9, 2024
513f7b9
progress of fixes
ASDAlexander77 Oct 9, 2024
b49fe3a
refactoring debug info scopes
ASDAlexander77 Oct 9, 2024
e9a29cf
progress of changes DebugInfo
ASDAlexander77 Oct 9, 2024
7061b1e
progress
ASDAlexander77 Oct 9, 2024
60bedfd
fixes to line number
ASDAlexander77 Oct 9, 2024
22ebe6e
refactoring define DEBUG_INFO
ASDAlexander77 Oct 9, 2024
167e6f0
refactoring alloca
ASDAlexander77 Oct 9, 2024
c9ec768
added code to reduce lexical blocks
ASDAlexander77 Oct 9, 2024
bc07c4e
fixed issue with wrong scope for functions
ASDAlexander77 Oct 10, 2024
ea3f5cb
more fixes
ASDAlexander77 Oct 10, 2024
71db88f
refactoring pos logic
ASDAlexander77 Oct 10, 2024
6045278
fixed issue with incorrect scope
ASDAlexander77 Oct 10, 2024
0cc0ec3
more fixes to DI scope
ASDAlexander77 Oct 10, 2024
2fdc64e
progress of fixing DI
ASDAlexander77 Oct 11, 2024
b37665b
more fixes to DebugInfo
ASDAlexander77 Oct 11, 2024
a816b8b
updated test bat
ASDAlexander77 Oct 11, 2024
3ac5b19
progress
ASDAlexander77 Oct 11, 2024
e2ffa82
update
ASDAlexander77 Oct 11, 2024
377371a
fixes to hashcode of location
ASDAlexander77 Oct 11, 2024
36666aa
more fixes
ASDAlexander77 Oct 11, 2024
8351d3f
more fixes
ASDAlexander77 Oct 11, 2024
b7900c9
more fixes
ASDAlexander77 Oct 11, 2024
3f0c556
fixes
ASDAlexander77 Oct 11, 2024
e51ca5f
added scope for overwritten locations
ASDAlexander77 Oct 11, 2024
a80e82f
fixes to generate recusive types
ASDAlexander77 Oct 12, 2024
2c40a0a
restored ts type conversion
ASDAlexander77 Oct 12, 2024
7822a64
added default case
ASDAlexander77 Oct 12, 2024
3b10a6f
fixed issue with using generic function in let
ASDAlexander77 Oct 12, 2024
468a1eb
fixed issue with debug info for async call
ASDAlexander77 Oct 12, 2024
458140d
more fixes
ASDAlexander77 Oct 12, 2024
9f0c5fe
added some code to fix for/async
ASDAlexander77 Oct 12, 2024
08d21da
more fixes
ASDAlexander77 Oct 12, 2024
ae60918
cleaning up locations
ASDAlexander77 Oct 12, 2024
dbdfc85
refactoring locations
ASDAlexander77 Oct 12, 2024
07c9d26
fixes to compile
ASDAlexander77 Oct 13, 2024
d46af70
update launch
ASDAlexander77 Oct 13, 2024
e3922ea
updated test app
ASDAlexander77 Oct 13, 2024
ed9e549
removing not needed code
ASDAlexander77 Oct 13, 2024
98aae02
restored code
ASDAlexander77 Oct 13, 2024
47fac4c
added tuple type
ASDAlexander77 Oct 13, 2024
2d8fa42
progress of implementing debug info
ASDAlexander77 Oct 14, 2024
dba7470
progress
ASDAlexander77 Oct 14, 2024
6d9c425
fixes to varOp
ASDAlexander77 Oct 14, 2024
1e57dc2
fixed recursive types
ASDAlexander77 Oct 14, 2024
3253411
more fixes
ASDAlexander77 Oct 14, 2024
e08e6ff
updating readme
ASDAlexander77 Oct 14, 2024
5a433d3
added some flag to rm command
ASDAlexander77 Oct 14, 2024
24e1276
fixes
ASDAlexander77 Oct 14, 2024
852a01b
fixed issue with incorrect filelocation pickup
ASDAlexander77 Oct 14, 2024
887013e
update compile issue on linux
ASDAlexander77 Oct 14, 2024
deffc2c
reducing parallelism
ASDAlexander77 Oct 14, 2024
5e11811
added def for debug compile
ASDAlexander77 Oct 14, 2024
6dadcbe
fix
ASDAlexander77 Oct 14, 2024
d86c315
more fixes
ASDAlexander77 Oct 14, 2024
7e96cbd
added fix
ASDAlexander77 Oct 14, 2024
0ea40a6
one more fix
ASDAlexander77 Oct 15, 2024
af10f42
fixes to use doublicate anonymous names
ASDAlexander77 Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake-test-release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ jobs:
shell: sh
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -j18 -C ${{ env.BUILD_TYPE }} -T test --output-on-failure -T test --output-on-failure
run: ctest -j1 -C ${{ env.BUILD_TYPE }} -T test --output-on-failure -T test --output-on-failure

2 changes: 1 addition & 1 deletion .github/workflows/cmake-test-release-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ jobs:
working-directory: ${{github.workspace}}/__build/tsc/msbuild/x64/release
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -j18 -C ${{ env.BUILD_TYPE }} -T test --output-on-failure -T test --output-on-failure
run: ctest -j1 -C ${{ env.BUILD_TYPE }} -T test --output-on-failure -T test --output-on-failure
shell: pwsh
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
[![Test Build (Linux)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-linux.yml/badge.svg)](https://github.com/ASDAlexander77/TypeScriptCompiler/actions/workflows/cmake-test-release-linux.yml)

# What's new
- improved ```generating debug information``` more info here: [Wiki:How-To](https://github.com/ASDAlexander77/TypeScriptCompiler/wiki/How-To#compile-and-debug-with-visual-studio-code)
```cmd
tsc --di --opt_level=0 --emit=exe example.ts
```

- cast from Union Types
```TypeScript
let a: string | number = 5;
Expand Down
2 changes: 1 addition & 1 deletion tag.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git tag -a v0.0-pre-alpha54 -m "pre alpha v0.0-54"
git tag -a v0.0-pre-alpha54 -m "pre alpha v0.0-55"
git push origin --tags
4 changes: 2 additions & 2 deletions tag_del.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git push --delete origin v0.0-pre-alpha54
git tag -d v0.0-pre-alpha54
git push --delete origin v0.0-pre-alpha55
git tag -d v0.0-pre-alpha55
2 changes: 2 additions & 0 deletions tsc/include/TypeScript/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@
// seems we can't use appending logic at all
//#define SHARED_LIB_DECLARATION_INFO_IS_APPENDABLE true

//#define DBG_INFO_ADD_VALUE_OP true

#endif // CONFIG_H_
6 changes: 6 additions & 0 deletions tsc/include/TypeScript/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@
#define DEFAULT_LIB_DIR "defaultlib"
#define DEFAULT_LIB_NAME "TypeScriptDefaultLib"

#define DEBUG_SCOPE "current"
#define CU_DEBUG_SCOPE "compileUnit"
#define FILE_DEBUG_SCOPE "file"
#define SUBPROGRAM_DEBUG_SCOPE "function"
#define BLOCK_DEBUG_SCOPE "block"

#endif // DEFINES_H_
10 changes: 4 additions & 6 deletions tsc/include/TypeScript/LowerToLLVM/AssertLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ class AssertLogic
{
auto unreachable = clh.FindUnreachableBlockOrCreate();

LLVMLocationHelper lh;

auto [fileName, line] = lh.getLineAndFile(loc);
auto [fileName, lineAndColumn] = LLVMLocationHelper::getLineAndColumnAndFileName(loc);
auto [line, column] = lineAndColumn;

// Insert the `_assert` declaration if necessary.
auto i8PtrTy = th.getI8PtrType();
Expand Down Expand Up @@ -111,9 +110,8 @@ class AssertLogic
{
auto unreachable = clh.FindUnreachableBlockOrCreate();

LLVMLocationHelper lh;

auto [fileName, line] = lh.getLineAndFile(loc);
auto [fileName, lineAndColumn] = LLVMLocationHelper::getLineAndColumnAndFileName(loc);
auto [line, column] = lineAndColumn;

// Insert the `_assert` declaration if necessary.
auto i8PtrTy = th.getI8PtrType();
Expand Down
14 changes: 10 additions & 4 deletions tsc/include/TypeScript/LowerToLLVM/CastLogicHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "mlir/Dialect/Index/IR/IndexOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"

#define DEBUG_TYPE "llvm"

using namespace mlir;
namespace mlir_ts = mlir::typescript;

Expand Down Expand Up @@ -723,9 +725,11 @@ class CastLogicHelper

LLVM_DEBUG(llvm::dbgs() << "invalid cast operator type 1: '" << inLLVMType << "', type 2: '" << resLLVMType << "'\n";);

emitError(loc, "invalid cast from ") << inLLVMType << " to " << resLLVMType;
//return rewriter.create<LLVM::UndefOp>(loc, resLLVMType);
return mlir::Value();
// TODO: we return undef bacause if "conditional compiling" we can have non compilable code with "cast" to bypass it we need to retun precompiled value
emitWarning(loc, "invalid cast from ") << inLLVMType << " to " << resLLVMType;
return rewriter.create<LLVM::UndefOp>(loc, resLLVMType);
//emitError(loc, "invalid cast from ") << inLLVMType << " to " << resLLVMType;
//return mlir::Value();
}

mlir::Value castTupleToTuple(mlir::Value in, ::llvm::ArrayRef<::mlir::typescript::FieldInfo> fields, mlir_ts::TupleType tupleTypeRes)
Expand Down Expand Up @@ -940,7 +944,7 @@ class CastLogicHelper
{
auto bytesSize = rewriter.create<mlir_ts::SizeOfOp>(loc, th.getIndexType(), arrayValueSize);
// TODO: create MemRef which will store information about memory. stack of heap, to use in array push to realloc
// auto copyAllocated = rewriter.create<LLVM::AllocaOp>(loc, arrayPtrType, bytesSize);
// auto copyAllocated = ch.Alloca(arrayPtrType, bytesSize);
auto copyAllocated = ch.MemoryAllocBitcast(arrayPtrType, bytesSize);

auto ptrToArraySrc = rewriter.create<LLVM::BitcastOp>(loc, ptrToArray, in);
Expand Down Expand Up @@ -1104,4 +1108,6 @@ mlir::Value castLogic(mlir::Value size, mlir::Type sizeType, mlir::Operation *op

} // namespace typescript

#undef DEBUG_TYPE

#endif // MLIR_TYPESCRIPT_LOWERTOLLVMLOGIC_CASTLOGICHELPER_H_
6 changes: 3 additions & 3 deletions tsc/include/TypeScript/LowerToLLVM/ConvertLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ConvertLogic
ArrayRef<mlir::Type>{rewriter.getI32Type(), th.getI8PtrType(), rewriter.getI32Type()}, true));

auto bufferSizeValue = clh.createI32ConstantOf(50);
// auto newStringValue = rewriter.create<LLVM::AllocaOp>(loc, i8PtrTy, bufferSizeValue, true);
// auto newStringValue = ch.Alloca(i8PtrTy, bufferSizeValue, true);
auto newStringValue = ch.MemoryAllocBitcast(i8PtrTy, bufferSizeValue, MemoryAllocSet::Atomic);
auto base = clh.createI32ConstantOf(10);

Expand All @@ -60,7 +60,7 @@ class ConvertLogic
ArrayRef<mlir::Type>{rewriter.getI64Type(), th.getI8PtrType(), rewriter.getI32Type()}, true));

auto bufferSizeValue = clh.createI32ConstantOf(50);
// auto newStringValue = rewriter.create<LLVM::AllocaOp>(loc, i8PtrTy, bufferSizeValue, true);
// auto newStringValue = ch.Alloca(i8PtrTy, bufferSizeValue, true);
auto newStringValue = ch.MemoryAllocBitcast(i8PtrTy, bufferSizeValue, MemoryAllocSet::Atomic);
auto base = clh.createI32ConstantOf(10);

Expand All @@ -76,7 +76,7 @@ class ConvertLogic
ArrayRef<mlir::Type>{rewriter.getF64Type(), rewriter.getI32Type(), th.getI8PtrType()}, true));

auto bufferSizeValue = clh.createI32ConstantOf(50);
// auto newStringValue = rewriter.create<LLVM::AllocaOp>(loc, i8PtrTy, bufferSizeValue, true);
// auto newStringValue = ch.Alloca(i8PtrTy, bufferSizeValue, true);
auto newStringValue = ch.MemoryAllocBitcast(i8PtrTy, bufferSizeValue, MemoryAllocSet::Atomic);
auto doubleValue = rewriter.create<LLVM::FPExtOp>(loc, rewriter.getF64Type(), in);
auto precision = clh.createI32ConstantOf(16);
Expand Down
4 changes: 4 additions & 0 deletions tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"

#define DEBUG_TYPE "llvm"

using namespace mlir;
namespace mlir_ts = mlir::typescript;

Expand Down Expand Up @@ -711,4 +713,6 @@ class LLVMCodeHelper : public LLVMCodeHelperBase

} // namespace typescript

#undef DEBUG_TYPE

#endif // MLIR_TYPESCRIPT_LOWERTOLLVMLOGIC_LLVMCODEHELPER_H_
27 changes: 27 additions & 0 deletions tsc/include/TypeScript/LowerToLLVM/LLVMCodeHelperBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,33 @@ class LLVMCodeHelperBase
return _MemoryFree<int>(ptrValue);
}

mlir::Value Alloca(mlir::Type llvmReferenceType, int count, bool inalloca = false)
{
auto location = op->getLoc();

mlir::OpBuilder::InsertionGuard insertGuard(rewriter);

// put all allocs at 'func' top
auto parentFuncOp = op->getParentOfType<LLVM::LLVMFuncOp>();
if (parentFuncOp)
{
// if inside function (not in global op)
rewriter.setInsertionPoint(&parentFuncOp.getBody().front().front());
}

CodeLogicHelper clh(op, rewriter);
auto allocated = rewriter.create<LLVM::AllocaOp>(location, llvmReferenceType, clh.createI32ConstantOf(count), inalloca);
return allocated;
}

mlir::Value Alloca(mlir::Type llvmReferenceType, mlir::Value count, bool inalloca = false)
{
auto location = op->getLoc();
CodeLogicHelper clh(op, rewriter);
auto allocated = rewriter.create<LLVM::AllocaOp>(location, llvmReferenceType, count, inalloca);
return allocated;
}

template <typename T> mlir::Value _MemoryAlloc(mlir::Value sizeOfAlloc, MemoryAllocSet memAllocMode)
{
TypeHelper th(rewriter);
Expand Down
Loading
Loading