Skip to content

Commit

Permalink
boots: report some example locations
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Aug 5, 2023
1 parent d3dd061 commit fe4b580
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
4 changes: 4 additions & 0 deletions dora-boots/assembler/arm64.dora
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl AssemblerArm64 {
self.buffer.createAndBindLabel()
}

pub fn position(): Int32 {
self.buffer.position().toInt32()
}

pub fn add(rd: Register, rn: Register, rm: Register) {
if rd == REG_SP || rn == REG_SP {
self.add_ext(rd, rn, rm, Extend::UXTX, 0i32);
Expand Down
4 changes: 4 additions & 0 deletions dora-boots/assembler/x64.dora
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ impl AssemblerX64 {
self.buffer.createAndBindLabel()
}

pub fn position(): Int32 {
self.buffer.position().toInt32()
}

pub fn addl_ri(dest: Register, imm: Immediate) {
self.emitAlu32Imm(dest, imm, 0b000i32, 0x05u8);
}
Expand Down
16 changes: 12 additions & 4 deletions dora-boots/codegen/arm64.dora
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use package::interface::{Architecture, CompilationInfo, config, TRAP_DIV0};
use package::codegen::{CodeGen, CodeDescriptor, CommentTable, LocationTable};
use package::codegen::{CodeGen, CodeDescriptor, CommentTable, Location, LocationTable};
use package::assembler::arm64::AssemblerArm64;
use package::assembler::arm64::{R0, R1, R2, R3, R4, R5, R6, R7, R10, R11};
use package::assembler::arm64::{REG_FP, REG_SP, REG_LR};
Expand All @@ -9,11 +9,18 @@ use package::graph::{Inst, Op, LocationData};
pub class CodeGenArm64 {
info: CompilationInfo,
asm: AssemblerArm64,
locations: LocationTable,
comments: CommentTable,
}

impl CodeGenArm64 {
pub static fn new(info: CompilationInfo): CodeGenArm64 {
CodeGenArm64(info, AssemblerArm64::new())
CodeGenArm64(
info,
AssemblerArm64::new(),
LocationTable::new(),
CommentTable::new(),
)
}

pub fn generate(): Array[UInt8] {
Expand All @@ -31,6 +38,7 @@ impl CodeGenArm64 {
self.asm.movz(CCALL_REG_PARAMS(0), trap, 0i32);
self.mov_imm(tmp, config.trap_trampoline.toInt64());
self.asm.bl_r(tmp);
self.locations.insert(self.asm.position(), Location(5i32, 10i32));
}

fn mov_imm(dest: Register, imm: Int64) {
Expand Down Expand Up @@ -147,8 +155,8 @@ impl CodeGen for CodeGenArm64 {

CodeDescriptor(
code,
CommentTable::new(),
LocationTable::new(),
self.comments,
self.locations,
)
}
}
16 changes: 12 additions & 4 deletions dora-boots/codegen/x64.dora
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ use package::assembler::x64::{AssemblerX64, Address, Condition, Immediate, Scale
use package::assembler::x64::{RAX, RDI, RDX, RCX, RSI, RBP, RSP};
use package::assembler::x64::{R8, R9, R10, R11};
use package::assembler::{Register, RegSet};
use package::codegen::{CodeGen, CodeDescriptor, CommentTable, LocationTable};
use package::codegen::{CodeGen, CodeDescriptor, CommentTable, Location, LocationTable};
use package::interface::{Architecture, CompilationInfo, config, TRAP_DIV0};
use package::graph::{Inst, Op, LocationData};

pub class CodeGenX64 {
info: CompilationInfo,
asm: AssemblerX64,
locations: LocationTable,
comments: CommentTable,
}

impl CodeGenX64 {
pub static fn new(info: CompilationInfo): CodeGenX64 {
CodeGenX64(info, AssemblerX64::new())
CodeGenX64(
info,
AssemblerX64::new(),
LocationTable::new(),
CommentTable::new(),
)
}

fn epilog() {
Expand All @@ -26,6 +33,7 @@ impl CodeGenX64 {
self.asm.movl_ri(CCALL_REG_PARAMS(0), Immediate(trap.toInt64()));
self.asm.movq_ri(tmp, Immediate(config.trap_trampoline.toInt64()));
self.asm.call_r(tmp);
self.locations.insert(self.asm.position(), Location(5i32, 1i32));
}
}

Expand Down Expand Up @@ -150,8 +158,8 @@ impl CodeGen for CodeGenX64 {

CodeDescriptor(
code,
CommentTable::new(),
LocationTable::new(),
self.comments,
self.locations,
)
}
}
10 changes: 10 additions & 0 deletions dora-boots/graph.dora
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ pub class Inst {
block: Option[Block],

_op: Option[Op],
bytecode_position: Option[Int32],

aux: Int64,

Expand All @@ -587,6 +588,7 @@ impl Inst {
None[Int32],
None[Block],
None[Op],
None[Int32],
0,
None[Inst],
None[Inst],
Expand All @@ -608,6 +610,14 @@ impl Inst {
self._op.getOrPanic()
}

pub fn bytecode_position(): Option[Int32] {
self.bytecode_position
}

pub fn set_bytecode_position(pos: Int32) {
self.bytecode_position = Some(pos);
}

pub fn getBlock(): Block {
self.block.getOrPanic()
}
Expand Down
1 change: 1 addition & 0 deletions dora-boots/graph_builder.dora
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ impl SsaGen {
}

let destInst = createBinaryInst(op, ty, lhsInst, rhsInst);
destInst.set_bytecode_position(self.offset);
self.current().appendInst(destInst);
self.writeVariable(dest, self.current(), destInst);
}
Expand Down

0 comments on commit fe4b580

Please sign in to comment.