// validImmediate checks that addr represents an immediate constant. func (p *Parser) validImmediate(pseudo string, addr *obj.Addr) bool { if addr.Type != obj.TYPE_CONST || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 { p.errorf("%s: expected immediate constant; found %s", pseudo, obj.Dconv(&emptyProg, addr)) return false } return true }
func testOperandParser(t *testing.T, parser *Parser, tests []operandTest) { for _, test := range tests { parser.start(lex.Tokenize(test.input)) addr := obj.Addr{} parser.operand(&addr) result := obj.Dconv(&emptyProg, &addr) if result != test.output { t.Errorf("fail at %s: got %s; expected %s\n", test.input, result, test.output) } } }
// getRegister checks that addr represents a register and returns its value. func (p *Parser) getRegister(prog *obj.Prog, op int, addr *obj.Addr) int16 { if addr.Type != obj.TYPE_REG || addr.Offset != 0 || addr.Name != 0 || addr.Index != 0 { p.errorf("%s: expected register; found %s", obj.Aconv(op), obj.Dconv(prog, addr)) } return addr.Reg }
// getImmediate checks that addr represents an immediate constant and returns its value. func (p *Parser) getImmediate(prog *obj.Prog, op int, addr *obj.Addr) int64 { if addr.Type != obj.TYPE_CONST || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 { p.errorf("%s: expected immediate constant; found %s", obj.Aconv(op), obj.Dconv(prog, addr)) } return addr.Offset }
// getConstantPseudo checks that addr represents a plain constant and returns its value. func (p *Parser) getConstantPseudo(pseudo string, addr *obj.Addr) int64 { if addr.Type != obj.TYPE_MEM || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 { p.errorf("%s: expected integer constant; found %s", pseudo, obj.Dconv(&emptyProg, addr)) } return addr.Offset }
// getConstant checks that addr represents a plain constant and returns its value. func (p *Parser) getConstant(prog *obj.Prog, op obj.As, addr *obj.Addr) int64 { if addr.Type != obj.TYPE_MEM || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 { p.errorf("%s: expected integer constant; found %s", obj.Aconv(op), obj.Dconv(prog, addr)) } return addr.Offset }