public static IMOperand Reference(DataType dataType, IMOperand refValue) { return(new IMOperand() { DataType = dataType, Kind = IMOperandKind.Reference, ChildValue = refValue }); }
public override List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { return(new List <IMOperation>() { IMOperation.Mul(target, operand1, operand2) }); }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { return(IMOperation.Create(_setInstruction, new List <IMOperand>() { target, operand1, operand2 }).AsList); }
public IMOperation(IMInstruction instruction, IMOperand operand1, IMOperand operand2, IMOperand operand3) { Assert.True(instruction.NumOperands == 3, "Instruction " + instruction.Name + " expected " + instruction.NumOperands + " operands, but 3 given!"); Instruction = instruction; Operands = new List <IMOperand> { operand1, operand2, operand3 }; }
private IMOperation(IMInstruction instruction, IMOperand operand1, IMOperand operand2) { Assert.True(instruction.NumOperands == 2, "Instruction " + instruction.Name + " expected " + instruction.NumOperands + " operands, but 2 given!"); Instruction = instruction; Operands = new List <IMOperand> { operand1, operand2 }; }
private static string ImmediateChar8ToAsmCode(IMOperand operand) { var strValue = (string)operand.ImmediateValue; var firstChar = strValue[0]; var number = (ushort)firstChar; return(number.ToString() + " ; '" + StringUtils.CharToPrintableStr(firstChar) + "'"); }
public static IMOperation GVec(IMOperand target, List <IMOperand> values) { var allOperands = new List <IMOperand>() { target }; allOperands.AddRange(values); return(new IMOperation() { Instruction = IMInstruction.GVEC, Operands = allOperands }); }
public static IMOperation Call(string functionName, IMOperand result, List <IMOperand> paramValues) { var allOperands = new List <IMOperand>() { IMOperand.Identifier(functionName), result }; allOperands.AddRange(paramValues); return(new IMOperation() { Instruction = IMInstruction.CALL, Operands = allOperands }); }
public override List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { switch (operand1.DataType.Kind) { case DataTypeKind.ARRAY: throw new NotImplementedException(); case DataTypeKind.STRING8: return(GenerateStringConcat(env, target, operand1, operand2)); default: return(IMOperation.Add(target, operand1, operand2).AsList); } }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { var result = new List <IMOperation>(); if (_negate) { result.Add(IMOperation.SetNE(target, operand1, operand2)); } else { result.Add(IMOperation.SetE(target, operand1, operand2)); } return(result); }
public List <IMOperation> Generate(IMOperand target, IMOperand operand) { if (operand.DataType.Kind == DataTypeKind.ARRAY || operand.DataType.Kind == DataTypeKind.STRING8) { //Array already is a pointer, so directly use it //Add 8 bytes to array pointer so it points to first value, not to the length var result = new List <IMOperation>(2) { IMOperation.Mov(target, operand), IMOperation.Add(target, target, IMOperand.Immediate(DataType.U64, 8L)) }; return(result); } return(IMOperation.Lea(target, operand).AsList); }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { if (target.DataType.Kind == operand1.DataType.Kind) { return new List <IMOperation>() { IMOperation.Mov(target, operand1) } } ; else { return new List <IMOperation>() { IMOperation.Cast(target, operand1) } }; } }
private static string ImmediateString8ToAsmCode(IMOperand operand) { var strValue = (string)operand.ImmediateValue; var numBytes = 8 + strValue.Length + 1; //size + string value + terminating zero var immediateBytes = new List <byte>(numBytes); //Add 4 bytes length var length = (ulong)strValue.Length; immediateBytes.AddRange(BitConverter.GetBytes(length)); //Add string value encoded as bytes immediateBytes.AddRange(_isoEncoding.GetBytes(strValue)); //Add terminating zero immediateBytes.Add(0); //Create final string return(String.Join(",", immediateBytes.ConvertAll((b) => b.ToString())) + "; \"" + StringUtils.Escape(strValue) + "\""); }
public static IMOperation Lea(IMOperand target, IMOperand source) { return(new IMOperation(IMInstruction.LEA, target, source)); }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { return(IMOperation.Nop().AsList); }
public static IMOperation Shr(IMOperand target, IMOperand source, IMOperand numBits) { return(new IMOperation(IMInstruction.SHR, target, source, numBits)); }
public override List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { return(IMOperation.Div(target, operand1, operand2).AsList); }
public static IMOperation Add(IMOperand target, IMOperand summand1, IMOperand summand2) { return(new IMOperation(IMInstruction.ADD, target, summand1, summand2)); }
public static string GetMemLocationName(IMOperand target) { return("mem(" + target.FullName + ")"); }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { throw new NotImplementedException("StaticAccessOperator should not generate anything at the moment!"); }
public List <IMOperation> Generate(IMOperand target, IMOperand operand) { return(IMOperation.Neg(target, operand).AsList); }
public List <IMOperation> Generate(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { return(new IMOperation(_instruction, target, operand1, operand2).AsList); }
public static IMOperation Push(IMOperand source) { return(new IMOperation(IMInstruction.PUSH, source)); }
private List <IMOperation> GenerateStringConcat(IMGeneratorEnv env, IMOperand target, IMOperand operand1, IMOperand operand2) { var result = new List <IMOperation>(20); var op1LengthLocation = IMOperand.Reference(DataType.U64, operand1); var op2LengthLocation = IMOperand.Reference(DataType.U64, operand2); //Calculate new string length var lengthLocation = env.NewTempLocal(DataType.U64); result.Add(IMOperation.Mov(lengthLocation, op1LengthLocation)); result.Add(IMOperation.Add(lengthLocation, lengthLocation, op2LengthLocation)); //Calculate new string byte size var byteSizeLocation = env.NewTempLocal(DataType.U64); result.Add(IMOperation.Mov(byteSizeLocation, lengthLocation)); result.Add(IMOperation.Add(lengthLocation, lengthLocation, IMOperand.Immediate(DataType.U64, 9L))); //Reserve new memory on stack, which is freed automatically result.Add(IMOperation.SAloc(target, byteSizeLocation)); //Copy target address var targetAddressLocation = env.NewTempLocal(target.DataType); result.Add(IMOperation.Mov(targetAddressLocation, target)); //Write new string length to target result.Add(IMOperation.Mov(IMOperand.Reference(DataType.U64, targetAddressLocation), lengthLocation)); //Move pointer to first char result.Add(IMOperation.Add(targetAddressLocation, targetAddressLocation, IMOperand.Immediate(DataType.U64, 8L))); var targetRefLocation = IMOperand.Reference(DataType.CHAR8, targetAddressLocation); //Get address of first char of operand1 var sourceAddressLocation = env.NewTempLocal(target.DataType); result.Add(IMOperation.Mov(sourceAddressLocation, operand1)); result.Add(IMOperation.Add(sourceAddressLocation, sourceAddressLocation, IMOperand.Immediate(DataType.U64, 8L))); var sourceRefLocation = IMOperand.Reference(DataType.CHAR8, sourceAddressLocation); var startLabel = env.NewLabelName(); var endLabel = env.NewLabelName(); //Start label result.Add(IMOperation.Labl(startLabel)); //Check if more chars to copy (string ends with 0 char) result.Add(IMOperation.JmpE(sourceRefLocation, IMOperand.Immediate(DataType.CHAR8, "\0"), endLabel)); //Copy char result.Add(IMOperation.Mov(targetRefLocation, sourceRefLocation)); //Inc target and source pointers result.Add(IMOperation.Add(targetAddressLocation, targetAddressLocation, IMOperand.Immediate(DataType.U64, 1L))); result.Add(IMOperation.Add(sourceAddressLocation, sourceAddressLocation, IMOperand.Immediate(DataType.U64, 1L))); //Next iteration result.Add(IMOperation.Jmp(startLabel)); result.Add(IMOperation.Labl(endLabel)); //Get address of first char of operand2 result.Add(IMOperation.Mov(sourceAddressLocation, operand2)); result.Add(IMOperation.Add(sourceAddressLocation, sourceAddressLocation, IMOperand.Immediate(DataType.U64, 8L))); startLabel = env.NewLabelName(); endLabel = env.NewLabelName(); //Start label result.Add(IMOperation.Labl(startLabel)); //Check if more chars to copy (string ends with 0 char) result.Add(IMOperation.JmpE(sourceRefLocation, IMOperand.Immediate(DataType.CHAR8, "\0"), endLabel)); //Copy char result.Add(IMOperation.Mov(targetRefLocation, sourceRefLocation)); //Inc target and source pointers result.Add(IMOperation.Add(targetAddressLocation, targetAddressLocation, IMOperand.Immediate(DataType.U64, 1L))); result.Add(IMOperation.Add(sourceAddressLocation, sourceAddressLocation, IMOperand.Immediate(DataType.U64, 1L))); //Next iteration result.Add(IMOperation.Jmp(startLabel)); result.Add(IMOperation.Labl(endLabel)); //Terminating 0 result.Add(IMOperation.Mov(targetRefLocation, IMOperand.Immediate(DataType.U8, (byte)0))); return(result); }
public static IMOperation Pop(IMOperand target) { return(new IMOperation(IMInstruction.POP, target)); }
public static IMOperation Sub(IMOperand target, IMOperand minuend, IMOperand subtrahend) { return(new IMOperation(IMInstruction.SUB, target, minuend, subtrahend)); }
public static IMOperation Cast(IMOperand target, IMOperand source) { return(new IMOperation(IMInstruction.CAST, target, source)); }
public static IMOperation Mov(IMOperand target, IMOperand source) { return(new IMOperation(IMInstruction.MOV, target, source)); }
public IMOperand NewTempLocal(DataType dataType) { _tempLocalCounter += 1; return(IMOperand.Local(dataType, _tempLocalCounter.ToString())); }
public static IMOperation BinaryOperator(IMInstruction instruction, IMOperand target, IMOperand operand1, IMOperand operand2) { return(new IMOperation(instruction, target, operand1, operand2)); }