Browse Source

Merge pull request #338 from ddobrev/master

Exposed the architecture of native libraries
pull/340/head
João Matos 11 years ago
parent
commit
76dd32e8be
  1. 10
      src/AST/SymbolContext.cs
  2. 7
      src/Core/Parser/Parser.cs
  3. 5
      src/CppParser/AST.cpp
  4. 12
      src/CppParser/AST.h
  5. 20
      src/CppParser/Bindings/CLI/AST.cpp
  6. 14
      src/CppParser/Bindings/CLI/AST.h
  7. 35
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  8. 37
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  9. 43
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  10. 17
      src/CppParser/Parser.cpp

10
src/AST/SymbolContext.cs

@ -2,6 +2,14 @@
namespace CppSharp.AST namespace CppSharp.AST
{ {
public enum ArchType
{
UnknownArch,
x86, // X86: i[3-9]86
x86_64 // X86-64: amd64, x86_64
}
/// <summary> /// <summary>
/// Represents a shared library or a static library archive. /// Represents a shared library or a static library archive.
/// </summary> /// </summary>
@ -24,6 +32,8 @@ namespace CppSharp.AST
/// </summary> /// </summary>
public string FileName; public string FileName;
public ArchType ArchType { get; set; }
/// <summary> /// <summary>
/// Symbols gathered from the library. /// Symbols gathered from the library.
/// </summary> /// </summary>

7
src/Core/Parser/Parser.cs

@ -1,4 +1,5 @@
using System; using System;
using CppSharp.AST;
using CppSharp.Parser; using CppSharp.Parser;
using ASTContext = CppSharp.Parser.AST.ASTContext; using ASTContext = CppSharp.Parser.AST.ASTContext;
using NativeLibrary = CppSharp.Parser.AST.NativeLibrary; using NativeLibrary = CppSharp.Parser.AST.NativeLibrary;
@ -95,7 +96,11 @@ namespace CppSharp
public static AST.NativeLibrary ConvertLibrary(NativeLibrary library) public static AST.NativeLibrary ConvertLibrary(NativeLibrary library)
{ {
var newLibrary = new AST.NativeLibrary { FileName = library.FileName }; var newLibrary = new AST.NativeLibrary
{
FileName = library.FileName,
ArchType = (ArchType) library.ArchType
};
for (uint i = 0; i < library.SymbolsCount; ++i) for (uint i = 0; i < library.SymbolsCount; ++i)
{ {

5
src/CppParser/AST.cpp

@ -578,6 +578,11 @@ TranslationUnit::TranslationUnit() { Kind = DeclarationKind::TranslationUnit; }
DEF_STRING(TranslationUnit, FileName) DEF_STRING(TranslationUnit, FileName)
DEF_VECTOR(TranslationUnit, MacroDefinition*, Macros) DEF_VECTOR(TranslationUnit, MacroDefinition*, Macros)
NativeLibrary::NativeLibrary()
: ArchType(ArchType::UnknownArch)
{
}
// NativeLibrary // NativeLibrary
DEF_STRING(NativeLibrary, FileName) DEF_STRING(NativeLibrary, FileName)
DEF_VECTOR_STRING(NativeLibrary, Symbols) DEF_VECTOR_STRING(NativeLibrary, Symbols)

12
src/CppParser/AST.h

@ -796,9 +796,19 @@ public:
VECTOR(MacroDefinition*, Macros) VECTOR(MacroDefinition*, Macros)
}; };
struct CS_API NativeLibrary enum class ArchType
{ {
UnknownArch,
x86,
x86_64
};
class CS_API NativeLibrary
{
public:
NativeLibrary();
STRING(FileName) STRING(FileName)
ArchType ArchType;
VECTOR_STRING(Symbols) VECTOR_STRING(Symbols)
VECTOR_STRING(Dependencies) VECTOR_STRING(Dependencies)
}; };

20
src/CppParser/Bindings/CLI/AST.cpp

@ -2940,6 +2940,11 @@ CppSharp::Parser::AST::NativeLibrary::NativeLibrary(System::IntPtr native)
NativePtr = __native; NativePtr = __native;
} }
CppSharp::Parser::AST::NativeLibrary::NativeLibrary()
{
NativePtr = new ::CppSharp::CppParser::AST::NativeLibrary();
}
System::String^ CppSharp::Parser::AST::NativeLibrary::getSymbols(unsigned int i) System::String^ CppSharp::Parser::AST::NativeLibrary::getSymbols(unsigned int i)
{ {
auto __ret = ((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->getSymbols(i); auto __ret = ((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->getSymbols(i);
@ -2978,11 +2983,6 @@ void CppSharp::Parser::AST::NativeLibrary::clearDependencies()
((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->clearDependencies(); ((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->clearDependencies();
} }
CppSharp::Parser::AST::NativeLibrary::NativeLibrary()
{
NativePtr = new ::CppSharp::CppParser::AST::NativeLibrary();
}
System::IntPtr CppSharp::Parser::AST::NativeLibrary::__Instance::get() System::IntPtr CppSharp::Parser::AST::NativeLibrary::__Instance::get()
{ {
return System::IntPtr(NativePtr); return System::IntPtr(NativePtr);
@ -3019,6 +3019,16 @@ unsigned int CppSharp::Parser::AST::NativeLibrary::DependenciesCount::get()
return __ret; return __ret;
} }
CppSharp::Parser::AST::ArchType CppSharp::Parser::AST::NativeLibrary::ArchType::get()
{
return (CppSharp::Parser::AST::ArchType)((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->ArchType;
}
void CppSharp::Parser::AST::NativeLibrary::ArchType::set(CppSharp::Parser::AST::ArchType value)
{
((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->ArchType = (::CppSharp::CppParser::AST::ArchType)value;
}
CppSharp::Parser::AST::ASTContext::ASTContext(::CppSharp::CppParser::AST::ASTContext* native) CppSharp::Parser::AST::ASTContext::ASTContext(::CppSharp::CppParser::AST::ASTContext* native)
{ {
NativePtr = native; NativePtr = native;

14
src/CppParser/Bindings/CLI/AST.h

@ -11,6 +11,7 @@ namespace CppSharp
namespace AST namespace AST
{ {
enum struct AccessSpecifier; enum struct AccessSpecifier;
enum struct ArchType;
enum struct CXXMethodKind; enum struct CXXMethodKind;
enum struct CXXOperatorKind; enum struct CXXOperatorKind;
enum struct CallingConvention; enum struct CallingConvention;
@ -292,6 +293,13 @@ namespace CppSharp
FunctionBody = 5 FunctionBody = 5
}; };
public enum struct ArchType
{
UnknownArch = 0,
x86 = 1,
x86_64 = 2
};
public ref class Type : ICppInstance public ref class Type : ICppInstance
{ {
public: public:
@ -1963,6 +1971,12 @@ namespace CppSharp
unsigned int get(); unsigned int get();
} }
property CppSharp::Parser::AST::ArchType ArchType
{
CppSharp::Parser::AST::ArchType get();
void set(CppSharp::Parser::AST::ArchType);
}
System::String^ getSymbols(unsigned int i); System::String^ getSymbols(unsigned int i);
void addSymbols(System::String^ s); void addSymbols(System::String^ s);

35
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -216,6 +216,13 @@ namespace CppSharp
FunctionBody = 5 FunctionBody = 5
} }
public enum ArchType
{
UnknownArch = 0,
x86 = 1,
x86_64 = 2
}
public unsafe partial class Type : IDisposable public unsafe partial class Type : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 8)] [StructLayout(LayoutKind.Explicit, Size = 8)]
@ -7562,13 +7569,16 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable public unsafe partial class NativeLibrary : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 36)] [StructLayout(LayoutKind.Explicit, Size = 40)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(12)]
public CppSharp.Parser.AST.ArchType ArchType;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2Ev")]
internal static extern void ctor_1(global::System.IntPtr instance); internal static extern void ctor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -7640,7 +7650,7 @@ namespace CppSharp
private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native) private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native)
{ {
var ret = Marshal.AllocHGlobal(36); var ret = Marshal.AllocHGlobal(40);
CppSharp.Parser.AST.NativeLibrary.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.NativeLibrary.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return ret; return ret;
} }
@ -7657,8 +7667,8 @@ namespace CppSharp
public NativeLibrary() public NativeLibrary()
{ {
__Instance = Marshal.AllocHGlobal(36); __Instance = Marshal.AllocHGlobal(40);
Internal.ctor_1(__Instance); Internal.ctor_0(__Instance);
} }
public void Dispose() public void Dispose()
@ -7745,6 +7755,21 @@ namespace CppSharp
return __ret; return __ret;
} }
} }
public CppSharp.Parser.AST.ArchType ArchType
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return __ptr->ArchType;
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->ArchType = value;
}
}
} }
public unsafe partial class ASTContext : IDisposable public unsafe partial class ASTContext : IDisposable

