Skip to content

Commit

Permalink
fmt, and fix vfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
l1mey112 committed Oct 28, 2023
1 parent 7695c06 commit eb1eb54
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
7 changes: 6 additions & 1 deletion vlib/v/fmt/asm.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ fn (mut f Fmt) asm_stmt(stmt ast.AsmStmt) {
} else if stmt.is_goto {
f.write('goto ')
}
f.writeln('${stmt.arch} {')
lit_arch := if stmt.arch == .wasm32 {
'wasm'
} else {
stmt.arch.str()
}
f.writeln('${lit_arch} {')
f.indent++

f.asm_templates(stmt.templates)
Expand Down
33 changes: 19 additions & 14 deletions vlib/v/gen/wasm/asm.v
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ pub fn (mut g Gen) asm_local_get_set_or_tee(node ast.AsmTemplate, vars AsmVars)
}

target_var := if alias.name == '__vbp' {
Var{ idx: g.bp() }
} else {
var := vars[alias.name] or {
g.v_error('unknown identifier', alias.pos)
Var{
idx: g.bp()
}
} else {
var := vars[alias.name] or { g.v_error('unknown identifier', alias.pos) }
var
}
// -- doesn't work, cgen error
Expand Down Expand Up @@ -104,13 +104,17 @@ pub fn (mut g Gen) asm_global_get_or_set(node ast.AsmTemplate, vars AsmVars) {
}

target_var := if alias.name == '__vsp' {
Var{ g_idx: g.sp() is_global: true }
Var{
g_idx: g.sp()
is_global: true
}
} else if alias.name == '__heap_base' {
Var{ g_idx: g.hp() is_global: true }
} else {
var := vars[alias.name] or {
g.v_error('unknown identifier', alias.pos)
Var{
g_idx: g.hp()
is_global: true
}
} else {
var := vars[alias.name] or { g.v_error('unknown identifier', alias.pos) }
var
}

Expand Down Expand Up @@ -207,7 +211,7 @@ pub fn (mut g Gen) asm_parse_align_offset(node ast.AsmTemplate) (int, int) {
if node.args.len != 2 {
g.v_error('incorrect number of arguments to `${node.name}`', node.pos)
}

arg0 := node.args[0]
arg1 := node.args[1]

Expand Down Expand Up @@ -848,11 +852,12 @@ pub fn (mut g Gen) asm_template(parent ast.AsmStmt, node ast.AsmTemplate, vars A
'memory.fill' {
g.func.memory_fill()
}

// TODO: impl later
/* 'ref.null' {
/*
'ref.null' {
g.func.ref_null()
} */
}
*/
else {
g.v_error('unknown opcode', node.pos)
}
Expand Down Expand Up @@ -881,4 +886,4 @@ pub fn (mut g Gen) asm_stmt(node ast.AsmStmt) {
for tmpl in node.templates {
g.asm_template(node, tmpl, vars)
}
}
}
6 changes: 4 additions & 2 deletions vlib/v/gen/wasm/gen.v
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub struct LoopBreakpoint {
pub fn (mut g Gen) v_error(s string, pos token.Pos) {
util.show_compiler_message('error:', pos: pos, file_path: g.file_path, message: s)
exit(1)
/* if g.pref.output_mode == .stdout {
/*
if g.pref.output_mode == .stdout {
util.show_compiler_message('error:', pos: pos, file_path: g.file_path, message: s)
exit(1)
} else {
Expand All @@ -76,7 +77,8 @@ pub fn (mut g Gen) v_error(s string, pos token.Pos) {
reporter: .gen
message: s
}
} */
}
*/
}

pub fn (mut g Gen) warning(s string, pos token.Pos) {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/wasm/mem.v
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub fn (mut g Gen) set(v Var) {
// never used by actual codegen
pub fn (mut g Gen) tee(v Var) {
assert !v.is_global

if !v.is_address {
g.func.local_tee(v.idx)
return
Expand Down
13 changes: 8 additions & 5 deletions vlib/v/gen/wasm/tests/asm.vv
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn literals() (int, i64, f32, f64) {
mut l2 := i64(0)
mut l3 := f32(0.0)
mut l4 := 0.0

asm wasm {
i32.const 999
i64.const 999
Expand All @@ -73,15 +73,18 @@ fn literals() (int, i64, f32, f64) {
local.set l3
local.set l2
local.set l1
; =r(l1) =r(l2) =r(l3) =r(l4)
; =r (l1)
=r (l2)
=r (l3)
=r (l4)
}

return l1, l2, l3, l4
}

fn reinterpret_asm() string {
mut reinterp := 0

// reinterpret int value into f32, convert back
asm wasm {
i32.const 0x44424000 // 777.0
Expand All @@ -97,7 +100,7 @@ fn reinterpret_asm() string {
asm wasm {
local.get lit
local.get reinterp
call "int.str"
call int.str
; =r (lit)
; r (reinterp)
}
Expand Down Expand Up @@ -144,4 +147,4 @@ fn main() {
seven_seven_seven := reinterpret_asm()
println(seven_seven_seven)
malloc_ptr()
}
}

0 comments on commit eb1eb54

Please sign in to comment.