Пример #1
0
 public void Append(CSTWriter w)
 {
     foreach (var customAttribute in CustomAttributes)
     {
         customAttribute.Append(w);
         w.EndLine();
     }
     w.Append("assembly ");
     Name.Append(w);
     w.Append(" {");
     w.EndLine();
     w.Indented(w2 => {
         foreach (var sn in References)
         {
             w2.Append(".reference ");
             sn.Append(w2);
             w2.EndLine();
         }
         if (EntryPoint != null)
         {
             w2.Append(".entry ");
             EntryPoint.Append(w2);
             w2.EndLine();
         }
         foreach (var namedTypeDef in Types)
         {
             namedTypeDef.AppendDefinition(w2);
             w2.EndLine();
         }
     });
     w.Append('}');
 }
Пример #2
0
 public void Append(CSTWriter w)
 {
     w.Append('[');
     Type.Append(w);
     w.Append('(');
     var first = true;
     foreach (var o in PositionalProperties)
     {
         if (first)
             first = false;
         else
             w.Append(',');
         w.AppendQuotedObject(o);
     }
     foreach (var kv in NamedProperties)
     {
         if (first)
             first = false;
         else
             w.Append(',');
         w.Append(kv.Key);
         w.Append('=');
         w.AppendQuotedObject(kv.Value);
     }
     w.Append(")]");
 }
Пример #3
0
 public SimplifierContext
     (CompilationEnvironment compEnv,
      JST.NameSupply nameSupply,
      ISimplifierDatabase database,
      CSTWriter trace)
 {
     CompEnv = compEnv;
     NameSupply = nameSupply;
     subst = new Map<JST.Identifier, Expression>();
     statements = null;
     contextEffects = JST.Effects.Bottom;
     Database = database;
     Trace = trace;
 }
Пример #4
0
 protected SimplifierContext
     (CompilationEnvironment compEnv,
      JST.NameSupply nameSupply,
      Map<JST.Identifier, Expression> subst,
      Seq<Statement> statements,
      JST.Effects contextEffects,
      ISimplifierDatabase database,
      CSTWriter trace)
 {
     CompEnv = compEnv;
     NameSupply = nameSupply;
     this.subst = subst;
     this.statements = statements;
     this.contextEffects = contextEffects;
     Database = database;
     Trace = trace;
 }
Пример #5
0
        public static CSTMethod Translate(MethodEnvironment methEnv, JST.NameSupply nameSupply, CSTWriter trace)
        {
            // Infer machine states for each control point
            var machineStateInference = new MachineStateInference(methEnv, trace);
            machineStateInference.Infer();

            if (trace != null)
                trace.Trace
                    ("After machine state inference",
                     w =>
                         {
                             methEnv.Method.AppendDefinition(w);
                             w.EndLine();
                         });

            // Translate to basic-blocks which use structural control flow where possible
            var controlFlowRecovery = new ControlFlowRecovery(methEnv, nameSupply.GenSym, -1, trace);
            var root = controlFlowRecovery.Root();

            if (trace != null)
                trace.Trace
                    ("After control flow recovery",
                     w =>
                         {
                             root.AppendAll(w);
                             w.EndLine();
                         });

            var initState = root.Targets[0].Block.BeforeState;
            var compEnv = methEnv.AddVariables(nameSupply, i => initState.ArgLocalIsAlive(ArgLocal.Local, i));

            // Translate to intermediate statements/expressions/cells language
            var translator = new Translator
                (compEnv, nameSupply, controlFlowRecovery.NextInstructionId, trace);
            var body = translator.Translate(root);

            var res = new CSTMethod(compEnv, body);

            if (trace != null)
                trace.Trace("After translation to intermediate representation", res.Append);

            return res;
        }
