示例#1
0
        public void SimpleAshr_ParseCheck()
        {
            LAshr ashr = new LAshr(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = ashr {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(ashr.ParseInstruction()));
        }
示例#2
0
        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()));
        }
示例#3
0
        public void SimpleLshr_ParseCheck()
        {
            LShl shl = new LShl(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = shl {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(shl.ParseInstruction()));
        }
示例#4
0
        public void SimpleXor_ParseCheck()
        {
            LXor xor = new LXor(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = xor {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(xor.ParseInstruction()));
        }
示例#5
0
        public void SimpleAllocaParse_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type());

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}",
                            LHelper.Trim(alloca.ParseInstruction()));
        }
示例#6
0
        public void SimpleAnd_ParseCheck()
        {
            LAnd and = new LAnd(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = and {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(and.ParseInstruction()));
        }
示例#7
0
        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()));
        }
示例#8
0
        public void Fneg_ParseCheck()
        {
            LFneg fneg = new LFneg(_op1, _result);

            Assert.AreEqual($"{_result.Identifier} = fneg {_result.ParseType()} {_op1.ValueOrIdentifier}",
                            LHelper.Trim(fneg.ParseInstruction()));
        }
示例#9
0
        public void AllocaLiteralStruct_Expected_Ok()
        {
            var     @struct = new LLiteralStruct(new LValueRef(LType.Int128Type(), ""), new LValueRef(LType.Int16Type(), ""));
            LAlloca alloca  = new LAlloca(_function, @struct);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {{ i128, i16 }}", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual("{ i128, i16 }*", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#10
0
        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()));
        }
示例#11
0
        public void Fneg_ParseCheck_FastMathFlags()
        {
            LFneg fneg = new LFneg(_op1, _result);

            fneg.Flags.Add(LFastMathFlags.fast);
            Assert.AreEqual($"{_result.Identifier} = fneg {LFastMathFlags.fast.Parse()} {_result.ParseType()} {_op1.ValueOrIdentifier}",
                            LHelper.Trim(fneg.ParseInstruction()));
        }
示例#12
0
        public void SimpleLoadParse_Expected_True()
        {
            LLoad load = new LLoad(_function, _alloca.PointerRef);

            Assert.AreEqual(
                $"{load.ValueRef.Identifier} = {LKeywords.Load} {LType.Int32Type().Parse()}, {load.PointerRef.ParseType()} {load.PointerRef.Identifier}",
                LHelper.Trim(load.ParseInstruction()));
        }
示例#13
0
        public void UnconditionalBr_ParseCheck()
        {
            LUnconditionalBr unconditionalBr = new LUnconditionalBr(_ifTrueLabel);

            Assert.AreEqual(
                $"{LKeywords.Br} {LKeywords.Label} {_ifTrueLabel.Identifier}",
                LHelper.Trim(unconditionalBr.ParseInstruction()));
        }
示例#14
0
        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()));
        }
示例#15
0
        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()));
        }
示例#16
0
        public void AllocaTriplePointerType_Expected_Equal()
        {
            LPointerRef singlePointer = new LPointerRef(new LValueRef(LType.Int32Type(), ""), _function.GetPointerRefIdentifier());
            LPointerRef doublePointer = new LPointerRef(singlePointer, _function.GetPointerRefIdentifier());
            LAlloca     alloca        = new LAlloca(_function, doublePointer);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}**", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual($"{LType.Int32Type().Parse()}***", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#17
0
        public void AllocaIdentifiedStruct_Expected_Ok()
        {
            string  structIdentifier = "abcTestStruct";
            var     @struct          = new LIdentifiedStruct(structIdentifier, new LValueRef(LType.Int128Type(), ""), new LValueRef(LType.Int16Type(), ""));
            LAlloca alloca           = new LAlloca(_function, @struct);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {structIdentifier}", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual($"{structIdentifier}*", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#18
0
        public void SimpleLshr_Exact_ParseCheck()
        {
            LLshr lshr = new LLshr(_valueResult, _valueOp1, _valueOp2)
            {
                Exact = true
            };

            Assert.AreEqual($"{_valueResult.Identifier} = lshr exact {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(lshr.ParseInstruction()));
        }
示例#19
0
        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()));
        }
示例#20
0
        public void AllocaParseNumOfElements_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type())
            {
                NumOfElements = 5
            };

            Assert.AreEqual(
                $"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}, {LType.Int32Type().Parse()} 5",
                LHelper.Trim(alloca.ParseInstruction()));
        }
示例#21
0
        public void SimpleLshr_NuwNsw_ParseCheck()
        {
            LShl shl = new LShl(_valueResult, _valueOp1, _valueOp2)
            {
                NoUnsignedWrap = true,
                NoSignedWrap   = true,
            };

            Assert.AreEqual($"{_valueResult.Identifier} = shl nuw nsw {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(shl.ParseInstruction()));
        }
示例#22
0
        public void AllocaParseAddrspace_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type())
            {
                Addrspace = 4
            };

            Assert.AreEqual(
                $"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}, {LKeywords.Addrspace}(4)",
                LHelper.Trim(alloca.ParseInstruction()));
        }
示例#23
0
        public void StoreAlignment_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                Alignment = 5012
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}, {LKeywords.Align} 5012",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#24
0
        public void StoreIsAtomic_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                IsAtomic = true
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {LKeywords.Atomic} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#25
0
        public void LoadParseIsAtomicVolatile_Expected_True()
        {
            LLoad load = new LLoad(_function, _alloca.PointerRef)
            {
                IsAtomic   = true,
                IsVolatile = true
            };

            Assert.AreEqual(
                $"{load.ValueRef.Identifier} = {LKeywords.Load} {LKeywords.Atomic} {LKeywords.Volatile} {LType.Int32Type().Parse()}, {load.PointerRef.ParseType()} {load.PointerRef.Identifier}",
                LHelper.Trim(load.ParseInstruction()));
        }
示例#26
0
        public void StoreIsAtomicVolatileAlignment_Hardcoded_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                IsAtomic   = true,
                IsVolatile = true,
                Alignment  = 5012
            };

            Assert.AreEqual(
                $"store atomic volatile i32 {_src.ValueOrIdentifier}, i32* {_dst.Identifier}, align 5012",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#27
0
        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()));
        }
示例#28
0
        public void Ret_ParseCheck_Void_Ok()
        {
            LRet ret = new LRet(new LValueRef(LType.VoidType(), _function.GetValueRefIdentifier()));

            Assert.AreEqual($"{LKeywords.Ret} {LKeywords.Void}", LHelper.Trim(ret.ParseInstruction()));
        }