예제 #1
0
파일: r1_r2_test.go 프로젝트: mm0205/gcasl
func TestOperandListR1R2Parse(t *testing.T) {
	testCaseList := []testCaseForTestOperandListR1R2Parse{
		{
			data:            "GR0, GR1",
			expectedRemains: "",
			expectedOK:      true,
		},
		{
			data:            "GR2, GR3 ; this is comment",
			expectedRemains: "; this is comment",
			expectedOK:      true,
		},
		{
			data: "			GR4 , 	GR5",
			expectedRemains: "",
			expectedOK:      true,
		},
	}
	for testIndex, testCase := range testCaseList {
		target := operandlist.NewR1R2()
		testData := testCase.data
		expectedRemains := testCase.expectedRemains
		expectedOK := testCase.expectedOK
		// expectedOperandSingleValue := testCase.expectedOperandSingleValue
		// expectedHasValue := testCase.expectedHasValue

		actualRemains, actualOK := target.Parse(testData)
		if actualRemains != expectedRemains {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedRemains, actualRemains)
		}
		if actualOK != expectedOK {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedOK, actualOK)
		}
	}
}
예제 #2
0
파일: opcode.go 프로젝트: mm0205/gcasl
// AcceptableOprandLists returns a list of OperandList.
func (opcode *Opcode) AcceptableOprandLists() *operandlist.ListOfList {
	switch opcode.OpcodeValue {
	case OpcodeValueSTART:
		return operandlist.NewListOfList(operandlist.NewNone(), operandlist.NewLabel())
	case OpcodeValueEND:
		return operandlist.NewListOfList(operandlist.NewNone())
	case OpcodeValueDS:
		return operandlist.NewListOfList(operandlist.NewNumber())
	case OpcodeValueDC:
		return operandlist.NewListOfList(operandlist.NewConstants())
	case OpcodeValueIN:
		return operandlist.NewListOfList(operandlist.NewLabelLabel())
	case OpcodeValueOUT:
		return operandlist.NewListOfList(operandlist.NewLabelLabel())
	case OpcodeValueRPUSH:
		return operandlist.NewListOfList(operandlist.NewNone())
	case OpcodeValueRPOP:
		return operandlist.NewListOfList(operandlist.NewNone())
	case OpcodeValueNOP:
		return operandlist.NewListOfList(operandlist.NewNone())
	case OpcodeValueLD:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueST:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueLAD:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueADDA:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSUBA:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueADDL:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSUBL:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueAND:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueOR:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueXOR:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueCPA:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueCPL:
		return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSLA:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSRA:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSLL:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueSRL:
		return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress())
	case OpcodeValueJMI:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueJNZ:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueJZE:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueJUMP:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueJPL:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueJOV:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValuePUSH:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValuePOP:
		return operandlist.NewListOfList(operandlist.NewRegister())
	case OpcodeValueCALL:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	case OpcodeValueRET:
		return operandlist.NewListOfList(operandlist.NewNone())
	case OpcodeValueSVC:
		return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress())
	}
	return operandlist.NewListOfList()
}