mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
Add support for inline assembly
This depends on support in LLVM, which hasn't been merged yet. See: https://reviews.llvm.org/D46437
This commit is contained in:
@@ -32,6 +32,9 @@ package arm
|
|||||||
type __reg uint32
|
type __reg uint32
|
||||||
type RegValue = __reg
|
type RegValue = __reg
|
||||||
|
|
||||||
|
type __asm string
|
||||||
|
func Asm(s __asm)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SCS_BASE = 0xE000E000
|
SCS_BASE = 0xE000E000
|
||||||
NVIC_BASE = SCS_BASE + 0x0100
|
NVIC_BASE = SCS_BASE + 0x0100
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ func monotime() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func abort() {
|
func abort() {
|
||||||
// TODO: wfi
|
|
||||||
for {
|
for {
|
||||||
|
arm.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1038,6 +1038,15 @@ func (c *Compiler) parseCall(frame *Frame, instr *ssa.CallCommon, parentHandle l
|
|||||||
case *ssa.Builtin:
|
case *ssa.Builtin:
|
||||||
return c.parseBuiltin(frame, instr.Args, call.Name())
|
return c.parseBuiltin(frame, instr.Args, call.Name())
|
||||||
case *ssa.Function:
|
case *ssa.Function:
|
||||||
|
if call.Name() == "Asm" && len(instr.Args) == 1 {
|
||||||
|
// Magic function: insert inline assembly instead of calling it.
|
||||||
|
if named, ok := instr.Args[0].Type().(*types.Named); ok && named.Obj().Name() == "__asm" {
|
||||||
|
fnType := llvm.FunctionType(llvm.VoidType(), []llvm.Type{}, false)
|
||||||
|
asm := constant.StringVal(instr.Args[0].(*ssa.Const).Value)
|
||||||
|
target := llvm.InlineAsm(fnType, asm, "", true, false, 0)
|
||||||
|
return c.builder.CreateCall(target, nil, ""), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
targetBlocks := false
|
targetBlocks := false
|
||||||
name := getFunctionName(call, targetBlocks)
|
name := getFunctionName(call, targetBlocks)
|
||||||
llvmFn := c.mod.NamedFunction(name)
|
llvmFn := c.mod.NamedFunction(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user