Skip to content

Commit e2bf7bb

Browse files
aykevlniaow
authored andcommitted
device: add new cross-arch Asm and AsmFull functions
This is necessary to avoid a circular dependency between the device/avr and runtime/interrupts package in the next commit. It may be worth replacing existing calls like device/arm.Asm to device.Asm, to have a single place where these are defined.
1 parent 4d1d0c2 commit e2bf7bb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

compiler/compiler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,9 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
13271327
return b.createMemoryCopyCall(fn, instr.Args)
13281328
case name == "runtime.memzero":
13291329
return b.createMemoryZeroCall(instr.Args)
1330-
case name == "device/arm.Asm" || name == "device/avr.Asm" || name == "device/riscv.Asm":
1330+
case name == "device.Asm" || name == "device/arm.Asm" || name == "device/avr.Asm" || name == "device/riscv.Asm":
13311331
return b.createInlineAsm(instr.Args)
1332-
case name == "device/arm.AsmFull" || name == "device/avr.AsmFull" || name == "device/riscv.AsmFull":
1332+
case name == "device.AsmFull" || name == "device/arm.AsmFull" || name == "device/avr.AsmFull" || name == "device/riscv.AsmFull":
13331333
return b.createInlineAsmFull(instr)
13341334
case strings.HasPrefix(name, "device/arm.SVCall"):
13351335
return b.emitSVCall(instr.Args)

src/device/asm.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package device
2+
3+
// Run the given assembly code. The code will be marked as having side effects,
4+
// as it doesn't produce output and thus would normally be eliminated by the
5+
// optimizer.
6+
func Asm(asm string)
7+
8+
// Run the given inline assembly. The code will be marked as having side
9+
// effects, as it would otherwise be optimized away. The inline assembly string
10+
// recognizes template values in the form {name}, like so:
11+
//
12+
// arm.AsmFull(
13+
// "str {value}, {result}",
14+
// map[string]interface{}{
15+
// "value": 1
16+
// "result": &dest,
17+
// })
18+
//
19+
// You can use {} in the asm string (which expands to a register) to set the
20+
// return value.
21+
func AsmFull(asm string, regs map[string]interface{}) uintptr

0 commit comments

Comments
 (0)