Esempio n. 1
0
File: Math.cs Progetto: Myvar/XSharp
        protected void RegMathVar(Register aReg, string aOpMath, Address aVal)
        {
            switch (aOpMath)
            {
            case "+=":
                Asm.Emit(OpCode.Add, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
                break;

            case "-=":
                Asm.Emit(OpCode.Sub, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
                break;

            case "*=":
                Asm.Emit(OpCode.Mul, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
                break;

            case "/=":
                Asm.Emit(OpCode.Div, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
                break;

            case "%=":
                Asm.Emit(OpCode.Rem, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
                break;

            default:
                throw new Exception("Unsupported math operator");
            }
        }
Esempio n. 2
0
        protected void RegMathVar(Register aReg, string aOpMath, Address aVal)
        {
            // TODO: Do this better? Use Compiler.GetFullName() so things are consistent.
            aVal.AddPrefix(Compiler.CurrentNamespace);

            switch (aOpMath)
            {
            case "+=":
                Asm.Emit(OpCode.Add, aReg, aReg.RegSize, aVal);
                break;

            case "-=":
                Asm.Emit(OpCode.Sub, aReg, aReg.RegSize, aVal);
                break;

            case "*=":
                Asm.Emit(OpCode.Mul, aReg, aReg.RegSize, aVal);
                break;

            case "/=":
                Asm.Emit(OpCode.Div, aReg, aReg.RegSize, aVal);
                break;

            case "%=":
                Asm.Emit(OpCode.Rem, aReg, aReg.RegSize, aVal);
                break;

            default:
                throw new Exception("Unsupported math operator");
            }
        }
Esempio n. 3
0
        protected void VariableAssignment(Address aVariableName, string aOpEquals, object aValue)
        {
            // TODO: Do this better? Use Compiler.GetFullName() so things are consistent.
            aVariableName.AddPrefix(Compiler.CurrentNamespace);

            string size;

            switch (aValue)
            {
            case uint _:
                size = "dword";
                Asm.Emit(OpCode.Mov, size, aVariableName, aValue);
                break;

            case Register aValueReg:
                size = aValueReg.RegSize;
                Asm.Emit(OpCode.Mov, size, aVariableName, aValue);
                break;

            case string _:
                //TODO: verify this
                aValue = Compiler.GetFullName($"Const_{aValue}");
                Asm.Emit(OpCode.Mov, aVariableName, aValue);
                break;
            }
        }
Esempio n. 4
0
        protected void IfSizeRegisterConditionVariableReturn(string aOpIf, string aSize, Register aRegister, string aOpCompare, Address aValue, object aOpReturn)
        {
            var xJumpOpCode = GetJumpOpCode(aOpCompare);

            aValue.AddPrefix(Compiler.CurrentNamespace);
            Asm.Emit(OpCode.Cmp, aSize, aRegister, aValue);
            Asm.Emit(xJumpOpCode, Compiler.CurrentFunctionExitLabel);
        }
Esempio n. 5
0
        protected void IfRegisterConditionVariable(string aOpIf, Register aRegister, string aOpCompare, Address aValue, object aOpOpenBrace)
        {
            Compiler.Blocks.StartBlock(Compiler.BlockType.If);
            var xJumpOpCode = GetOppositeJumpOpCode(aOpCompare);

            aValue.AddPrefix(Compiler.CurrentNamespace);
            Asm.Emit(OpCode.Cmp, aRegister, aValue);
            Asm.Emit(xJumpOpCode, Compiler.Blocks.EndBlockLabel);
        }
Esempio n. 6
0
        protected void IfRegisterConditionVariable(string aOpIf, Register aRegister, string aOpCompare, Address aValue, string aGotoKeyword, string aLabel)
        {
            var xJumpOpCode = GetJumpOpCode(aOpCompare);

            aValue.AddPrefix(Compiler.CurrentNamespace);
            Asm.Emit(OpCode.Cmp, aRegister, aValue);
            string xLabel = Compiler.GetFullName(aLabel, true);

            Asm.Emit(xJumpOpCode, xLabel);
        }
Esempio n. 7
0
        protected void IfSizeAdressConditionConst(string aOpIf, string aSize, Address aAdress, string aOpCompare, string aConstant, object aOpOpenBrace)
        {
            Compiler.Blocks.StartBlock(Compiler.BlockType.If);
            var xJumpOpCode = GetOppositeJumpOpCode(aOpCompare);

            aAdress.AddPrefix(Compiler.CurrentNamespace);
            string xConstant = Compiler.GetFullName($"Const_{aConstant}");

            Asm.Emit(OpCode.Cmp, aSize, aAdress, xConstant);
            Asm.Emit(xJumpOpCode, Compiler.Blocks.EndBlockLabel);
        }
Esempio n. 8
0
        protected void VariableAssignment(Address aVariableName, string aOpEquals, object aValue)
        {
            string size;

            switch (aValue)
            {
            case uint _:
                size = "dword";
                Asm.Emit(OpCode.Mov, size, aVariableName.AddPrefix(Compiler.GetPrefixForVar), aValue);
                break;

            case Register aValueReg:
                size = aValueReg.RegSize;
                Asm.Emit(OpCode.Mov, size, aVariableName.AddPrefix(Compiler.GetPrefixForVar), aValue);
                break;

            case string _:
                //TODO: verify this
                aValue = $"{Compiler.GetPrefixForConst}{aValue}";
                Asm.Emit(OpCode.Mov, aVariableName.AddPrefix(Compiler.GetPrefixForVar), aValue);
                break;
            }
        }
Esempio n. 9
0
 protected void PopVar(string aOpPlus, Address value)
 {
     // TODO: Do this better? Use Compiler.GetFullName() so things are consistent.
     value.AddPrefix(Compiler.CurrentNamespace);
     Asm.Emit(OpCode.Pop, value);
 }
Esempio n. 10
0
 protected void RegAssignVar(Register aReg, string aEquals, Address aVal)
 {
     // TODO: Do this better? Use Compiler.GetFullName() so things are consistent.
     aVal.AddPrefix(Compiler.CurrentNamespace);
     Asm.Emit(OpCode.Mov, aReg, aReg.RegSize, aVal);
 }
Esempio n. 11
0
 protected void VariableAssignToMemory(string aOpOpenBracket, Register aTargetRegisterRoot, string aOpCloseBracket, string aOpEquals, Address source)
 {
     source.AddPrefix(Compiler.CurrentNamespace);
     Asm.Emit(OpCode.Mov, "dword", new Address(aTargetRegisterRoot), source);
 }
Esempio n. 12
0
 protected void RegAssigVar(Register aReg, string aEquals, Address aVal)
 {
     Asm.Emit(OpCode.Mov, aReg, aReg.RegSize, aVal.AddPrefix(Compiler.GetPrefixForVar));
 }
Esempio n. 13
0
 protected void PopVar(string aOpPlus, Address value)
 {
     Asm.Emit(OpCode.Pop, value.AddPrefix(Compiler.GetPrefixForVar));
 }
Esempio n. 14
0
 protected void RegAssignVar(Register aReg, string aEquals, Address aVal)
 {
     Asm.Emit(OpCode.Mov, aReg, aReg.RegSize, aVal.AddPrefix($"{Compiler.CurrentNamespace}_"));
 }
Esempio n. 15
0
 protected void PopVar(string aOpPlus, Address value)
 {
     Asm.Emit(OpCode.Pop, value.AddPrefix($"{Compiler.CurrentNamespace}_"));
 }