instr: support nop
This commit is contained in:
parent
cc2671e208
commit
224415c008
@ -454,6 +454,10 @@ func (c *compiler) Compile(t Token) error {
|
|||||||
c.Must([]byte{0xc3}) // ret
|
c.Must([]byte{0xc3}) // ret
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
case NopInstrToken:
|
||||||
|
c.Must([]byte{0x90}) // nop
|
||||||
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("can't compile token of type %#t", t)
|
return fmt.Errorf("can't compile token of type %#t", t)
|
||||||
}
|
}
|
||||||
|
3
lexer.go
3
lexer.go
@ -80,6 +80,9 @@ func (l *lexer) Next() (Token, error) {
|
|||||||
case "ret":
|
case "ret":
|
||||||
return RetInstrToken{}, nil
|
return RetInstrToken{}, nil
|
||||||
|
|
||||||
|
case "nop":
|
||||||
|
return NopInstrToken{}, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// If the field ends with `:`, it's a (local) label
|
// If the field ends with `:`, it's a (local) label
|
||||||
if strings.HasSuffix(fields[0], `:`) {
|
if strings.HasSuffix(fields[0], `:`) {
|
||||||
|
2
token.go
2
token.go
@ -23,6 +23,8 @@ type SyscallInstrToken struct{}
|
|||||||
|
|
||||||
type RetInstrToken struct{}
|
type RetInstrToken struct{}
|
||||||
|
|
||||||
|
type NopInstrToken struct{}
|
||||||
|
|
||||||
type DataVariableInstrToken struct {
|
type DataVariableInstrToken struct {
|
||||||
VarName string
|
VarName string
|
||||||
Sizeclass string // sz, u8, u16, u32, u64
|
Sizeclass string // sz, u8, u16, u32, u64
|
||||||
|
Loading…
Reference in New Issue
Block a user