Skip to content

Commit 4a65f1c

Browse files
committed
✨ feat: enhance ELF emitter with net_write support
Added logic to the ELF emitter to handle the `net_write` function, including the appropriate offsets and bytecode appending for its arguments. This enhancement improves the code emission capabilities for network-related operations in the compiler.
1 parent 05c88db commit 4a65f1c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

compiler/emitter/elf/elf.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,36 @@ func (e *Emitter) generateTextSegment() []byte {
344344
})
345345
code = append32(code, 0)
346346

347+
destOffset := sc.getOffset(inst.Dest)
348+
code = append(code, 0x48, 0x89, 0x85)
349+
code = append32(code, int32(destOffset))
350+
} else if fnName == "net_write" {
351+
arg1Offset := sc.getOffset(inst.Src2)
352+
code = append(code, 0x48, 0x8b, 0xbd)
353+
code = append32(code, int32(arg1Offset))
354+
355+
arg2Offset := sc.getOffset(ir.Operand{Type: "variable", Value: "__net_write_arg2"})
356+
code = append(code, 0x48, 0x8b, 0xb5)
357+
code = append32(code, int32(arg2Offset))
358+
359+
code = append(code, 0xe8)
360+
refs = append(refs, labelRef{
361+
placeholderOffset: len(code),
362+
targetLabel: "net_write",
363+
isCall: true,
364+
})
365+
code = append32(code, 0)
366+
347367
destOffset := sc.getOffset(inst.Dest)
348368
code = append(code, 0x48, 0x89, 0x85)
349369
code = append32(code, int32(destOffset))
350370
} else {
371+
// Load argument into RAX if present
372+
if inst.Src2.Type != "" {
373+
argOffset := sc.getOffset(inst.Src2)
374+
code = append(code, 0x48, 0x8b, 0x85)
375+
code = append32(code, int32(argOffset))
376+
}
351377
// call fn
352378
code = append(code, 0xe8)
353379
refs = append(refs, labelRef{

0 commit comments

Comments
 (0)