@@ -400,26 +400,51 @@ fn (mut c Amd64) inc_var(var Var, config VarConfig) {
400
400
c.inc_var (var_object as GlobalVar , config)
401
401
}
402
402
Register {
403
+ c.g.n_error ('Register incrementation is not supported yet' )
403
404
// TODO
404
405
// g.inc()
405
406
}
406
407
}
407
408
}
408
409
LocalVar {
409
- // TODO: size
410
- c.g. write8 ( 0x81 ) // 83 for 1 byte
410
+ typ := c.g. unwrap (var.typ)
411
+ mut size_str := 'UNKNOWN'
411
412
offset := var.offset - config.offset
412
413
is_far_var := offset > 0x80 || offset < - 0x7f
414
+ match typ {
415
+ ast.i64_ type_idx, ast.u64_ type_idx, ast.isize_type_idx, ast.usize_type_idx,
416
+ ast.int_literal_type_idx {
417
+ c.g.write16 (0xFF48 )
418
+ size_str = 'QWORD'
419
+ }
420
+ ast.i32_ type_idx, ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
421
+ c.g.write8 (0xFF )
422
+ size_str = 'DWORD'
423
+ }
424
+ ast.i16_ type_idx, ast.u16_ type_idx {
425
+ c.g.write8 (0xFF )
426
+ size_str = 'WORD'
427
+ }
428
+ ast.i8_ type_idx, ast.u8_ type_idx, ast.char_type_idx {
429
+ c.g.write8 (0xFE )
430
+ size_str = 'BYTE'
431
+ }
432
+ else {
433
+ ts := c.g.table.sym (typ.idx_type ())
434
+ c.g.n_error ('unsupported type for inc_var ${ts.info} ' )
435
+ }
436
+ }
437
+
413
438
c.g.write8 (if is_far_var { i32 (0x85 ) } else { i32 (0x45 ) })
414
439
if is_far_var {
415
440
c.g.write32 (i32 ((0xffffffff - i64 (offset) + 1 ) % 0x100000000 ))
416
441
} else {
417
442
c.g.write8 ((0xff - offset + 1 ) % 0x100 )
418
443
}
419
- c.g.write32 (1 )
420
- c.g.println ('inc_var `${var.name} `' )
444
+ c.g.println ('inc_var ${size_str} `${var.name} `' )
421
445
}
422
446
GlobalVar {
447
+ c.g.n_error ('Global variables incrementation is not supported yet' )
423
448
// TODO
424
449
}
425
450
}
@@ -643,7 +668,7 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
643
668
c.g.write16 (0x8948 + if is_extended_register { i32 (4 ) } else { i32 (0 ) })
644
669
size_str = 'QWORD'
645
670
}
646
- ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
671
+ ast.i 32_ type_idx, ast. int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
647
672
if is_extended_register {
648
673
c.g.write8 (0x44 )
649
674
}
@@ -694,7 +719,7 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
694
719
} else {
695
720
c.g.write8 ((0xff - offset + 1 ) % 0x100 )
696
721
}
697
- c.g.println ('mov ${size_str} PTR [rbp-${int(offset).hex2()} ],${reg} ' )
722
+ c.g.println ('mov ${size_str} PTR [rbp-${int(offset).hex2()} ],${reg} ; ` ${var.name} ` ' )
698
723
}
699
724
GlobalVar {
700
725
// TODO
@@ -746,7 +771,7 @@ fn (mut c Amd64) mov_int_to_var(var Var, integer i32, config VarConfig) {
746
771
c.g.write16 (u16 (integer))
747
772
c.g.println ('mov WORD PTR[rbp-${int(offset).hex2()} ], ${integer} ' )
748
773
}
749
- ast.int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
774
+ ast.i 32_ type_idx, ast. int_type_idx, ast.u32_ type_idx, ast.rune_type_idx {
750
775
c.g.write8 (0xc7 )
751
776
c.g.write8 (if is_far_var { i32 (0x85 ) } else { i32 (0x45 ) })
752
777
if is_far_var {
@@ -832,7 +857,6 @@ fn (mut c Amd64) mov_var_to_reg(reg Register, var Var, config VarConfig) {
832
857
typ := if config.typ == 0 { var.typ } else { config.typ }
833
858
size := c.g.get_type_size (typ)
834
859
is_signed := ! typ.is_any_kind_of_pointer () && typ.is_signed ()
835
-
836
860
instruction , size_str := match true {
837
861
size == 4 && is_signed {
838
862
// movsxd rax, DWORD PTR [rbp-0x8]
0 commit comments