37
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

@ -216,6 +216,13 @@ namespace CppSharp
FunctionBody = 5 FunctionBody = 5
} }
public enum ArchType
{
UnknownArch = 0,
x86 = 1,
x86_64 = 2
}
public unsafe partial class Type : IDisposable public unsafe partial class Type : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 8)] [StructLayout(LayoutKind.Explicit, Size = 8)]
@ -7562,17 +7569,20 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable public unsafe partial class NativeLibrary : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 48)] [StructLayout(LayoutKind.Explicit, Size = 52)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(24)]
public CppSharp.Parser.AST.ArchType ArchType;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0NativeLibrary@AST@CppParser@CppSharp@@QAE@XZ")] EntryPoint="??0NativeLibrary@AST@CppParser@CppSharp@@QAE@XZ")]
internal static extern global::System.IntPtr ctor_1(global::System.IntPtr instance); internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="??0NativeLibrary@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")] EntryPoint="??0NativeLibrary@AST@CppParser@CppSharp@@QAE@ABV0123@@Z")]
internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0); internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
@ -7640,7 +7650,7 @@ namespace CppSharp
private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native) private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native)
{ {
var ret = Marshal.AllocHGlobal(48); var ret = Marshal.AllocHGlobal(52);
CppSharp.Parser.AST.NativeLibrary.Internal.cctor_2(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.NativeLibrary.Internal.cctor_2(ret, new global::System.IntPtr(&native));
return ret; return ret;
} }
@ -7657,8 +7667,8 @@ namespace CppSharp
public NativeLibrary() public NativeLibrary()
{ {
__Instance = Marshal.AllocHGlobal(48); __Instance = Marshal.AllocHGlobal(52);
Internal.ctor_1(__Instance); Internal.ctor_0(__Instance);
} }
public void Dispose() public void Dispose()
@ -7745,6 +7755,21 @@ namespace CppSharp
return __ret; return __ret;
} }
} }
public CppSharp.Parser.AST.ArchType ArchType
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return __ptr->ArchType;
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->ArchType = value;
}
}
} }
public unsafe partial class ASTContext : IDisposable public unsafe partial class ASTContext : IDisposable

