Skip to content

Commit 192a147

Browse files
committed
interp: support GEP on fixed (MMIO) addresses
GetElementPtr would not work on values that weren't pointers. Because fixed addresses (often used in memory-mapped I/O) are integers rather than pointers in interp, it would return an error. This resulted in the teensy40 target not compiling correctly since the interp package rewrite. This commit should fix that.
1 parent 9f06798 commit 192a147

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

interp/interp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func Run(mod llvm.Module, debug bool) error {
102102
if callErr != nil {
103103
if isRecoverableError(callErr.Err) {
104104
if r.debug {
105-
fmt.Fprintln(os.Stderr, "not interpretring", r.pkgName, "because of error:", callErr.Err)
105+
fmt.Fprintln(os.Stderr, "not interpreting", r.pkgName, "because of error:", callErr.Error())
106106
}
107107
mem.revert()
108108
continue

interp/interpreter.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,22 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
550550
}
551551
ptr, err := operands[0].asPointer(r)
552552
if err != nil {
553-
return nil, mem, r.errorAt(inst, err)
553+
if err != errExpectedPointer {
554+
return nil, mem, r.errorAt(inst, err)
555+
}
556+
// GEP on fixed pointer value (for example, memory-mapped I/O).
557+
ptrValue := operands[0].Uint() + offset
558+
switch operands[0].len(r) {
559+
case 8:
560+
locals[inst.localIndex] = literalValue{uint64(ptrValue)}
561+
case 4:
562+
locals[inst.localIndex] = literalValue{uint32(ptrValue)}
563+
case 2:
564+
locals[inst.localIndex] = literalValue{uint16(ptrValue)}
565+
default:
566+
panic("pointer operand is not of a known pointer size")
567+
}
568+
continue
554569
}
555570
ptr = ptr.addOffset(uint32(offset))
556571
locals[inst.localIndex] = ptr

0 commit comments

Comments
 (0)