Skip to content

Commit

Permalink
Improving generation of debug information for executable (#129)
Browse files Browse the repository at this point in the history
* adding abs path for source code to load file in debug mode

* added RegularExpressionLiteral

* restore commented code

* update

* fixes to forward declaration of statements

* fixed issue with not showing all errors

* progress of fixes

* fixes to position parser

* updated parser to track texp position better

* added DebugVariableOp

* fixed isse with DI type for debug var op

* progress of refactoring debug info

* progress of refactoring debug info

* progress of fixes

* refactoring debug info scopes

* progress of changes DebugInfo

* progress

* fixes to line number

* refactoring define DEBUG_INFO

* refactoring alloca

* added code to reduce lexical blocks

* fixed issue with wrong scope for functions

* more fixes

* refactoring pos logic

* fixed issue with incorrect scope

* more fixes to DI scope

* progress of fixing DI

* more fixes to DebugInfo

* updated test bat

* progress

* update

* fixes to hashcode of location

* more fixes

* more fixes

* more fixes

* fixes

* added scope for overwritten locations

* fixes to generate recusive types

* restored ts type conversion

* added default case

* fixed issue with using generic function in let

* fixed issue with debug info for async call

* more fixes

* added some code to fix for/async

* more fixes

* cleaning up locations

* refactoring locations

* fixes to compile

* update launch

* updated test app

* removing not needed code

* restored code

* added tuple type

* progress of implementing debug info

* progress

* fixes to varOp

* fixed recursive types

* more fixes

* updating readme

* added some flag to rm command

* fixes

* fixed issue with incorrect filelocation pickup

* update compile issue on linux

* reducing parallelism

* added def for debug compile

* fix

* more fixes

* added fix

* one more fix

* fixes to use doublicate anonymous names
  • Loading branch information
ASDAlexander77 authored Oct 15, 2024
1 parent 04a0440 commit 9781d47
Show file tree
Hide file tree
Showing 51 changed files with 1,499 additions and 725 deletions.
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

0 comments on commit 9781d47

Please sign in to comment.