43
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

@ -216,6 +216,13 @@ namespace CppSharp
FunctionBody = 5 FunctionBody = 5
} }
public enum ArchType
{
UnknownArch = 0,
x86 = 1,
x86_64 = 2
}
public unsafe partial class Type : IDisposable public unsafe partial class Type : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 8)] [StructLayout(LayoutKind.Explicit, Size = 8)]
@ -7561,18 +7568,21 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable public unsafe partial class NativeLibrary : IDisposable
{ {
[StructLayout(LayoutKind.Explicit, Size = 56)] [StructLayout(LayoutKind.Explicit, Size = 64)]
public partial struct Internal public partial struct Internal
{ {
[FieldOffset(8)]
public CppSharp.Parser.AST.ArchType ArchType;
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2ERKS2_")] EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2Ev")]
internal static extern void cctor_0(global::System.IntPtr instance, global::System.IntPtr _0); internal static extern void ctor_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2Ev")] EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibraryC2ERKS2_")]
internal static extern void ctor_2(global::System.IntPtr instance); internal static extern void cctor_1(global::System.IntPtr instance, global::System.IntPtr _0);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl, [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
@ -7639,8 +7649,8 @@ namespace CppSharp
private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native) private static global::System.IntPtr __CopyValue(NativeLibrary.Internal native)
{ {
var ret = Marshal.AllocHGlobal(56); var ret = Marshal.AllocHGlobal(64);
CppSharp.Parser.AST.NativeLibrary.Internal.cctor_0(ret, new global::System.IntPtr(&native)); CppSharp.Parser.AST.NativeLibrary.Internal.cctor_1(ret, new global::System.IntPtr(&native));
return ret; return ret;
} }
@ -7656,8 +7666,8 @@ namespace CppSharp
public NativeLibrary() public NativeLibrary()
{ {
__Instance = Marshal.AllocHGlobal(56); __Instance = Marshal.AllocHGlobal(64);
Internal.ctor_2(__Instance); Internal.ctor_0(__Instance);
} }
public void Dispose() public void Dispose()
@ -7744,6 +7754,21 @@ namespace CppSharp
return __ret; return __ret;
} }
} }
public CppSharp.Parser.AST.ArchType ArchType
{
get
{
var __ptr = (Internal*)__Instance.ToPointer();
return __ptr->ArchType;
}
set
{
var __ptr = (Internal*)__Instance.ToPointer();
__ptr->ArchType = value;
}
}
} }
public unsafe partial class ASTContext : IDisposable public unsafe partial class ASTContext : IDisposable