Пример #6
0
 public void Append(CSTWriter w)
 {
     w.Append("method ");
     w.Append(CompEnv.Method.Name);
     w.Append('(');
     for (var i = 0; i < CompEnv.ValueParameterIds.Count; i++)
     {
         if (i > 0)
             w.Append(", ");
         CompEnv.ValueParameterIds[i].Append(w);
         w.Append(':');
         CompEnv.Method.ValueParameters[i].Type.Append(w);
     }
     w.Append("){");
     w.EndLine();
     w.Indented
         (w2 =>
              {
                  foreach (var kv in CompEnv.Variables)
                  {
                      if (kv.Value.ArgLocal == ArgLocal.Local)
                      {
                          w2.Append("var ");
                          kv.Value.Id.Append(w2);
                          w2.Append(':');
                          kv.Value.Type.Append(w2);
                          if (kv.Value.IsInit)
                              w2.Append("=default");
                          w2.Append(';');
                          w2.EndLine();
                      }
                  }
                  Body.Append(w2);
              });
     w.Append('}');
     w.EndLine();
 }
Пример #7
0
 public override void AppendModifiers(CSTWriter w)
 {
     switch (CodeFlavor)
     {
     case MethodCodeFlavor.Managed:
         break;
     case MethodCodeFlavor.ManagedExtern:
         w.Append("extern ");
         break;
     case MethodCodeFlavor.Native:
         w.Append("native ");
         break;
     case MethodCodeFlavor.Runtime:
         w.Append("runtime ");
         break;
     case MethodCodeFlavor.ForwardRef:
         w.Append("forwardref ");
         break;
     default:
         throw new ArgumentOutOfRangeException();
     }
     if (HasNewSlot)
         w.Append("newslot ");
     if (IsSyncronized)
         w.Append("syncronized ");
     if (NoInlining)
         w.Append("noinline ");
     if (IsInitLocals)
         w.Append("initlocals ");
     switch (MethodStyle)
     {
         case MethodStyle.Normal:
         case MethodStyle.Constructor:
             break;
         case MethodStyle.Virtual:
             w.Append("virtual ");
             break;
         case MethodStyle.Abstract:
             w.Append("abstract ");
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Пример #8
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     w.Append(':');
     FieldType.Append(w);
     if (Init != null)
     {
         w.Append('=');
         Init.Append(w);
     }
 }
Пример #9
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     if (TypeParameters.Count > 0)
     {
         w.Append('<');
         for (var i = 0; i < TypeParameters.Count; i++)
         {
             if (i > 0)
                 w.Append(',');
             w.Append("!!");
             w.Append(TypeParameters[i].Index);
         }
         w.Append('>');
     }
     w.Append('(');
     for (var i = 0; i < ValueParameters.Count; i++)
     {
         if (i > 0)
             w.Append(',');
         ValueParameters[i].Type.Append(w);
     }
     w.Append(')');
     if (Result != null)
     {
         w.Append(':');
         Result.Append(w);
     }
     var instructions = Instructions(w.Global);
     if (instructions != null)
     {
         w.Append(" {");
         w.EndLine();
         w.Indented
             (w2 =>
                  {
                      for (var i = 0; i < Locals.Count; i++)
                      {
                          w2.Append(".local ");
                          w2.Append(i);
                          w2.Append(':');
                          Locals[i].Type.Append(w2);
                          w2.EndLine();
                      }
                      instructions.Append(w2);
                  });
         w.Append('}');
     }
 }
Пример #10
0
 public override void AppendFlavor(CSTWriter w)
 {
     w.Append("method ");
 }
Пример #11
0
 public abstract void AppendModifiers(CSTWriter w);
Пример #12
0
 public void Append(CSTWriter w)
 {
     Type.Append(w);
 }
Пример #13
0
 public override void AppendFlavor(CSTWriter w)
 {
     w.Append("event ");
 }
Пример #14
0
 public MachineStateInference(MethodEnvironment methEnv, CSTWriter tracer)
 {
     this.methEnv = methEnv;
     global = methEnv.Global;
     method = methEnv.Method;
     this.tracer = tracer;
     offsetToBeforeState = new Map<int, MachineState>();
     offsetToAfterState = new Map<int, MachineState>();
 }
