Beispiel #1
0
 public override Expression GetStoreBufferLocationInfo(ref List <Expression> fields)
 {
     if (parent.NoTSO())
     {
         return(null);
     }
     if (parent is GlobalsArmadaLValue)
     {
         return(AH.MakeNameSegment($"Armada_GlobalStaticVar_{fieldName}", "Armada_GlobalStaticVar"));
     }
     else if (!(parent.Type is UserDefinedType))
     {
         return(null);
     }
     else
     {
         var ut  = (UserDefinedType)parent.Type;
         var ret = parent.GetStoreBufferLocationInfo(ref fields);
         if (ret == null)
         {
             return(null);
         }
         var struct_field_type = AH.MakeNameSegment($"Armada_FieldType_{ut.Name}'{fieldName}", "Armada_FieldType");
         var field             = AH.MakeApply1("Armada_FieldStruct", struct_field_type, "Armada_Field");
         fields.Add(field);
         return(ret);
     }
 }
Beispiel #2
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty)
        {
            if (!(type is SizedArrayType))
            {
                context.Fail(i_tok, "Attempt to obtain element of non-array type");
                return(null);
            }
            SizedArrayType st = (SizedArrayType)type;

            if (!AH.TypesMatch(st.Range, ty))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {ty}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s    = context.GetLValueState();
            var mem  = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h    = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var tree = AH.MakeExprDotName(h, "tree", "Armada_Tree");

            crashAvoidance.Add(AH.MakeInExpr(address.Val, tree));

            var node        = AH.MakeSeqSelectExpr(tree, address.Val, "Armada_Node");
            var children    = AH.MakeExprDotName(node, "children", AH.MakeChildrenType());
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val);
            var field       = AH.MakeApply1("Armada_FieldArrayIndex", idx1_as_int, "Armada_Field");
            var child       = AH.MakeSeqSelectExpr(children, field, new PointerType(st.Range));

            crashAvoidance.Add(AH.MakeInExpr(field, children));

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }
Beispiel #3
0
        public override Expression GetStoreBufferLocation()
        {
            if (!AH.IsPrimitiveType(type))
            {
                return(null);
            }

            return(AH.MakeApply1("Armada_StoreBufferLocation_Addressable", address.Val, "Armada_StoreBufferLocation"));
        }
Beispiel #4
0
        public Expression GetStoreBufferEntry(Expression val_new)
        {
            var loc = GetStoreBufferLocation();

            if (loc == null)
            {
                return(null);
            }
            var primitive_value_constructor = AH.MakeNameSegment(AH.GetPrimitiveValueConstructorName(val_new.Type), "Armada_PrimitiveValue");
            var boxed_val_new = AH.MakeApply1(primitive_value_constructor, val_new, "Armada_PrimitiveValue");

            return(AH.MakeApply2("Armada_StoreBufferEntry", loc, boxed_val_new, "Armada_StoreBufferEntry"));
        }
Beispiel #5
0
        public override ArmadaLValue ApplyExprDotName(IToken i_tok, ResolutionContext context, string fieldName, Type ty)
        {
            if (!(type is UserDefinedType))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non-struct type {type}");
                return(null);
            }
            UserDefinedType ut = (UserDefinedType)type;

            if (!context.symbols.DoesStructExist(ut.Name))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non struct type {ut.Name}");
                return(null);
            }
            Type fieldType = context.symbols.GetStructFieldType(ut.Name, fieldName);

            if (fieldType == null)
            {
                context.Fail(i_tok, $"Attempt to take non-existent field ({fieldName}) in struct type {ut.Name}");
                return(null);
            }
            if (!AH.TypesMatch(fieldType, ty))
            {
                context.Fail(i_tok, $"Field {fieldName} of type {fieldType} used as type {ty}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance;

            var s    = context.GetLValueState();
            var mem  = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h    = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var tree = AH.MakeExprDotName(h, "tree", "Armada_Tree");

            crashAvoidance.Add(AH.MakeInExpr(address.Val, tree));

            var node     = AH.MakeSeqSelectExpr(tree, address.Val, "Armada_Node");
            var children = AH.MakeExprDotName(node, "children", AH.MakeChildrenType());
            var field    = AH.MakeApply1("Armada_FieldStruct",
                                         AH.MakeNameSegment($"Armada_FieldType_{ut.Name}'{fieldName}", "Armada_FieldType"),
                                         "Armada_Field");
            var child = AH.MakeSeqSelectExpr(children, field, new PointerType(fieldType));

            crashAvoidance.Add(AH.MakeInExpr(field, children));

            return(new AddressableArmadaLValue(i_tok, fieldType, new ArmadaRValue(crashAvoidance, child)));
        }
Beispiel #6
0
        public override Expression GetStoreBufferLocationInfo(ref List <Expression> fields)
        {
            if (parent.NoTSO())
            {
                return(null);
            }

            var ret = parent.GetStoreBufferLocationInfo(ref fields);

            if (ret == null)
            {
                return(null);
            }

            var field = AH.MakeApply1("Armada_FieldArrayIndex", index, "Armada_Field");

            fields.Add(field);
            return(ret);
        }