Microsoft Developer Network > Página principal de foros > Phoenix > Process Command-Line options for a phoenix plugin
Formular una preguntaFormular una pregunta
 

PreguntaProcess Command-Line options for a phoenix plugin

  • miércoles, 14 de octubre de 2009 6:17sagarj Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi,
    I want my phoenix plugin to take an argument say '-func:main' in the command line and would then like to run my plugin for that function only.
    For above example, what should be the input command line and how should I process this flag in my plugin code. Please note that I am working with Pass.

    Thanks,
    Sagar

Todas las respuestas

  • domingo, 18 de octubre de 2009 7:01Andy Ayers - MSFTModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código

    Here's one way to do it (I'll just show an example with a plugin with a phase, but it should work the same for a plugin with a pass and a phase).

    First, make sure your phase is set as off by default. This means you'll need to explicitly enable the phase via the command line. Then set up your phase to have a PhaseControl, control so we can do just that:

    public class MyPhase : Phx.Phases.Phase
    {
       static public Phx.Controls.ComponentControl DebugControl;
    
       public MyPhase(Phx.Phases.PhaseConfiguration config)
       {
          this.Initialize(config, "my phase");
          this.PhaseControl = MyPhase.DebugControl;
          this.IsOnByDefault = false;
       }
    
       protected override void
       Execute
       (
          Phx.Unit unit
       )
       {
          Phx.Output.WriteLine("Alive and well in {0}", unit);
       }
    }
    
    Next, have your plugin create the component control for the Phase in the RegisterObjects method, and add the phase into the phase list.

    public class MyPlugIn : Phx.PlugIn
    {
       public override void
       RegisterObjects()
       {
          MyPhase.DebugControl = Phx.Controls.ComponentControl.New("func",
             "Enble my phase for a given function",
             "myplugin.cs");
       }
    
       public override void
       BuildPhases
       (
          Phx.Phases.PhaseConfiguration config
       )
       {
          MyPhase myPhase = new MyPhase(config);
          Phx.Phases.Phase encodingPhase = config.PhaseList.FindByName("Encoding");
          encodingPhase.InsertAfter(myPhase);      
       }
    
       public override System.String NameString
       {
          get
          {
             return "MyPlugin";
          }
       }
    
    }<br/>
    

    Now, build your plugin (mine is called "sample.dll"), and run it on the command line as follows:

    C:\home>cl -nologo -c hello.cpp -d2plugin:sample.dll
    hello.cpp
    Nothing happens, as expected.

    To enable your phase you need to set the command line so the component control is activated. The control's name is func, and when this appears as an command-line option to Phoenix, the control is activated. A component control can accept a variety of prefixes called component modifiers describing the type of activation. One of these is on which overrides the IsOnByDefault setting on the phase, and turns the phase on. The control also accepts a suffix which indicates which set of functions the override should apply to. To specify a function name, add :# and then the name of the function. So to enable MyPhase for main, we need to pass -onfunc:#main as a command line argument. There's one last wrinkle. When running as a "subprocess" under cl.exe, you need to use a special prefix to tunnel Phoenix command line arguments through the driver. So the full command line syntax is actually -d2onfunc:#main (likewise, to tunnel through to c2 via the linker, the syntax would be -d2:-onfunc:#main. All this tunneling can be avoided by just setting the PHX environment variable to the plain old -onfunc:#main instead).
    C:\home>cl -nologo -c hello.cpp -d2plugin:sample.dll -d2onfunc:#main
    hello.cpp
    Alive and well in _main (State: IsLaidOut IsPostFrameGenerated IsPostRegisterAllocated Lir)
    Note that the :# suffix actually does a substring match, so a function named "main2" would also be processed by the phase.


    Architect - Microsoft Phoenix Project