Пример #15
0
 public abstract void Append(CSTWriter w);
Пример #16
0
 public override void Append(CSTWriter w)
 {
     w.Append('[');
     for (var i = 0; i < Data.Length; i++)
     {
         if (i > 0)
             w.Append(',');
         w.Append(Data[i]);
     }
     w.Append(']');
 }
Пример #17
0
 public override void AppendFlavor(CSTWriter w)
 {
     w.Append("field ");
 }
Пример #18
0
 public ValidityContext(Global global, Log log, CSTWriter tracer)
 {
     Global = global;
     Log = log;
     this.tracer = tracer;
 }
Пример #19
0
        public ControlFlowRecovery(MethodEnvironment methEnv, Func<JST.Identifier> gensym, int nextInstructionId, CSTWriter tracer)
        {
            this.methEnv = methEnv;
            method = methEnv.Method;
            this.gensym = gensym;
            this.tracer = tracer;

            targets = new Set<int>();
            nextBlockId = 0;
            NextInstructionId = nextInstructionId;
        }
Пример #20
0
 public void Append(CSTWriter w)
 {
     Type.Append(w);
     if (UpperBound != null)
     {
         w.Append("<:");
         UpperBound.Append(w);
     }
 }
Пример #21
0
 public void Append(CSTWriter w)
 {
     // Print from bottom to top to match argument order
     w.Append("{[");
     for (var i = Depth - 1; i >= 0; i--)
     {
         if (i < Depth - 1)
             w.Append(',');
         if (innerState.Value.Ids != null)
         {
             w.AppendName(innerState.Value.Ids[i].Value);
             w.Append(':');
         }
         innerState.Value.Stack[i].Append(w);
     }
     w.Append(']');
     if (!innerState.Value.ArgsLocalsState.IsBottom)
     {
         w.Append(' ');
         innerState.Value.ArgsLocalsState.Append(w);
     }
     w.Append('}');
 }
Пример #22
0
 public override void AppendModifiers(CSTWriter w)
 {
 }
Пример #23
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     w.Append(':');
     FieldType.Append(w);
     w.Append(" {");
     if (Get != null)
     {
         w.Append(" get { ");
         Get.Append(w);
         w.Append(" }");
     }
     if (Set != null)
     {
         w.Append(" set { ");
         Set.Append(w);
         w.Append(" }");
     }
     w.Append(" }");
 }
Пример #24
0
 public override void Append(CSTWriter w)
 {
     w.AppendQuotedObject(Value);
 }
Пример #25
0
 public override void AppendFlavor(CSTWriter w)
 {
     w.Append("property ");
 }
Пример #26
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     w.Append(':');
     HandlerType.Append(w);
     w.Append(" {");
     if (Add != null)
     {
         w.Append(" add { ");
         Add.Append(w);
         w.Append(" }");
     }
     if (Remove != null)
     {
         w.Append(" remove {");
         Remove.Append(w);
         w.Append(" }");
     }
     w.Append(" }");
 }
Пример #27
0
        //
        // Pretty printing
        //

        public virtual void AppendDefinition(CSTWriter w)
        {
            foreach (var annotation in CustomAttributes)
            {
                annotation.Append(w);
                w.EndLine();
            }
            AppendFlavor(w);
            w.Append(IsStatic ? "static " : "instance ");
            AppendModifiers(w);
            w.AppendName(Name);
        }
Пример #28
0
 public abstract void AppendFlavor(CSTWriter w);
Пример #29
0
 public void Append(CSTWriter w)
 {
     w.Append("{source=");
     Source.Append(w);
     w.Append(",target=L");
     w.Append(Target.ToString("x"));
     w.Append(",reason=\"");
     w.Append(Reason);
     w.Append("\"}");
 }