public void Hdrgen_rekodoth()
        {
            var hdrgen = new HeaderGenerator(typeof(Address).Assembly, sw);

            hdrgen.Execute();
            Debug.WriteLine(sw);
        }
        public void Hdrgen_Guid()
        {
            var sExp =
                #region Expected
                @"// {12506D0F-1C67-4828-9601-96F8ED4D162D}
DEFINE_GUID(IID_INativeRewriter, 0x12506D0F,0x1C67,0x4828,0x96,0x01,0x96,0xF8,0xED,0x4D,0x16,0x2D);
";

            #endregion
            var hdrgen = new HeaderGenerator(typeof(Address).Assembly, sw);
            hdrgen.WriteGuidDefinition("INativeRewriter", "12506D0F-1C67-4828-9601-96F8ED4D162D");
            Debug.Print(sw.ToString());
            Assert.AreEqual(sExp, sw.ToString());
        }
        public void Hdrgen_OutParameter()
        {
            var hdrgen = new HeaderGenerator(typeof(Address).Assembly, sw);
            var method = typeof(INativeArchitecture).GetMethod("GetAllRegisters");

            hdrgen.WriteInterfaceMethod(method);
            var sExp =
                #region Expected
                @"    virtual HRESULT STDAPICALLTYPE GetAllRegisters(int32_t registerType, int32_t* n, void ** aregs) = 0;
";

            #endregion
            Assert.AreEqual(sExp, sw.ToString());
        }
        public void Hdrgen_Interface()
        {
            var hdrgen = new HeaderGenerator(typeof(Address).Assembly, sw);

            hdrgen.WriteInterfaceDefinition(typeof(INativeRewriter));
            var sExp =
                #region Expected
                @"// {12506D0F-1C67-4828-9601-96F8ED4D162D}
DEFINE_GUID(IID_INativeRewriter, 0x12506D0F,0x1C67,0x4828,0x96,0x01,0x96,0xF8,0xED,0x4D,0x16,0x2D);
class INativeRewriter : public IUnknown
{
public:
    virtual int32_t STDAPICALLTYPE Next() = 0;
    virtual int32_t STDAPICALLTYPE GetCount() = 0;
};
";

            #endregion
            Debug.Print(sw.ToString());
            Assert.AreEqual(sExp, sw.ToString());
        }
        public void Hdrgen_Enum()
        {
            var hdrgen = new HeaderGenerator(typeof(Address).Assembly, sw);

            hdrgen.WriteEnumDefinition(typeof(Reko.Core.AccessMode));
            var sExp =
                #region Expected
                @"enum class AccessMode
{
    Execute = 1,
    Write = 2,
    Read = 4,
    ReadExecute = 5,
    ReadWrite = 6,
    ReadWriteExecute = 7,
};
";

            #endregion
            Assert.AreEqual(sExp, sw.ToString());
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.WriteLine("usage: hdrgen <.NET assembly file name> [output file name]");
                return;
            }
            var assemblyName = args[0];
            var asm          = typeof(NativeInteropAttribute).Assembly;

            if (args.Length == 1)
            {
                var hdrgen = new HeaderGenerator(asm, System.Console.Out);
                hdrgen.Execute();
            }
            else
            {
                TextWriter w = null;
                try
                {
                    w = File.CreateText(args[1]);
                    var hdrgen = new HeaderGenerator(asm, w);
                    hdrgen.Execute();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"hdrgen: an error occurred while generating headers. {ex.Message}");
                }
                finally
                {
                    if (w != null)
                    {
                        w.Dispose();
                    }
                }
            }
        }