public void SimpleFunctionType_ParseCheck() { var returnVal = new LValueRef(LType.F32Type(), ""); var parameter = new LPointerRef(new LValueRef(LType.F32Type(), ""), ""); LFunctionType fnType = new LFunctionType(returnVal, parameter); Assert.AreEqual("float (float*)", fnType.Parse()); }
public void Ret_ParseCheck_i32_Value_Ok() { LValueRef valueRef = new LValueRef(LType.Int32Type(), "12"); LRet ret = new LRet(valueRef); Assert.AreEqual($"{LKeywords.Ret} i32 12", LHelper.Trim(ret.ParseInstruction())); }
public void Ret_ParseCheck_i32_Identifier_Ok() { LValueRef valueRef = new LValueRef(LType.Int32Type(), _function.GetValueRefIdentifier()); LRet ret = new LRet(valueRef); Assert.AreEqual($"{LKeywords.Ret} i32 {valueRef.ValueOrIdentifier}", LHelper.Trim(ret.ParseInstruction())); }
public void SimpleLshr_WithConstant_ParseCheck() { LValueRef op2 = new LValueRef(LType.Int32Type(), "12"); LShl shl = new LShl(_valueResult, _valueOp1, op2); Assert.AreEqual($"{_valueResult.Identifier} = shl {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {op2.ValueOrIdentifier}", LHelper.Trim(shl.ParseInstruction())); }
public void SimpleAnd_WithConstant_ParseCheck() { LValueRef op2 = new LValueRef(LType.Int32Type(), "12"); LAnd and = new LAnd(_valueResult, _valueOp1, op2); Assert.AreEqual($"{_valueResult.Identifier} = and {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {op2.ValueOrIdentifier}", LHelper.Trim(and.ParseInstruction())); }
public void VarargFunctionType_ParseCheck() { var returnVal = new LValueRef(LType.F32Type(), ""); var parameter = new LPointerRef(new LValueRef(LType.F32Type(), ""), ""); LFunctionType fnType = new LFunctionType(returnVal, parameter) { HasVararg = true }; Assert.AreEqual("float (float*, ...)", fnType.Parse()); }
public void Switch_Unconditional_ParseCheck() { LValueRef valueRef = new LValueRef(LType.Int32Type(), "%1"); LLabelType defaultLabel = new LLabelType("%default"); LSwitch @switch = new LSwitch(valueRef, defaultLabel); Assert.AreEqual("switch i32 %1, label %default [ ]", LHelper.Trim(@switch.ParseInstruction())); }
public void SimpleFunctionType_ArrayAsParameter_Expected_Exception() { var returnVal = new LValueRef(LType.F32Type(), ""); var parameter = new LArrayRef("", new LValueRef(LType.F32Type(), ""), 5); LFunctionType fnType; Assert.Throws<Exception>(() => fnType = new LFunctionType(returnVal, parameter) ); }
public LPtrtointTo(LValueRef result, LPointerRef value) { if (!result.Type.IsIntegral() || !value.BaseType.IsIntegral()) { throw new Exception("Only floating point types are allowed for ptrtoint ... to instruction." + $"Result: {result.ParseType()}, Value: {value.ParseType()}"); } Result = result; Value = value; }
public void ConditionalBr_ParseCheck() { LValueRef condition = new LValueRef(LType.BoolType(), _function.GetValueRefIdentifier()); LConditionalBr conditionalBr = new LConditionalBr( condition, _ifTrueLabel, _ifFalseLabel); Assert.AreEqual( $"{LKeywords.Br} i1 {condition.ValueOrIdentifier}, {LKeywords.Label} {_ifTrueLabel.Identifier}, {LKeywords.Label} {_ifFalseLabel.Identifier}", LHelper.Trim(conditionalBr.ParseInstruction())); }
public LZextTo(LValueRef result, LValueRef value) { if (!result.Type.IsIntegral() || !value.Type.IsIntegral()) { throw new Exception("Only integer types are allowed for zext ... to instruction." + $"Result: {result.ParseType()}, Value: {value.ParseType()}"); } Result = result; Value = value; }
public LFptruncTo(LValueRef result, LValueRef value) { if (!result.Type.IsFloatingPoint() || !value.Type.IsFloatingPoint()) { throw new Exception("Only floating point types are allowed for fptrunc ... to instruction." + $"Result: {result.ParseType()}, Value: {value.ParseType()}"); } Result = result; Value = value; }
public LSitofpTo(LValueRef result, LValueRef value) { if (!result.Type.IsFloatingPoint() || !value.Type.IsIntegral()) { throw new Exception("Result must be a floating point and value an integer type for uitofp ... to instruction." + $"Result: {result.ParseType()}, Value: {value.ParseType()}"); } Result = result; Value = value; }
public LConditionalBr(LValueRef condition, LLabelType ifTrueLabel, LLabelType ifFalseLabel) { if (!condition.Type.IsPrimitiveType() || condition.Type.CheckedCast <LPrimitiveType>().Type != LPrimitiveTypes.@bool) { throw new Exception("Condition must be from type i1. Actual type: " + condition.ParseType()); } Condition = condition; IfTrueLabel = ifTrueLabel; IfFalseLabel = ifFalseLabel; }
public void Switch_ParseCheck() { LValueRef valueRef = new LValueRef(LType.Int32Type(), "%1"); LLabelType defaultLabel = new LLabelType("%default"); LSwitch @switch = new LSwitch(valueRef, defaultLabel); @switch.JumpTableDestinations.Add((0, new LLabelType("%one"))); @switch.JumpTableDestinations.Add((1, new LLabelType("%two"))); @switch.JumpTableDestinations.Add((2, new LLabelType("%three"))); @switch.JumpTableDestinations.Add((3, new LLabelType("%four"))); Assert.AreEqual($"switch i32 %1, label %default [ i32 0, label %one{Environment.NewLine}i32 1, label %two{Environment.NewLine}i32 2, label %three{Environment.NewLine}i32 3, label %four ]", LHelper.Trim(@switch.ParseInstruction())); }
public LAnd(LValueRef result, LValueRef op1, LValueRef op2) { if (result.Type != op1.Type || op1.Type != op2.Type) { throw new Exception($"Types of operands or result are not equal. Result: {result.ParseType()}" + $", Op1: {op1.ParseType()}, Op2: {op2.ParseType()}"); } if (result.Type.IsFloatingPoint()) { throw new Exception("Floating point types are not allowed for and."); } Result = result; Op1 = op1; Op2 = op2; }
/// <summary> /// Returns identifier of reference. /// </summary> /// <param name="reference"></param> /// <returns>identifier</returns> public static string GetIdentifierOf(LBaseRef reference) { if (reference.IsValue()) { LValueRef value = (LValueRef)reference; return(value.Identifier !); } else if (reference.IsPointer()) { LPointerRef pointer = (LPointerRef)reference; return(pointer.Identifier); } else if (reference.IsArray()) { LArrayRef array = (LArrayRef)reference; return(array.Identifier); } else if (reference.IsVector()) { LVectorRef vector = (LVectorRef)reference; return(vector.Identifier !); } throw new Exception("unknown reference."); }
public void SetUp() { _dst = new LPointerRef(new LValueRef(LType.Int32Type(), ""), "%ptr"); _src = new LValueRef(LType.Int32Type(), "%val"); }