mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
inline assembly
This commit is contained in:
38
vlib/compiler/asm.v
Normal file
38
vlib/compiler/asm.v
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module compiler
|
||||
|
||||
fn (p mut Parser) inline_asm() {
|
||||
if !p.inside_unsafe {
|
||||
p.error('asm() needs to be run unside `unsafe {}`')
|
||||
}
|
||||
p.next()
|
||||
p.check(.lpar)
|
||||
s := p.check_string()
|
||||
p.genln('asm("$s"')
|
||||
for p.tok == .str {
|
||||
p.genln('"$p.lit"')
|
||||
p.next()
|
||||
}
|
||||
for p.tok == .colon {
|
||||
p.next()
|
||||
arg := p.check_string()
|
||||
p.gen(': "$arg"')
|
||||
if p.tok == .lpar {
|
||||
p.next()
|
||||
var_name := p.check_name()
|
||||
if !p.known_var(var_name) {
|
||||
p.error('unknown variable `$var_name`')
|
||||
}
|
||||
p.check(.rpar)
|
||||
p.genln('($var_name)')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
p.genln(');')
|
||||
p.check(.rpar)
|
||||
|
||||
}
|
Reference in New Issue
Block a user