Skip to content

Commit 5fac17d

Browse files
committed
Feature(compiler): Support boolean type
1 parent 3ed4b68 commit 5fac17d

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/backend/llvm/cpp.mangler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class CPPMangler {
1111
return 'd';
1212
case ts.SyntaxKind.StringKeyword:
1313
return 'PKc';
14+
case ts.SyntaxKind.BooleanKeyword:
15+
return 'b';
1416
default:
1517
throw new Error(
1618
`Unsupported mangling parameter type: ${parameter.type.kind}`

src/backend/llvm/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ export function buildFromStringValue(node: ts.StringLiteral, ctx: Context, build
7777
);
7878
}
7979

80+
export function buildFromTrueKeyword(node: ts.BooleanLiteral, ctx: Context, builder: llvm.IRBuilder): llvm.Value {
81+
return llvm.ConstantInt.get(
82+
ctx.llvmContext,
83+
1,
84+
8,
85+
false
86+
);
87+
}
88+
89+
export function buildFromFalseKeyword(node: ts.BooleanLiteral, ctx: Context, builder: llvm.IRBuilder): llvm.Value {
90+
return llvm.ConstantInt.get(
91+
ctx.llvmContext,
92+
1,
93+
8,
94+
false
95+
);
96+
}
97+
8098
function buildFromNumericLiteral(
8199
value: ts.NumericLiteral,
82100
ctx: Context,
@@ -258,6 +276,10 @@ function buildFromExpression(block: ts.Expression, ctx: Context, builder: llvm.I
258276
return buildFromNumericLiteral(<any>block, ctx, builder, nativeType);
259277
case ts.SyntaxKind.StringLiteral:
260278
return buildFromStringValue(<any>block, ctx, builder);
279+
case ts.SyntaxKind.TrueKeyword:
280+
return buildFromTrueKeyword(<any>block, ctx, builder);
281+
case ts.SyntaxKind.FalseKeyword:
282+
return buildFromFalseKeyword(<any>block, ctx, builder);
261283
case ts.SyntaxKind.BinaryExpression:
262284
return buildFromBinaryExpression(<any>block, ctx, builder);
263285
case ts.SyntaxKind.CallExpression:

src/backend/llvm/native-type-resolver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export class NativeTypeResolver {
2222
);
2323
}
2424

25+
if ((<any>type).intrinsicName === 'boolean') {
26+
return new NativeType(
27+
llvm.Type.getInt8Ty(
28+
ctx.llvmContext
29+
)
30+
);
31+
}
32+
2533
if ((<any>type).intrinsicName === 'void') {
2634
return new NativeType(
2735
llvm.Type.getVoidTy(

0 commit comments

Comments
 (0)