internal override void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv) { if (Invalid != null || typeEnv.Type.Invalid != null) { return; } var ctxt = MessageContextBuilders.Member(vctxt.Global, typeEnv.Assembly, typeEnv.Type, this); if (Get != null) { Invalid = Get.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { return; } } if (Set != null) { Invalid = Set.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { return; } } Invalid = FieldType.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { vctxt.ImplementableMemberDef(typeEnv.Assembly, typeEnv.Type, this); } }
/// <summary> /// Creates a reference resolver. /// </summary> /// <param name="resolver"> /// The assembly resolver to use. /// </param> /// <param name="typeEnvironment"> /// The reference resolver's type environment. /// </param> public ReferenceResolver( AssemblyResolver resolver, TypeEnvironment typeEnvironment) { this.AssemblyResolver = resolver; this.TypeEnvironment = typeEnvironment; this.assemblyCache = new Dictionary <string, IAssembly>(); this.typeResolvers = new Dictionary <IAssembly, TypeResolver>(); this.cacheLock = new ReaderWriterLockSlim(); this.fieldIndex = new Index <IType, KeyValuePair <string, IType>, IField>( type => type.Fields .Select(field => new KeyValuePair <KeyValuePair <string, IType>, IField>( new KeyValuePair <string, IType>( field.Name.ToString(), field.FieldType), field))); this.methodIndex = new Index <IType, ClrMethodSignature, IMethod>( type => type.Methods .Concat( type.Properties.SelectMany(prop => prop.Accessors)) .Select(method => new KeyValuePair <ClrMethodSignature, IMethod>( ClrMethodSignature.Create(method), method))); this.propertyIndex = new Index <IType, ClrPropertySignature, IProperty>( type => type.Properties.Select(prop => new KeyValuePair <ClrPropertySignature, IProperty>( ClrPropertySignature.Create(prop), prop))); }
internal override void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv) { if (Invalid != null || typeEnv.Type.Invalid != null) { return; } var ctxt = MessageContextBuilders.Member(vctxt.Global, typeEnv.Assembly, typeEnv.Type, this); if (Add != null) { Invalid = Add.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { return; } } if (Remove != null) { Invalid = Remove.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { return; } } Invalid = HandlerType.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) { return; } vctxt.ImplementableMemberDef(typeEnv.Assembly, typeEnv.Type, this); }
/// <summary> /// Compiles an assembly content description to an LLVM module. /// </summary> /// <param name="contents">An assembly content description to compile.</param> /// <param name="typeSystem">A type system to use.</param> /// <param name="mangler">A name mangler to use.</param> /// <returns>An LLVM module builder.</returns> public static ModuleBuilder Compile( AssemblyContentDescription contents, TypeEnvironment typeSystem, NameMangler mangler) { return(Compile(contents, typeSystem, mangler, ClrInternalCallImplementor.Instance)); }
/// <summary> /// Creates a Flame assembly that wraps a Cecil assembly /// definition. /// </summary> /// <param name="definition"> /// The assembly definition to wrap. /// </param> /// <param name="resolver"> /// The assembly resolver to use. /// </param> /// <param name="typeEnvironment"> /// The type environment to use. /// </param> public ClrAssembly( AssemblyDefinition definition, AssemblyResolver resolver, TypeEnvironment typeEnvironment) : this(definition, new ReferenceResolver(resolver, typeEnvironment)) { }
public void AddOrUpdateValue_ShouldThrowExceptionIfInvalidExpressionIsGiven() { var typeEnv = new TypeEnvironment(); var dummyKey = "HelloWorld!"; Expression expression = null; Assert.Throws <ArgumentNullException>(() => typeEnv.AddOrUpdateValue(dummyKey, expression)); }
/// <summary> /// Compiles Flame IR to CIL. /// </summary> /// <returns>A CIL method body.</returns> /// <param name="sourceBody">A Flame IR method body to compile to a CIL method body.</param> /// <param name="method">The method to which the CIL method body can be assigned.</param> /// <param name="typeEnvironment">A type environment.</param> public static Mono.Cecil.Cil.MethodBody Compile( MethodBody sourceBody, Mono.Cecil.MethodDefinition method, TypeEnvironment typeEnvironment) { var instance = new ClrMethodBodyEmitter(method, sourceBody, typeEnvironment); return(instance.Compile()); }
/// <summary> /// Creates a Flame assembly resolver that forwards requests /// to a Mono.Cecil assembly resolver. /// </summary> /// <param name="resolver">The Mono.Cecil assembly resolver to use.</param> /// <param name="typeEnvironment">The Flame type environment to use when analyzing assemblies.</param> /// <param name="parameters">The Mono.Cecil reader parameters to use.</param> public CecilAssemblyResolver( Mono.Cecil.IAssemblyResolver resolver, TypeEnvironment typeEnvironment, Mono.Cecil.ReaderParameters parameters) { this.Resolver = resolver; this.Parameters = parameters; this.ReferenceResolver = new ReferenceResolver(this, typeEnvironment); }
public ClrMethodBodyEmitter( Mono.Cecil.MethodDefinition method, MethodBody sourceBody, TypeEnvironment typeEnvironment) { this.Method = method; this.SourceBody = sourceBody; this.TypeEnvironment = typeEnvironment; }
/// <summary> /// Creates a switch lowering transform. /// </summary> /// <param name="typeEnvironment"> /// The type environment to use. /// </param> /// <param name="allowBitTests"> /// Tells if it is permissible to generate bit tests. /// </param> /// <param name="allowJumpTables"> /// Tells if it is permissible to generate jump tables. /// </param> public SwitchLowering( TypeEnvironment typeEnvironment, bool allowBitTests = true, bool allowJumpTables = true) { this.TypeEnvironment = typeEnvironment; this.AllowBitTests = allowBitTests; this.AllowJumpTables = allowJumpTables; }
public FieldEnvironment Enter(TypeEnvironment typeEnv) { var fieldDef = typeEnv.Type.ResolveField(this); if (fieldDef == null) { throw new InvalidOperationException("unable to resolve field"); } return(typeEnv.AddField(fieldDef)); }
private TypeEnvironment ComputeTypeEnvironment() { var tenv = new TypeEnvironment(); foreach (var t in Types) { RegisterCilType(t, tenv); } return(tenv); }
public void AddOrUpdateValue_ShouldThrowExceptionIfInvalidKeyIsGiven(string keyName) { var typeEnv = new TypeEnvironment(); var dummyValue = new BooleanValue(true); var dummyExpression = new StringLiteral("Hello"); Assert.Throws <ArgumentException>(() => typeEnv.AddOrUpdateValue(keyName, dummyValue)); Assert.Throws <ArgumentException>(() => typeEnv.AddOrUpdateValue(keyName, dummyExpression)); }
public PropertyEnvironment Enter(TypeEnvironment typeEnv) { var propDef = typeEnv.Type.ResolveProperty(this); if (propDef == null) { throw new InvalidOperationException("unable to reslove property"); } return(typeEnv.AddProperty(propDef)); }
public void AddSymbol_ShouldAddSymbolIfCorrectDataIsGiven() { var typeEnv = new TypeEnvironment(); var symbolToAdd = (Name : "HelloWorld", Type : new BooleanValueType()); typeEnv.AddSymbol(symbolToAdd.Name, symbolToAdd.Type); Assert.Equal(symbolToAdd.Type, typeEnv.GetTypeOf(symbolToAdd.Name)); }
public PolymorphicMethodEnvironment Enter(TypeEnvironment typeEnv) { var methodDef = typeEnv.Type.ResolveMethod(this); if (methodDef == null) { throw new InvalidOperationException("unable to resolve method"); } return(typeEnv.AddMethod(methodDef)); }
public EventEnvironment Enter(TypeEnvironment typeEnv) { var eventDef = typeEnv.Type.ResolveEvent(this); if (eventDef == null) { throw new InvalidOperationException("unable to resolve event"); } return(typeEnv.AddEvent(eventDef)); }
public BitTestLowering( SwitchFlow flow, IntegerConstant minValue, IntegerConstant valueRange, TypeEnvironment typeEnvironment) { this.Flow = flow; this.MinValue = minValue; this.ValueRange = valueRange; this.TypeEnvironment = typeEnvironment; }
public SearchTreeLowering( Constant pivot, SwitchFlowLowering leftTree, SwitchFlowLowering rightTree, TypeEnvironment typeEnvironment) { this.pivot = pivot; this.leftTree = leftTree; this.rightTree = rightTree; this.typeEnvironment = typeEnvironment; }
public ActionSet(AST <Node> ast, TermIndex index) { Contract.Requires(index != null && ast != null); Contract.Requires(ast.Node.NodeKind == NodeKind.Rule || ast.Node.NodeKind == NodeKind.ContractItem); //// TODO: Accept contract specifications too. AST = ast; Index = index; myComprData = null; TypeEnvironment = new TypeEnvironment(ast.Node, index); IsCompiled = LiftedBool.Unknown; }
public void Evaluate_ShoudlReturnExpectedValueFromExpression( Expression expression, Type expectedResultType, IValue expected) { var evaluator = new Evaluator(); var environment = new TypeEnvironment(); var result = evaluator.Evaluate(expression, environment); Assert.IsType(expectedResultType, result); Assert.NotNull(result); Assert.Equal(expected, result); }
public void DetectsUndefinedQuestionUse() { string varName = "someVar"; ITypeCheckStmnt stmnt = tcFactory.Label("Test", tcFactory.Variable(varName)); ErrorManager errMngr = new ErrorManager(); TypeEnvironment te = new TypeEnvironment(errMngr); stmnt.TypeCheck(te); Assert.False(te.IsDeclared(varName)); Assert.True(errMngr.HasErrors); }
private static MethodBody GetInitialMethodBody(IMethod method, TypeEnvironment typeSystem) { var body = OnDemandOptimizer.GetInitialMethodBodyDefault(method); if (body == null) { return(null); } // Validate the method body. var errors = body.Validate(); if (errors.Count > 0) { var sourceIr = FormatIr(body); log.Log( new LogEntry( Severity.Warning, "invalid IR", Quotation.QuoteEvenInBold( "the Flame IR produced by the CIL analyzer for ", method.FullName.ToString(), " is erroneous; skipping it."), CreateRemark( "errors in IR:", new BulletedList(errors.Select(x => new Text(x)).ToArray())), CreateRemark( "generated Flame IR:", new Paragraph(new WrapBox(sourceIr, 0, -sourceIr.Length))))); return(null); } // Register some analyses and clean up the CFG before we actually start to optimize it. return(body.WithImplementation( body.Implementation .WithAnalysis( new ConstantAnalysis <SubtypingRules>( typeSystem.Subtyping)) .WithAnalysis( new ConstantAnalysis <PermissiveExceptionDelayability>( PermissiveExceptionDelayability.Instance)) .Transform( AllocaToRegister.Instance, CopyPropagation.Instance, new ConstantPropagation(), CanonicalizeDelegates.Instance, new CanonicalizeArrayInit(typeSystem.Int32), InstructionSimplification.Instance))); }
public void DetectsAssignmentOfInvalidType() { string varName = "someVar"; ITypeCheckStmnt stmnt = tcFactory.Label("Test", tcFactory.VarAssign(varName, tcFactory.RealType(), tcFactory.Bool(true)) ); ErrorManager errMngr = new ErrorManager(); TypeEnvironment te = new TypeEnvironment(errMngr); stmnt.TypeCheck(te); Assert.True(te.IsDeclared(varName)); Assert.True(errMngr.HasErrors); }
public string Emit() { foreach (Instruction i in mInstructions) { mCode.AppendLine(i.ToASM()); } foreach (Declaration d in mDeclarations) { mData.AppendLine(d.Name + ": " + TypeEnvironment.SizeOfType(d.Type)); } string stack = mStack.ToString(); string data = mData.ToString(); string code = mCode.ToString(); return(stack + data + code); }
internal Action( Node head, ConstraintSystem body, TypeEnvironment typeEnv, ComprehensionData comprData = null, Node configurationContext = null) { Head = head; Body = body; myComprData = comprData; this.configurationContext = configurationContext; typeEnvironment = typeEnv; theUnnSymbol = body.Index.SymbolTable.GetOpSymbol(ReservedOpKind.TypeUnn); theRngSymbol = body.Index.SymbolTable.GetOpSymbol(ReservedOpKind.Range); }
/// <summary> /// Method : un ou plusieurs comptes envoyés par D365. /// </summary> /// <param name="dDataIn01">Obtient ou Définit la liste des comptes.</param> /// <returns>Le résultat en rapport des instructions de travail de liaison avec le Business </returns> /// <remarks>Interface 01 - DC-IN02 - COM03</remarks> /// <example></example> public static List <Response> Execute(List <PcmnIn01> dDataIn01, TypeEnvironment dEnvironnement) { var ListResponse = new List <Response>(); foreach (var element in dDataIn01) { ListResponse.Add(new Response { Code = "0", Message = "", ErpOprNumber = Guid.NewGuid(), DynamicsOprNumber = element.DynamicsOprNumber }); } return(ListResponse); }
/// <summary> /// Compiles an assembly content description to an LLVM module. /// </summary> /// <param name="contents">An assembly content description to compile.</param> /// <param name="typeSystem">A type system to use.</param> /// <param name="mangler">A name mangler to use.</param> /// <param name="internalCallImplementor">An internal call implementor to use.</param> /// <returns>An LLVM module builder.</returns> public static ModuleBuilder Compile( AssemblyContentDescription contents, TypeEnvironment typeSystem, NameMangler mangler, InternalCallImplementor internalCallImplementor) { var module = LLVM.ModuleCreateWithName(contents.FullName.FullyUnqualifiedName.ToString()); var builder = new ModuleBuilder( module, typeSystem, mangler, MallocInterface.Instance, new ClosedMetadataFormat(contents.Types, contents.TypeMembers)); var icalls = new Dictionary <IMethod, LLVMValueRef>(); foreach (var method in contents.TypeMembers.OfType <IMethod>()) { var fun = builder.DeclareMethod(method); if (method.IsInternalCall()) { icalls[method] = fun; } } foreach (var pair in contents.MethodBodies) { builder.DefineMethod(pair.Key, pair.Value); icalls.Remove(pair.Key); } foreach (var pair in icalls) { internalCallImplementor.Implement(pair.Key, pair.Value, builder); } if (contents.EntryPoint != null) { // If there is an entry point, then we will synthesize a 'main' function that calls // said entry point. builder.SynthesizeMain(contents.EntryPoint); } return(builder); }
public ModuleBuilder( LLVMModuleRef module, TypeEnvironment typeSystem, NameMangler mangler, GCInterface gc, MetadataFormat metadata) { this.Module = module; this.TypeSystem = typeSystem; this.Mangler = mangler; this.GC = gc; this.Metadata = metadata; this.methodDecls = new Dictionary <IMethod, LLVMValueRef>(); this.fieldDecls = new Dictionary <IField, LLVMValueRef>(); this.importCache = new Dictionary <IType, LLVMTypeRef>(); this.fieldIndices = new Dictionary <IType, Dictionary <IField, int> >(); this.baseIndices = new Dictionary <IType, Dictionary <IType, int> >(); }
/// <summary> /// Creates an Itanium C++ ABI mangler. /// </summary> /// <param name="typeSystem">The type system to use.</param> public ItaniumMangler(TypeEnvironment typeSystem) { builtinTypeNames = new Dictionary <IType, string>() { { typeSystem.Void, "v" }, { typeSystem.Char, "w" }, { typeSystem.Boolean, "b" }, { typeSystem.Int8, "a" }, { typeSystem.UInt8, "h" }, { typeSystem.Int16, "s" }, { typeSystem.UInt16, "t" }, { typeSystem.Int32, "i" }, { typeSystem.UInt32, "j" }, { typeSystem.Int64, "l" }, { typeSystem.UInt64, "m" }, { typeSystem.Float32, "f" }, { typeSystem.Float64, "d" } }; }
public void CyclicDependencyNotPossible() { string varName1 = "var1"; string varName2 = "var2"; ITypeCheckType type1 = tcFactory.RealType(); ITypeCheckType type2 = tcFactory.BoolType(); ITypeCheckStmnt stmnt = tcFactory.Statements( tcFactory.Label("Test", tcFactory.VarAssign(varName1, type1, tcFactory.Variable(varName2))), tcFactory.Label("Test", tcFactory.VarAssign(varName2, type2, tcFactory.Variable(varName1))) ); ErrorManager errMngr = new ErrorManager(); TypeEnvironment te = new TypeEnvironment(errMngr); stmnt.TypeCheck(te); Assert.True(te.IsDeclared(varName1)); Assert.True(te.IsDeclared(varName2)); Assert.True(errMngr.HasErrors); }
public void DuplicateLabelsWarning() { string varName = "someVar"; ITypeCheckType varType = tcFactory.IntType(); ITypeCheckStmnt stmnt = tcFactory.Statements( tcFactory.Question("Test", tcFactory.VarDecl(varName, varType)), tcFactory.Question("Test", tcFactory.VarDecl(varName, varType)) ); ErrorManager errMngr = new ErrorManager(); TypeEnvironment te = new TypeEnvironment(errMngr); stmnt.TypeCheck(te); Assert.True(te.IsDeclared(varName)); Assert.True(errMngr.HasWarnings); Assert.False(errMngr.HasErrors); }
public void DetectsRedefinedQuestions() { string varName = "someVar"; ITypeCheckType type1 = tcFactory.RealType(); ITypeCheckType type2 = tcFactory.BoolType(); ITypeCheckStmnt stmnt = tcFactory.Statements( tcFactory.Question("Test", tcFactory.VarDecl(varName, type1)), tcFactory.Question("Test", tcFactory.VarDecl(varName, type2)) ); ErrorManager errMngr = new ErrorManager(); TypeEnvironment te = new TypeEnvironment(errMngr); stmnt.TypeCheck(te); Assert.True(te.IsDeclared(varName)); Assert.True(errMngr.HasErrors); }
internal override void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv) { if (Invalid != null || typeEnv.Type.Invalid != null) return; var ctxt = MessageContextBuilders.Member(vctxt.Global, typeEnv.Assembly, typeEnv.Type, this); if (Add != null) { Invalid = Add.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) return; } if (Remove != null) { Invalid = Remove.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) return; } Invalid = HandlerType.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) return; vctxt.ImplementableMemberDef(typeEnv.Assembly, typeEnv.Type, this); }
internal override void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv) { if (Invalid != null || typeEnv.Type.Invalid != null) return; var methEnv = typeEnv.AddMethod(this).AddSelfMethodBoundArguments(); for (var i = 0; i < TypeParameters.Count; i++) { TypeParameters[i].CheckValid(vctxt, methEnv); if (TypeParameters[i].Invalid != null) { Invalid = new InvalidInfo (MessageContextBuilders.TypeArg(ParameterFlavor.Method, i), TypeParameters[i].Invalid); return; } } var ctxt = MessageContextBuilders.Member(vctxt.Global, typeEnv.Assembly, typeEnv.Type, this); foreach (var p in ValueParameters) { Invalid = p.Type.CheckValid(vctxt, ctxt, methEnv); if (Invalid != null) return; } if (Result != null) { Invalid = Result.Type.CheckValid(vctxt, ctxt, methEnv); if (Invalid != null) return; } if (vctxt.IgnoreMethodDefBody(typeEnv.Assembly, typeEnv.Type, this)) return; foreach (var l in Locals) { Invalid = l.Type.CheckValid(vctxt, ctxt, methEnv); if (Invalid != null) return; } var instructions = Instructions(vctxt.Global); if (instructions != null) { foreach (var i in instructions.Body) { Invalid = i.CheckValid(vctxt, ctxt, methEnv); if (Invalid != null) return; Invalid = vctxt.ImplementableInstruction(ctxt, methEnv.Assembly, methEnv.Type, this, i); if (Invalid != null) return; } } vctxt.ImplementableMemberDef(typeEnv.Assembly, typeEnv.Type, this); }
internal abstract void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv);
internal override void CheckValid(ValidityContext vctxt, TypeEnvironment typeEnv) { if (Invalid != null || typeEnv.Type.Invalid != null) return; var ctxt = MessageContextBuilders.Member(vctxt.Global, typeEnv.Assembly, typeEnv.Type, this); if (Get != null) { Invalid = Get.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) return; } if (Set != null) { Invalid = Set.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) return; } Invalid = FieldType.CheckValid(vctxt, ctxt, typeEnv); if (Invalid != null) vctxt.ImplementableMemberDef(typeEnv.Assembly, typeEnv.Type, this); }