Object Intermediate Representation - A high-level IR for object-oriented languages, inspired by LLVM IR but designed specifically for OOP semantics.
ObjectIR is a typed intermediate representation that sits between high-level OOP languages (C#, Java, C++) and their target runtimes. It combines the precision of stack-based IRs like CIL with structured control flow for better readability and tooling support.
Primary Design: ObjectIR is primarily designed for execution on its own high-performance runtime, which provides a unified object model and advanced features for analysis, transformation, and cross-language interoperability.
Multi-Target Capability: In addition to its own runtime, ObjectIR can also be compiled to each language's native runtime (such as .NET CIL, JVM bytecode, C++ code, JavaScript, etc.), making it a powerful bridge for multi-platform and multi-language development.
- Unified ObjectIR Runtime: Execute modules directly on the ObjectIR runtime for maximum compatibility and advanced features
- Hybrid approach: CIL-style stack instructions + structured control flow (if/while/for)
- Type-safe: Strongly typed with full generic support
- Multi-target: Compile to .NET CIL, JVM bytecode, JavaScript, C++, Lua, etc.
- Standard library: Built-in generic types (List, Dict<K,V>, Set) that map to native implementations
- Builder API: Fluent C# API for constructing IR programmatically
- Extensible: Easy to add custom backends and optimization passes
dotnet add package ObjectIR.Coreusing ObjectIR.Core.Builder;
using ObjectIR.Core.IR;
var builder = new IRBuilder("CalculatorApp");
builder.Class("Calculator")
.Field("history", TypeReference.List(TypeReference.Int32))
.Field("lastResult", TypeReference.Int32)
.Method("Add", TypeReference.Int32)
.Parameter("a", TypeReference.Int32)
.Parameter("b", TypeReference.Int32)
.Local("result", TypeReference.Int32)
.Body()
.Ldarg("a")
.Ldarg("b")
.Add()
.Stloc("result")
.Ldloc("result")
.Ret()
.EndBody()
.EndMethod()
.EndClass();
var module = builder.Build();module CalculatorApp
class Calculator {
field history: List<int32>
field lastResult: int32
method Add(a: int32, b: int32) -> int32 {
local result: int32
ldarg a
ldarg b
add
stloc result
ldloc result
ret
}
}
ObjectIR provides a rich type system:
- Primitives:
void,bool,int8/16/32/64,uint8/16/32/64,float32/64,char,string - Reference Types: Classes, interfaces, delegates
- Value Types: Structs, enums
- Generics: Full generic support with constraints
- Arrays: Single and multi-dimensional
Built-in generic types that backends must implement:
System.List<T>
System.Dict<K, V>
System.Set<T>
System.Optional<T>
System.StringObjectIR uses a hybrid instruction set:
Stack-based operations (CIL-style):
- Load/Store:
ldarg,ldloc,ldfld,stloc,stfld - Constants:
ldc.i4,ldc.r4,ldstr,ldnull - Arithmetic:
add,sub,mul,div,rem,neg - Comparison:
ceq,cgt,clt - Calls:
call,callvirt,newobj - Stack manipulation:
dup,pop
Structured control flow (high-level):
if (condition) { ... } else { ... }while (condition) { ... }for (init; condition; increment) { ... }try { ... } catch (Type ex) { ... } finally { ... }
Backends implement the IBackend interface:
public interface IBackend
{
void Compile(Module module, Stream output);
string[] GetSupportedTypes();
}Example backends:
- CSharpBackend: Generates .NET CIL via System.Reflection.Emit
- CppBackend: Generates C++ with standard library mappings
- JavaScriptBackend: Generates JavaScript with runtime support
- LuaBackend: Generates Lua with metatables for OOP
| ObjectIR | C# | Java | C++ | JavaScript |
|---|---|---|---|---|
List<T> |
List<T> |
ArrayList<T> |
std::vector<T> |
Array |
Dict<K,V> |
Dictionary<K,V> |
HashMap<K,V> |
std::unordered_map<K,V> |
Map |
string |
string |
String |
std::string |
string |
Currently supported compilers:
- Construct Language (
src/ObjectIR.Core/Compilers/ConstructCompiler.cs) – High-level procedural language with ObjectIR semantics - Fortran 77 (OIFortran) (
src/OIFortran/Compiler/) – Classical scientific programming language- Phase 1 Status: Programs, subroutines, scalar arithmetic, basic control flow (IF/ELSE, DO loops), PRINT I/O
- Roadmap: See FORTRAN_F77_SPEC.md and FORTRAN_IMPLEMENTATION_PLAN.md
Build compilers for new languages that target multiple platforms:
YourLanguage → ObjectIR → C# / C++ / JavaScript / etc.
- Static analysis tools
- Optimization passes
- Code transformations
- Security analysis
Write once in ObjectIR, compile to any supported platform.
Bridge between different OOP languages with a common IR.
ObjectIR/
├── src/
│ └── ObjectIR.Core/
│ ├── IR/ # Core IR types
│ │ ├── Module.cs
│ │ ├── TypeDefinition.cs
│ │ ├── Instruction.cs
│ │ └── ...
│ └── Builder/ # Fluent builder API
│ └── IRBuilder.cs
├── examples/ # Example programs
├── docs/ # Documentation
└── tests/ # Unit tests
See GRAMMAR.md for the complete formal specification.
- Core IR implementation ✓ (Done)
- Builder API ✓ (Done)
- Text format parser
- Binary format (for performance) ✓ (FOB format implemented - see docs)
- C# backend (CIL emission)
- JavaScript backend
- C++ backend
- Standard library definitions
- Optimization passes
- Debugger support (DWARF, PDB)
- LLVM backend (for native compilation)
Contributions welcome! Areas of interest:
- Backend implementations
- Optimization passes
- Standard library expansions
- Language frontends
AGPL-V3 License - See LICENSE file for details
ObjectIR draws inspiration from:
- LLVM IR: Modular architecture, SSA form concepts
- .NET CIL: Stack-based operations, rich type system
- JVM Bytecode: Cross-platform vision
- WebAssembly: Structured control flow
- MLIR: Extensible dialect system
Key documentation files:
- Getting Started - Introduction and basic usage
- Grammar - Complete formal grammar specification
- VM Instructions (Text Format) - Text-based instruction reference for C++ VM
- Instruction Serialization (JSON) - JSON instruction format
- Architecture - System architecture overview
- Module Serialization - Module dump and export formats
- FOB Binary Format - Binary object format specification
Status: Early Development - API subject to change