@@ -245,47 +245,61 @@ function mangleNameFromDecleration(
245245}
246246
247247
248- export function buildCalleFromCallExpression (
249- expr : ts . CallExpression ,
248+ export function buildCalleFromSignature (
249+ signature : ts . Signature ,
250250 ctx : Context ,
251251 builder : llvm . IRBuilder
252- ) {
253- const calleSignature = ctx . typeChecker . getResolvedSignature ( expr ) ;
254- if ( calleSignature ) {
255- if ( ctx . signature . has ( calleSignature ) ) {
256- return ctx . signature . get ( calleSignature ) ;
257- }
252+ ) : llvm . Function | null {
253+ if ( ctx . signature . has ( signature ) ) {
254+ return ctx . signature . get ( signature ) ;
255+ }
258256
259- const declaration = < ts . SignatureDeclaration > calleSignature . declaration ;
260- if ( declaration . name ) {
261- const sourceFile = declaration . getSourceFile ( ) ;
257+ const declaration = < ts . SignatureDeclaration > signature . declaration ;
258+ if ( declaration . name ) {
259+ const sourceFile = declaration . getSourceFile ( ) ;
262260
263- if ( sourceFile . fileName === RUNTIME_DEFINITION_FILE ) {
264- const llvmFunction = declareFunctionFromDefinition (
265- < ts . FunctionDeclaration > declaration ,
266- ctx ,
267- builder ,
268- mangleNameFromDecleration ( declaration , ctx , CPPMangler )
269- ) ;
261+ if ( sourceFile . fileName === RUNTIME_DEFINITION_FILE ) {
262+ const llvmFunction = declareFunctionFromDefinition (
263+ < ts . FunctionDeclaration > declaration ,
264+ ctx ,
265+ builder ,
266+ mangleNameFromDecleration ( declaration , ctx , CPPMangler )
267+ ) ;
270268
271- ctx . signature . set ( calleSignature , llvmFunction ) ;
269+ ctx . signature . set ( signature , llvmFunction ) ;
272270
273- return llvmFunction ;
274- }
271+ return llvmFunction ;
272+ }
275273
276- if ( sourceFile . fileName === LANGUAGE_DEFINITION_FILE ) {
277- const llvmFunction = declareFunctionFromDefinition (
278- < ts . FunctionDeclaration > declaration ,
279- ctx ,
280- builder ,
281- mangleNameFromDecleration ( declaration , ctx , CMangler )
282- ) ;
274+ if ( sourceFile . fileName === LANGUAGE_DEFINITION_FILE ) {
275+ const llvmFunction = declareFunctionFromDefinition (
276+ < ts . FunctionDeclaration > declaration ,
277+ ctx ,
278+ builder ,
279+ mangleNameFromDecleration ( declaration , ctx , CMangler )
280+ ) ;
283281
284282
285- ctx . signature . set ( calleSignature , llvmFunction ) ;
283+ ctx . signature . set ( signature , llvmFunction ) ;
286284
287- return llvmFunction ;
288- }
285+ return llvmFunction ;
286+ }
287+ }
288+
289+ return null ;
290+ }
291+
292+
293+ export function buildCalleFromCallExpression (
294+ expr : ts . CallExpression ,
295+ ctx : Context ,
296+ builder : llvm . IRBuilder
297+ ) {
298+ const signature = ctx . typeChecker . getResolvedSignature ( expr ) ;
299+ if ( signature ) {
300+ const callSignature = buildCalleFromSignature ( signature , ctx , builder ) ;
301+ if ( callSignature ) {
302+ return callSignature ;
289303 }
290304 }
291305
@@ -389,26 +403,26 @@ export function passVariableDeclaration(block: ts.VariableDeclaration, ctx: Cont
389403 ctx
390404 ) ;
391405
392- let allocate : llvm . AllocaInst ;
406+ let value : llvm . Value ;
393407
394408 const defaultValue = buildFromExpression ( block . initializer , ctx , builder , nativeTypeForDefaultValue ) ;
395409 if ( defaultValue instanceof ObjectReference || defaultValue instanceof ArrayReference ) {
396- allocate = defaultValue . getValue ( ) ;
410+ value = defaultValue . getValue ( ) ;
397411 } else {
398- allocate = builder . createAlloca (
412+ value = builder . createAlloca (
399413 defaultValue . getValue ( ) . type ,
400414 undefined ,
401415 < string > block . name . escapedText
402416 ) ;
403417
404418 builder . createStore (
405419 defaultValue . getValue ( ) ,
406- allocate ,
420+ value ,
407421 false
408422 ) ;
409423 }
410424
411- ctx . scope . variables . set ( < string > block . name . escapedText , new Primitive ( allocate ) ) ;
425+ ctx . scope . variables . set ( < string > block . name . escapedText , new Primitive ( value ) ) ;
412426
413427 return ;
414428 }
0 commit comments