Compile only used functions/builtins

Uses iteration as to properly detect functions called only from within
other functions (which appear unused from the global scope).
This commit is contained in:
arookas 2016-02-01 15:53:14 -05:00
parent dc559130bf
commit ba559b3fa3

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
namespace arookas { namespace arookas {
public class sunCompiler { public class sunCompiler {
@ -71,9 +72,15 @@ namespace arookas {
mBinary.WriteEND(); mBinary.WriteEND();
} }
void CompileFunctions() { void CompileFunctions() {
foreach (var callable in mContext.SymbolTable.Callables) { while (DoCompileFunctions() > 0) ;
}
int DoCompileFunctions() {
var count = 0;
foreach (var callable in mContext.SymbolTable.Callables.Where(i => i.HasRelocations && i.CompileCount == 0)) {
callable.Compile(this); callable.Compile(this);
++count;
} }
return count;
} }
void CompileRelocations() { void CompileRelocations() {
foreach (var symbol in mContext.SymbolTable) { foreach (var symbol in mContext.SymbolTable) {