コード例 #1
0
        public static ASMInstruction Parse(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }
            ASMInstruction instruction = new ASMInstruction();

            string[] split = str.Split(' ');
            if (split[0][0] == '+')
            {
                instruction.DoesAdd = true;
                instruction.Token   = split[0].Substring(1);
            }
            else
            {
                instruction.Token = split[0];
            }
            instruction.Parameter = new ASMParameter[split.Length - 1];
            for (int i = 0; i < instruction.Parameter.Length; ++i)
            {
                instruction.Parameter[i] = ASMParameter.Parse(split[i + 1]);
            }
            return(instruction);
        }
コード例 #2
0
        public static ASMParameter Parse(string str)
        {
            ASMParameter result = new ASMParameter();

            switch (str[0])
            {
            case '*':
                result.IsPointer = true;
                str = str.Substring(1);
                int offsetIndex = str.IndexOf('-');
                if (offsetIndex == -1)
                {
                    offsetIndex = str.IndexOf('+');
                }
                if (offsetIndex == -1)
                {
                    result.Value = int.Parse(str);
                }
                else
                {
                    result.Value  = int.Parse(str.Substring(0, offsetIndex));
                    result.Offset = int.Parse(str.Substring(offsetIndex));
                }
                break;

            case '@':
                result.IsRegister = true;
                str         = str.Substring(1);
                offsetIndex = str.IndexOf('-');
                if (offsetIndex == -1)
                {
                    offsetIndex = str.IndexOf('+');
                }
                if (offsetIndex == -1)
                {
                    result.Value = int.Parse(str);
                }
                else
                {
                    result.Value  = int.Parse(str.Substring(0, offsetIndex));
                    result.Offset = int.Parse(str.Substring(offsetIndex));
                }
                break;

            default:
                result.IsConstant = true;
                result.Value      = int.Parse(str);
                break;
            }
            return(result);
        }
コード例 #3
0
 public bool Accepts(ASMParameter param)
 {
     return((AllowConstant && param.IsConstant) ||
            (AllowRegister && param.IsRegister) ||
            (AllowPointer && param.IsPointer));
 }