SLIR.sleela
lib/cpu/SLIR.sleela · 113 line(s) · sleela
<< lib/cpu/SLIR.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLIR — a module of common intermediate representation: an
ordered sequence of SLIRInstruction nodes plus a temporary-allocation
counter and a label counter. Every language frontend (C, C++, Java, Sleela)
produces an SLIR; the shared backend SLLowering consumes it. This is the
single convergence point that makes the ISA genuinely multi-language.
Backed by SLRAM for the node stream (SLeeLa surface has no arrays); nodes are
stored by index and the lowering pass walks them in order.
Family: cpu. Composes SLIRInstruction; the IR container. >>
#sleela 2.5
material;
class SLIR {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10250;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-06";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
< "sleela" | "c" | "cpp" | "java" (provenance only) >
String language;
< encoded IR nodes, one per word-group (modeled) >
SLRAM nodeStore;
< number of IR instructions >
int count;
< SSA-ish temporary allocator >
int nextTemp;
< label id allocator >
int nextLabel;
< Node fields kept in parallel integer stores for walkability. >
SLRAM opStore; SLRAM dstStore; SLRAM aStore; SLRAM bStore; SLRAM immStore; SLRAM flagStore;
void configure(String lang, int capacity) {
language = lang; count = 0; nextTemp = 0; nextLabel = 0;
opStore = new SLRAM(); opStore.configure(capacity, 32); opStore.allocate();
dstStore = new SLRAM(); dstStore.configure(capacity, 32); dstStore.allocate();
aStore = new SLRAM(); aStore.configure(capacity, 32); aStore.allocate();
bStore = new SLRAM(); bStore.configure(capacity, 32); bStore.allocate();
immStore = new SLRAM(); immStore.configure(capacity, 32); immStore.allocate();
flagStore = new SLRAM(); flagStore.configure(capacity, 32); flagStore.allocate();
}
int allocTemp() { int t = nextTemp; nextTemp = nextTemp + 1; return t; }
int allocLabel() { int l = nextLabel; nextLabel = nextLabel + 1; return l; }
< Append an IR instruction; returns its index. >
int emit(int op, int dst, int a, int b, int imm) {
int i = count;
opStore.writeWord(i, op);
dstStore.writeWord(i, dst);
aStore.writeWord(i, a);
bStore.writeWord(i, b);
immStore.writeWord(i, imm);
flagStore.writeWord(i, 0);
count = count + 1;
return i;
}
void markImmediateA(int index) { flagStore.writeWord(index, 1); }
< Read a node back as an SLIRInstruction. >
SLIRInstruction at(int index) {
SLIRInstruction n = new SLIRInstruction();
n.configure(opStore.readWord(index), dstStore.readWord(index),
aStore.readWord(index), bStore.readWord(index), immStore.readWord(index));
if (flagStore.readWord(index) == 1) { n.markImmediateA(); }
return n;
}
int size() { return count; }
String lang() { return language; }
int tempCount() { return nextTemp; }
int labelCount() { return nextLabel; }
}