コード例 #1
0
        /// <summary>
        /// Adds a new <see cref="Instr.Alloc"/>.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to allocate space for.</param>
        /// <returns>The pointer to the allocated space.</returns>
        public Value Alloc(Type type)
        {
            var ptrType   = new Type.Ptr(type);
            var resultReg = AllocateRegister(ptrType);

            AddInstr(new Instr.Alloc(resultReg));
            return(resultReg);
        }
コード例 #2
0
        public void PointerPointer()
        {
            var b      = GetBuilder();
            var intPtr = new Type.Ptr(Type.I32);
            var ip     = b.Alloc(intPtr);
            var i      = b.Alloc(Type.I32);

            b.Store(ip, i);
            b.Store(b.Load(ip), Type.I32.NewValue(123));
            b.Ret(b.Load(i));

            TestOnAllBackends(b, Type.I32.NewValue(123));
        }
コード例 #3
0
        public void ModifyParameter()
        {
            var intPtr = new Type.Ptr(Type.I32);
            var b      = GetBuilder();
            var entry  = b.CurrentProc;

            var modify = b.DefineProc("modify");
            var p      = b.DefineParameter(intPtr);

            b.Store(p, Type.I32.NewValue(73));
            b.Ret();

            b.CurrentProc = entry;
            var storage = b.Alloc(Type.I32);

            b.Store(storage, Type.I32.NewValue(62));
            b.Call(modify, new List <Value> {
                storage
            });
            b.Ret(b.Load(storage));
            TestOnAllBackends(b, Type.I32.NewValue(73));
        }
コード例 #4
0
        public void ModifyBigParameter()
        {
            var intPtr = new Type.Ptr(Type.I64);
            var b      = GetBuilder(Type.I64);
            var entry  = b.CurrentProc;

            var modify = b.DefineProc("modify");
            var p      = b.DefineParameter(intPtr);

            b.Store(p, Type.I64.NewValue(8_724_105_835));
            b.Ret();

            b.CurrentProc = entry;
            var storage = b.Alloc(Type.I64);

            b.Store(storage, Type.I64.NewValue(1_176_864_900));
            b.Call(modify, new List <Value> {
                storage
            });
            b.Ret(b.Load(storage));
            TestOnAllBackends <Func <Int64> >(b, Type.I64.NewValue(8_724_105_835));
        }
コード例 #5
0
ファイル: Global.cs プロジェクト: LPeter1997/YoakkeLang
 /// <summary>
 /// Initializes a new <see cref="Global"/>.
 /// </summary>
 /// <param name="name">The name of the global symbol.</param>
 /// <param name="type">The <see cref="Type"/> of the global symbol.</param>
 public Global(string name, Type type)
 {
     Name = name;
     Type = new Type.Ptr(type);
 }