17
src/CppParser/Parser.cpp

@ -3043,8 +3043,20 @@ ParserResultKind Parser::ParseArchive(llvm::StringRef File,
return ParserResultKind::Success; return ParserResultKind::Success;
} }
static ArchType ConvertArchType(unsigned int archType)
{
switch (archType)
{
case llvm::Triple::ArchType::x86:
return ArchType::x86;
case llvm::Triple::ArchType::x86_64:
return ArchType::x86_64;
}
return ArchType::UnknownArch;
}
template<class ELFT> template<class ELFT>
void ReadELFDependencies(const llvm::object::ELFFile<ELFT>* ELFFile, CppSharp::CppParser::NativeLibrary*& NativeLib) static void ReadELFDependencies(const llvm::object::ELFFile<ELFT>* ELFFile, CppSharp::CppParser::NativeLibrary*& NativeLib)
{ {
for (const auto &Entry : ELFFile->dynamic_table()) for (const auto &Entry : ELFFile->dynamic_table())
if (Entry.d_tag == llvm::ELF::DT_NEEDED) if (Entry.d_tag == llvm::ELF::DT_NEEDED)
@ -3058,6 +3070,7 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File,
auto LibName = File; auto LibName = File;
NativeLib = new NativeLibrary(); NativeLib = new NativeLibrary();
NativeLib->FileName = LibName; NativeLib->FileName = LibName;
NativeLib->ArchType = ConvertArchType(ObjectFile->getArch());
if (ObjectFile->isELF()) if (ObjectFile->isELF())
{ {
@ -3142,7 +3155,7 @@ ParserResultKind Parser::ReadSymbols(llvm::StringRef File,
return ParserResultKind::Success; return ParserResultKind::Success;
} }
ParserResult* Parser::ParseLibrary(const std::string& File, ParserResult* res) ParserResult* Parser::ParseLibrary(const std::string& File, ParserResult* res)
{ {
if (File.empty()) if (File.empty())
{ {

Loading…
Cancel
Save