I have been writing a compiler. While profiling the compiler, one method takes 5 seconds to compile 2k lines of code, my profiler tells me that this is the bottleneck.
def toLLVMHelp(self, tree= None, isGlobal= True):
if tree == None:
tree = self.tree #tree is the Ast
for i in tree: #iterate through the top node
g = not type(i) is Tree.FuncStart and not type(i) is Tree.FuncBraceOpen and not type(i) is Tree.FuncBody and isGlobal
#for code that is not inside a function, it must be put somewhere else, g is a boolean for checking if outside a function
if g:
if i.isEnd(): #is the end node
self.main += i.compile(self)
else:
self.toLLVMHelp(i, g) #recurse for further nodes
self.main += i.compile(self) #compile turns the node into 'llvm-ir'
else:
if i.isEnd():
self.out += i.compile(self)
else:
self.toLLVMHelp(i, g)
self.out += i.compile(self)
I am guessing, that it is slow because of object dispatch. Any suggestion, would be greatly appreciated.