File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export class BinaryExpressionCodeGenerator implements NodeGenerateInterface<ts.B
3131 case ts . SyntaxKind . LessThanLessThanEqualsToken :
3232 case ts . SyntaxKind . GreaterThanGreaterThanEqualsToken :
3333 case ts . SyntaxKind . CaretEqualsToken :
34+ case ts . SyntaxKind . AsteriskAsteriskEqualsToken :
3435 case ts . SyntaxKind . AsteriskEqualsToken :
3536 case ts . SyntaxKind . PlusEqualsToken :
3637 case ts . SyntaxKind . MinusEqualsToken : {
@@ -101,6 +102,22 @@ export class BinaryExpressionCodeGenerator implements NodeGenerateInterface<ts.B
101102 )
102103 ) ;
103104 }
105+ // a ** b
106+ case ts . SyntaxKind . AsteriskAsteriskEqualsToken :
107+ case ts . SyntaxKind . AsteriskAsteriskToken : {
108+ const left = buildFromExpression ( node . left , ctx , builder ) ;
109+ const right = buildFromExpression ( node . right , ctx , builder ) ;
110+
111+ return new Primitive (
112+ builder . createCall (
113+ ctx . getIntrinsic ( 'llvm.pow.f64' ) ,
114+ [
115+ loadIfNeeded ( left , builder ) ,
116+ loadIfNeeded ( right , builder )
117+ ]
118+ )
119+ ) ;
120+ }
104121 // a ^ b
105122 case ts . SyntaxKind . CaretEqualsToken :
106123 case ts . SyntaxKind . CaretToken : {
Original file line number Diff line number Diff line change @@ -70,4 +70,32 @@ export class Context {
7070 'array<float64>'
7171 ) ) ;
7272 }
73+
74+ getIntrinsic ( functionName : string ) : llvm . Function {
75+ const moduleFn = this . llvmModule . getFunction ( functionName ) ;
76+ if ( moduleFn ) {
77+ return moduleFn ;
78+ }
79+
80+ switch ( functionName ) {
81+ case 'llvm.pow.f64' :
82+ const intrinsicType = llvm . FunctionType . get (
83+ llvm . Type . getDoubleTy ( this . llvmContext ) ,
84+ [
85+ llvm . Type . getDoubleTy ( this . llvmContext ) ,
86+ llvm . Type . getDoubleTy ( this . llvmContext ) ,
87+ ] ,
88+ false
89+ ) ;
90+
91+ return llvm . Function . create (
92+ intrinsicType ,
93+ llvm . LinkageTypes . ExternalLinkage ,
94+ functionName ,
95+ this . llvmModule
96+ ) ;
97+ default :
98+ throw new Error ( `Unknown intrinsic: "${ functionName } "` ) ;
99+ }
100+ }
73101}
You can’t perform that action at this time.
0 commit comments