Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8e20927
Adds tests for ensuring the output from the optimizing compiler. Add …
DBooots Mar 2, 2026
844d8df
Initial implementation of Three-Address Code interim representation. …
DBooots Mar 2, 2026
cd2448f
Clean up IR building code. Ensure IRInstructions remember the source …
DBooots Mar 6, 2026
3f609ff
Align IRInstruction property names and accessibility. Add interfaces …
DBooots Mar 6, 2026
1344914
Add concept of Extended Basic Blocks to help with future analysis and…
DBooots Mar 7, 2026
28410f0
Add abstract IRVariableBase class so that IRTemp can share some commo…
DBooots Mar 7, 2026
171b2bc
Add methods to, outside of executing an opcode, invoke the same math …
DBooots Mar 7, 2026
a53f7b3
Add convenience constructor for compilation exceptions arising from I…
DBooots Mar 7, 2026
131a4a9
Add constant folding pass. This reduces any constant expressions to t…
DBooots Mar 7, 2026
cd3104f
Add constant folding for built-in scalar function calls. This require…
DBooots Mar 7, 2026
2f11d21
Add infrastructure for automatic inclusion of optimization passes usi…
DBooots Mar 7, 2026
159e068
Move the InterimCPU ownership to IROptimizer to share resources acros…
DBooots Mar 7, 2026
2a71ecc
Add suffix replacement pass. This replaces all ship: suffixes that ca…
DBooots Mar 7, 2026
eb11e29
Store variable and constant source line and column so that (theoretic…
DBooots Mar 8, 2026
25b2897
Offload optimization steps from Compiler. Add a new IRCodePart repres…
DBooots Mar 8, 2026
c4da4df
Add nonsequential label capability to BasicBlocks to account for weir…
DBooots Mar 8, 2026
8f0ee70
Implement arg tests.
DBooots Mar 8, 2026
3a5cf78
Fix stack underflow when storing parameters.
DBooots Mar 8, 2026
6651a5f
Rewrite IRCodePart and the flow from Compiler to Optimizer to enable …
DBooots Mar 8, 2026
048d5bb
Give BasicBlocks unique IDs across the entire compilation, rather tha…
DBooots Mar 8, 2026
60c4458
Add concept of dominance to basic blocks. This will be key for determ…
DBooots Mar 8, 2026
cb8e5c6
Introduce IRParameter as a special type of IRValue, for instances whe…
DBooots Mar 8, 2026
294900f
Add Dead Code Elimination pass. This pass eliminates any basic blocks…
DBooots Mar 9, 2026
f727550
Adjust file structure and namespaces to be cleaner. Adjust numbering …
DBooots Mar 9, 2026
4d59836
Outline planned sorting of optimization passes.
DBooots Mar 9, 2026
91f179a
Clean up code for DCE and downgrade it to IHolisticOptimizationPass.
DBooots Mar 9, 2026
b0b85b9
Add methods for storing variable at local, global, or ambiguous scope…
DBooots Mar 10, 2026
80e6cc3
Add X/X=1 simplification to the constant folding pass. This will say …
DBooots Mar 10, 2026
0afa7aa
Add set access to IRInstruction interfaces, as well as indexing for I…
DBooots Mar 11, 2026
cf88539
Make ConstantFolding.AttemptReduction publicly accessible to allow la…
DBooots Mar 11, 2026
a435ddb
Provide a method for overwriting the source location of an instructio…
DBooots Mar 11, 2026
336ac48
Add a static utility class to make further passes that search the ins…
DBooots Mar 11, 2026
a879ba8
Implement equality checking for IR values and instructions. Instructi…
DBooots Mar 12, 2026
c86d308
Fix binary instructions losing appropriate commutative status when th…
DBooots Mar 12, 2026
852ece8
Add an argument marker to the stack before running a unit test progra…
DBooots Mar 12, 2026
73dee51
Force clobber builtins as necessary.
DBooots Mar 12, 2026
60624a6
Add a peephole optimization pass. This pass makes various small optim…
DBooots Mar 12, 2026
b6bb80c
Add property to enumerate which blocks are dominated by a BasicBlock.
DBooots Mar 12, 2026
ef43c4c
Implement scope awareness for BasicBlocks. Class IRScope should not b…
DBooots Mar 12, 2026
9dbea38
Add pass to remove unnecessary scope pushes and pops. This also remov…
DBooots Mar 12, 2026
dfaa8ad
Implement scope awareness into IRVariableBase so that variables are c…
DBooots Mar 12, 2026
bd24143
Finish peephole optimization pass by implementing lex indexing shortc…
DBooots Mar 12, 2026
281d3ae
Clean up and restructure IRCodePart and its child classes.
DBooots Mar 12, 2026
5040e46
Fix opcodebranch where the jump is relative instead of a label. Fix e…
DBooots Mar 13, 2026
567a7ae
Fix IRCodePart behaviour for triggers. It turns out they aren't just …
DBooots Mar 13, 2026
04ca8ce
Harmonize IRVariableBase and subclass equality, hashing, and string o…
DBooots Mar 13, 2026
58f6e52
Make IRAssignment more strict by knowing the exact variable (with sco…
DBooots Mar 13, 2026
898bd3a
Improve debug string readability.
DBooots Mar 13, 2026
5b42033
Fix collection changed while enumerating exception.
DBooots Mar 13, 2026
023de41
Fix infinite loop when dumping the tree where there is a loop contained.
DBooots Mar 13, 2026
c59ce69
Fix equality not working between constants.
DBooots Mar 14, 2026
b59a7b0
Add constant propagation pass. This pass replaces local variables wit…
DBooots Mar 14, 2026
7cfbd79
Patch scopes losing ancestry when an unused scope is collapsed.
DBooots Mar 14, 2026
b094ce3
Add return type indicator to FunctionAttribute and tag all kOS functi…
DBooots Mar 17, 2026
8faf614
Fix Structure not counting as a valid return type.
DBooots Mar 17, 2026
9402dce
Add methods to check if functions are invariant and to get their retu…
DBooots Mar 17, 2026
b11f5d2
Add methods to determine the resulting type of calculator operations.
DBooots Mar 17, 2026
e14da0b
Remove null checks in favour of readonly, statically-constructed fields.
DBooots Mar 17, 2026
50b2dda
Add suffix and index type inferencing through a utility class.
DBooots Mar 19, 2026
9eeb2ca
Finish implementing type inferencing through IRInstructions and IRVal…
DBooots Mar 21, 2026
ee29200
Properly implement static single assignment. This breaks the previous…
DBooots Mar 21, 2026
3cc27a8
Documentation pass.
DBooots Apr 6, 2026
2827131
Reimplement IOperandInstructionBase and make it actually useful. Adds…
DBooots Apr 17, 2026
fa0345b
Make OpcodeStore code shared. Fix StoreLocal not creating a local var…
DBooots Apr 17, 2026
b8e350d
Implement SCCP for constant propagation, replacing the former constan…
DBooots Apr 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add methods to check if functions are invariant and to get their retu…
…rn type.
  • Loading branch information
DBooots committed Mar 17, 2026
commit 9402dce674e86256bc2d8bc394696faf0f78b2ce
26 changes: 24 additions & 2 deletions src/kOS.Safe/Function/FunctionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace kOS.Safe.Function
public class FunctionManager : IFunctionManager
{
private readonly SafeSharedObjects shared;
private Dictionary<string, SafeFunctionBase> functions;
private readonly Dictionary<string, SafeFunctionBase> functions = new Dictionary<string, SafeFunctionBase>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, Type> functionTypes = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> invariantFunctions = new HashSet<string>();
private static readonly Dictionary<FunctionAttribute, Type> rawAttributes = new Dictionary<FunctionAttribute, Type>();

public FunctionManager(SafeSharedObjects shared)
Expand All @@ -21,7 +23,10 @@ public FunctionManager(SafeSharedObjects shared)

public void Load()
{
functions = new Dictionary<string, SafeFunctionBase>(StringComparer.OrdinalIgnoreCase);
functions.Clear();
functionTypes.Clear();
invariantFunctions.Clear();

foreach (FunctionAttribute attr in rawAttributes.Keys)
{
var type = rawAttributes[attr];
Expand All @@ -32,6 +37,9 @@ public void Load()
if (functionName != string.Empty)
{
functions.Add(functionName, (SafeFunctionBase)functionObject);
functionTypes.Add(functionName, attr.ReturnType);
if (attr.IsInvariant)
invariantFunctions.Add(functionName);
}
}
}
Expand Down Expand Up @@ -70,5 +78,19 @@ public bool Exists(string functionName)
{
return functions.ContainsKey(functionName);
}

public bool IsFunctionInvariant(string functionName)
{
return invariantFunctions.Contains(functionName);
}

public Type FunctionReturnType(string functionName)
{
if (!functions.ContainsKey(functionName))
{
throw new Exception("Queried return type of a non-existent function " + functionName);
}
return functionTypes[functionName];
}
}
}
2 changes: 2 additions & 0 deletions src/kOS.Safe/Function/IFunctionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public interface IFunctionManager
void Load();
void CallFunction(string functionName);
bool Exists(string functionName);
bool IsFunctionInvariant(string functionName);
System.Type FunctionReturnType(string functionName);
}
}