예제 #1
0
        public override Expression GetValueInLValueState(ResolutionContext context)
        {
            var s   = context.GetLValueState();
            var mem = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");

            return(AH.MakeExprDotName(mem, "globals", "Armada_Globals"));
        }
예제 #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)));
        }
예제 #3
0
        public override string UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                                string val_new)
        {
            var s = context.GetLValueState();

            return($"({s}).(mem := ({s}).mem.(globals := {val_new}))");
        }
예제 #4
0
        public override Expression UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                                    Expression val_new)
        {
            var s = context.GetLValueState();

            return(AH.MakeDatatypeUpdateExpr(s, "ghosts", val_new));
        }
예제 #5
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type indexType, Type exprType)
        {
            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, exprType))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {exprType}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s           = context.GetLValueState();
            var h           = $"({s}).mem.heap";
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val, indexType);

            crashAvoidance.Add($"{address.Val} in {h}.tree");
            crashAvoidance.Add($"0 <= {idx1_as_int} < |{h}.tree[{address.Val}].children|");

            var child = $"{h}.tree[{address.Val}].children[{idx1_as_int}]";

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }
예제 #6
0
        public override Expression UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                                    Expression val_new)
        {
            var s     = context.GetLValueState();
            var mem   = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h     = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var valid = AH.GetInvocationOfValidPointer(h, address.Val, type);

            if (valid == null)
            {
                constraintCollector.Fail(tok, $"Type {type} is currently not supported in the heap");
            }
            else
            {
                constraintCollector.AddUndefinedBehaviorAvoidanceConstraint(valid);
            }

            var h_new = AH.GetInvocationOfUpdatePointer(h, address.Val, val_new);

            if (h_new == null)
            {
                constraintCollector.Fail(tok, $"Type {type} is currently not supported in the heap");
            }

            var mem_new = AH.MakeDatatypeUpdateExpr(mem, "heap", h_new);

            return(AH.MakeDatatypeUpdateExpr(s, "mem", mem_new));
        }
예제 #7
0
        public override string UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                                string val_new)
        {
            var s     = context.GetLValueState();
            var h     = $"({s}).mem.heap";
            var valid = AH.GetInvocationOfValidPointer(h, address.Val, type);

            if (valid == null)
            {
                constraintCollector.Fail(tok, $"Type {type} is currently not supported in the heap");
            }
            else
            {
                constraintCollector.AddUndefinedBehaviorAvoidanceConstraint(valid);
            }

            var h_new = AH.GetInvocationOfUpdatePointer(h, address.Val, val_new, type);

            if (h_new == null)
            {
                constraintCollector.Fail(tok, $"Type {type} is currently not supported in the heap");
            }

            return($"{s}.(mem := {s}.mem.(heap := {h_new}))");
        }
예제 #8
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var s     = context.GetLValueState();
            var addrs = AH.MakeExprDotName(s, "addrs", "Armada_Addrs");
            var addr  = AH.MakeExprDotName(addrs, name, new PointerType(ty));

            return(new AddressableArmadaLValue(tok, ty, new ArmadaRValue(addr)));
        }
예제 #9
0
        public override Expression UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                                    Expression val_new)
        {
            var s       = context.GetLValueState();
            var mem     = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var mem_new = AH.MakeDatatypeUpdateExpr(mem, "globals", val_new);

            return(AH.MakeDatatypeUpdateExpr(s, "mem", mem_new));
        }
예제 #10
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)));
        }
예제 #11
0
        public override ArmadaLValue ApplyExprDotName(IToken i_tok, ResolutionContext context, string fieldName, Type targetType)
        {
            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, targetType))
            {
                context.Fail(i_tok, $"Field {fieldName} of type {fieldType} used as type {targetType}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance;

            var s        = context.GetLValueState();
            var h        = $"({s}).mem.heap";
            int fieldPos = context.symbols.GetStructFieldPos(ut.Name, fieldName);

            crashAvoidance.Add($"{address.Val} in {h}.tree");
            crashAvoidance.Add($"0 <= {fieldPos} < |{h}.tree[{address.Val}].children|");

            var child = $"{h}.tree[{address.Val}].children[{fieldPos}]";

            return(new AddressableArmadaLValue(i_tok, fieldType, new ArmadaRValue(crashAvoidance, child)));
        }
예제 #12
0
        public Expression UpdateTotalStateWithStoreBufferEntry(ResolutionContext context, IConstraintCollector constraintCollector,
                                                               Expression val_new)
        {
            if (NoTSO())
            {
                return(UpdateTotalStateLocationDirectly(context, constraintCollector, val_new));
            }

            if (!AH.IsPrimitiveType(type))
            {
                context.Fail(tok, "Can't do TSO write to non-primitive type; try using ::= instead of :=");
                return(null);
            }

            var entry = GetStoreBufferEntry(val_new);

            if (entry == null)
            {
                context.Fail(tok, "Can't do a TSO write to that location; try using ::= instead of :=");
                return(null);
            }

            return(AH.MakeApply3("Armada_AppendToThreadStoreBuffer", context.GetLValueState(), context.tid, entry, "Armada_TotalState"));
        }
예제 #13
0
        public string UpdateTotalStateWithStoreBufferEntry(ResolutionContext context, IConstraintCollector constraintCollector,
                                                           string val_new, ArmadaPC pc)
        {
            if (NoTSO())
            {
                return(UpdateTotalStateLocationDirectly(context, constraintCollector, val_new));
            }

            if (!AH.IsPrimitiveType(type))
            {
                context.Fail(tok, "Can't do TSO write to non-primitive type; try using ::= instead of :=");
                return(null);
            }

            var entry = GetStoreBufferEntry(val_new, pc);

            if (entry == null)
            {
                context.Fail(tok, "Can't do a TSO write to that location; try using ::= instead of :=");
                return(null);
            }

            return($"Armada_AppendToThreadStoreBuffer({context.GetLValueState()}, {context.tid}, {entry})");
        }
예제 #14
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var addr = $"({context.GetLValueState()}).addrs.{name}";

            return(new AddressableArmadaLValue(tok, ty, new ArmadaRValue(addr)));
        }
예제 #15
0
 public override string UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                         string val_new)
 {
     return($"Armada_UpdateTSFrame({context.GetLValueState()}, {context.tid}, Armada_StackFrame_{methodName}({val_new}))");
 }
예제 #16
0
        public override Expression GetValueInLValueState(ResolutionContext context)
        {
            var s = context.GetLValueState();

            return(AH.MakeExprDotName(s, "ghosts", "Armada_Ghosts"));
        }
예제 #17
0
 public override string GetValueInLValueState(ResolutionContext context)
 {
     return($"({context.GetLValueState()}).ghosts");
 }
예제 #18
0
 public override Expression UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                             Expression val_new)
 {
     return(AH.MakeApply3("Armada_UpdateTSFrame", context.GetLValueState(), context.tid, val_new, "Armada_TotalState"));
 }
예제 #19
0
 public override string UpdateTotalStateLocationDirectly(ResolutionContext context, IConstraintCollector constraintCollector,
                                                         string val_new)
 {
     return($"({context.GetLValueState()}).(ghosts := {val_new})");
 }