Просмотр исходного кода

Added generation of .def file for function exports. Fixes #349.

woollybah 7 лет назад
Родитель
Сommit
2f15c9fef4
5 измененных файлов с 67 добавлено и 3 удалено
  1. 15 1
      bcc.bmx
  2. 41 2
      ctranslator.bmx
  3. 2 0
      decl.bmx
  4. 4 0
      iparser.bmx
  5. 5 0
      options.bmx

+ 15 - 1
bcc.bmx

@@ -83,7 +83,7 @@ SaveInterface(opt_filepath, trans, mung)
 SaveHeader(opt_filepath, trans, mung)
 SaveSource(opt_filepath, trans, mung)
 SaveIncBinHeader(opt_filepath, trans, FileMung(False), app)
-
+SaveDef(opt_filepath, trans, mung, app)
 
 Function SaveInterface(file:String, trans:TCTranslator, mung:String)
 
@@ -162,3 +162,17 @@ Function SaveIncBinHeader(file:String, trans:TCTranslator, mung:String, app:TApp
 	End If
 
 End Function
+
+Function SaveDef(file:String, trans:TCTranslator, mung:String, app:TAppDecl)
+
+	If opt_def And opt_apptype And opt_platform = "win32" Then
+		If opt_verbose Then
+			Print "Generating def..."
+		End If
+	
+		Local path:String = ExtractDir(opt_filepath) + "/" + StripExt(StripDir(opt_filepath)) + ".def"
+	
+		SaveText(trans.JoinLines("def"), path)
+	End If
+	
+End Function

+ 41 - 2
ctranslator.bmx

@@ -867,6 +867,21 @@ t:+"NULLNULLNULL"
 
 		Return glob
 	End Method
+	
+	Method TransExportDef:String(decl:TFuncDecl, withApi:Int = True)
+		Local t:String = decl.munged
+		
+		If withApi And decl.attrs & DECL_API_STDCALL Then
+			t :+ "@"
+			Local size:Int
+			For Local arg:TArgDecl = EachIn decl.argDecls
+				size :+ arg.ty.GetSize()
+			Next
+			t :+ size
+		End If
+		
+		Return t
+	End Method
 
 	Method CreateLocal2$( ty:TType, t$ )
 		Local tmp:TLocalDecl=New TLocalDecl.Create( "", ty,Null, True )
@@ -3073,12 +3088,18 @@ End Rem
 			opt_debug = False
 		End If
 
-		'PushMungScope
 		BeginLocalScope
-'DebugStop
+
 		decl.Semant
 
 		MungDecl decl
+		
+		' export defs?
+		If opt_apptype And opt_def And decl.attrs & DECL_EXPORT Then
+			If Not _appInstance.exportDefs.Contains(decl) Then
+				_appInstance.exportDefs.AddLast(decl)
+			End If
+		End If
 
 		' emit nested functions/classes
 		If Not proto Then
@@ -6169,6 +6190,20 @@ End If
 		Next
 
 	End Method
+	
+	Method TransDef(app:TAppDecl)
+
+		SetOutput("def")
+
+		Emit "LIBRARY " + StripExt(StripDir(opt_filepath))
+		Emit "EXPORTS"
+		
+		For Local decl:TFuncDecl=EachIn app.exportDefs
+			Emit "~t" + TransExportDef(decl, opt_arch = "x86")
+		Next
+
+		Emit "~n"
+	End Method
 
 	Method TransApp( app:TAppDecl )
 
@@ -6182,6 +6217,10 @@ End If
 
 		TransInterface(app)
 
+		If opt_def And opt_apptype Then
+			TransDef(app)
+		End If
+		
 	End Method
 	
 End Type

+ 2 - 0
decl.bmx

@@ -3668,6 +3668,8 @@ Type TAppDecl Extends TScopeDecl
 	Field dataDefs:TList = New TList
 	Field scopeDefs:TMap = New TMap
 	
+	Field exportDefs:TList = New TList
+	
 	Method GetPathPrefix:String()
 		If opt_buildtype = BUILDTYPE_MODULE Then
 			Local prefix:String

+ 4 - 0
iparser.bmx

@@ -1164,6 +1164,10 @@ Type TIParser
 		End If
 		
 		'If funcDecl.IsAbstract() Return funcDecl
+		If opt_def And funcDecl.attrs & DECL_EXPORT Then
+			_appInstance.exportDefs.AddLast(funcDecl)
+		End If
+		
 		Return funcDecl
 		
 	End Method

+ 5 - 0
options.bmx

@@ -105,6 +105,9 @@ Global opt_warnover:Int = False
 ' musl libc support
 '    
 Global opt_musl:Int = False
+' def
+'    generate .def files for dlls
+Global opt_def:Int = False
 
 Global opt_filepath:String
 
@@ -200,6 +203,8 @@ Function ParseArgs:String[](args:String[])
 				opt_warnover=True
 			Case "musl"
 				opt_musl=True
+			Case "def"
+				opt_def=True
 		End Select
 	
 		count:+ 1