1- // SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
1+ // SPDX-FileCopyrightText : © 2025-2026 TU Wien <vadl@tuwien.ac.at>
22// SPDX-License-Identifier: GPL-3.0-or-later
33//
44// This program is free software: you can redistribute it and/or modify
2121import java .util .Optional ;
2222import vadl .utils .Pair ;
2323import vadl .utils .SourceLocation ;
24+ import vadl .utils .WithLocation ;
2425
2526/**
2627 * VADL ABI representation.
@@ -190,19 +191,47 @@ public ClangType(ClangType.TypeName typeName, ClangType.TypeSize size, SourceLoc
190191 }
191192
192193 /**
193- * Constructor .
194+ * ABI-specific register role .
194195 *
195- * @param registerFile is the "parent" of the register.
196- * @param addr represents the index in a register file.
197- * E.g., RISC-V's X11 would have {@code addr = 11}.
198- * @param alignment for the spilling of the register.
196+ * @param registerRef semantic register reference
197+ * @param alignment for the spilling of the register
199198 */
200- public record RegisterRef (RegisterResource registerFile ,
201- int addr ,
202- Alignment alignment ,
203- SourceLocation location ) {
199+ public record AbiRegister (RegisterRef registerRef ,
200+ Alignment alignment ) implements WithLocation {
201+
202+ /**
203+ * Constructs an ABI register role from the historical single-index representation.
204+ */
205+ public AbiRegister (RegisterResource registerFile ,
206+ int addr ,
207+ Alignment alignment ,
208+ SourceLocation location ) {
209+ this (new RegisterRef (registerFile ,
210+ List .of (Constant .Value .of (addr , registerFile .indexTypes ().getFirst ())),
211+ location ), alignment );
212+ }
213+
214+ public RegisterResource registerFile () {
215+ return registerRef .resource ();
216+ }
217+
218+ public int addr () {
219+ return registerRef .singleIndex ();
220+ }
221+
222+ @ Override
223+ public SourceLocation location () {
224+ return registerRef .location ();
225+ }
226+
227+ /**
228+ * Render the compiler register name.
229+ *
230+ * <p>This is kept temporarily for the existing LCB emitters. Rendering should move to the
231+ * respective backend later.</p>
232+ */
204233 public String render () {
205- return registerFile .generateRegisterFileName (addr );
234+ return registerFile () .generateRegisterFileName (addr () );
206235 }
207236 }
208237
@@ -213,18 +242,18 @@ public record RegisterAlias(String value) {
213242 }
214243
215244
216- private final RegisterRef returnAddress ;
217- private final RegisterRef stackPointer ;
218- private final Optional <RegisterRef > globalPointer ;
219- private final RegisterRef framePointer ;
220- private final Optional <RegisterRef > threadPointer ;
245+ private final AbiRegister returnAddress ;
246+ private final AbiRegister stackPointer ;
247+ private final Optional <AbiRegister > globalPointer ;
248+ private final AbiRegister framePointer ;
249+ private final Optional <AbiRegister > threadPointer ;
221250
222251
223252 private final Map <Pair <RegisterResource , Integer >, List <RegisterAlias >> aliases ;
224- private final List <RegisterRef > callerSaved ;
225- private final List <RegisterRef > calleeSaved ;
226- private final List <RegisterRef > argumentRegisters ;
227- private final List <List <RegisterRef >> returnRegisters ;
253+ private final List <AbiRegister > callerSaved ;
254+ private final List <AbiRegister > calleeSaved ;
255+ private final List <AbiRegister > argumentRegisters ;
256+ private final List <List <AbiRegister >> returnRegisters ;
228257 private final PrintableInstruction returnSequence ;
229258 private final PrintableInstruction callSequence ;
230259 private final Optional <PrintableInstruction > localAddressLoad ;
@@ -248,16 +277,16 @@ public record RegisterAlias(String value) {
248277 * Constructor.
249278 */
250279 public Abi (Identifier identifier ,
251- RegisterRef returnAddress ,
252- RegisterRef stackPointer ,
253- RegisterRef framePointer ,
254- Optional <RegisterRef > globalPointer ,
255- Optional <RegisterRef > threadPointer ,
280+ AbiRegister returnAddress ,
281+ AbiRegister stackPointer ,
282+ AbiRegister framePointer ,
283+ Optional <AbiRegister > globalPointer ,
284+ Optional <AbiRegister > threadPointer ,
256285 Map <Pair <RegisterResource , Integer >, List <RegisterAlias >> aliases ,
257- List <RegisterRef > callerSaved ,
258- List <RegisterRef > calleeSaved ,
259- List <RegisterRef > argumentRegisters ,
260- List <List <RegisterRef >> returnRegisters ,
286+ List <AbiRegister > callerSaved ,
287+ List <AbiRegister > calleeSaved ,
288+ List <AbiRegister > argumentRegisters ,
289+ List <List <AbiRegister >> returnRegisters ,
261290 PrintableInstruction returnSequence ,
262291 PrintableInstruction callSequence ,
263292 Optional <PrintableInstruction > localAddressLoad ,
@@ -300,43 +329,43 @@ public void accept(DefinitionVisitor visitor) {
300329 }
301330
302331
303- public RegisterRef returnAddress () {
332+ public AbiRegister returnAddress () {
304333 return returnAddress ;
305334 }
306335
307- public RegisterRef stackPointer () {
336+ public AbiRegister stackPointer () {
308337 return stackPointer ;
309338 }
310339
311- public RegisterRef framePointer () {
340+ public AbiRegister framePointer () {
312341 return framePointer ;
313342 }
314343
315- public Optional <RegisterRef > globalPointer () {
344+ public Optional <AbiRegister > globalPointer () {
316345 return globalPointer ;
317346 }
318347
319- public Optional <RegisterRef > threadPointer () {
348+ public Optional <AbiRegister > threadPointer () {
320349 return threadPointer ;
321350 }
322351
323352 public Map <Pair <RegisterResource , Integer >, List <RegisterAlias >> aliases () {
324353 return aliases ;
325354 }
326355
327- public List <RegisterRef > callerSaved () {
356+ public List <AbiRegister > callerSaved () {
328357 return callerSaved ;
329358 }
330359
331- public List <RegisterRef > calleeSaved () {
360+ public List <AbiRegister > calleeSaved () {
332361 return calleeSaved ;
333362 }
334363
335- public List <RegisterRef > argumentRegisters () {
364+ public List <AbiRegister > argumentRegisters () {
336365 return argumentRegisters ;
337366 }
338367
339- public List <List <RegisterRef >> returnRegisters () {
368+ public List <List <AbiRegister >> returnRegisters () {
340369 return returnRegisters ;
341370 }
342371
0 commit comments