export enum LocType {
|
|
REGISTER = "register",
|
|
TEMPORARY = "temporary",
|
|
VARIABLE = "variable",
|
|
}
|
|
|
|
export class Loc {
|
|
type: LocType
|
|
name: string
|
|
|
|
constructor(type: LocType, name: string) {
|
|
this.type = type
|
|
this.name = name
|
|
}
|
|
|
|
toString(): string {
|
|
let sigil = ''
|
|
|
|
switch (this.type) {
|
|
case 'register':
|
|
sigil = '%'
|
|
break
|
|
|
|
case 'temporary':
|
|
sigil = '#'
|
|
break
|
|
}
|
|
|
|
return sigil + this.name
|
|
}
|
|
|
|
static vari(name: string): Loc {
|
|
return new Loc(LocType.VARIABLE, name)
|
|
}
|
|
|
|
static temp(name: string): Loc {
|
|
return new Loc(LocType.TEMPORARY, name)
|
|
}
|
|
|
|
static reg(name: string): Loc {
|
|
return new Loc(LocType.REGISTER, name)
|
|
}
|
|
}
|