Prechádzať zdrojové kódy

NG incbins now wrapped in own object file.

woollybah 7 rokov pred
rodič
commit
4cf50136bd
6 zmenil súbory, kde vykonal 52 pridanie a 15 odobranie
  1. 1 1
      bcc.bmx
  2. 30 12
      ctranslator.bmx
  3. 1 1
      options.bmx
  4. 1 0
      stringbuffer_common.bmx
  5. 9 1
      stringbuffer_core.bmx
  6. 10 0
      stringbuffer_glue.c

+ 1 - 1
bcc.bmx

@@ -156,7 +156,7 @@ End Function
 Function SaveIncBinHeader(file:String, trans:TCTranslator, mung:String, app:TAppDecl)
 
 	If app.genIncBinHeader Then
-		Local path:String = OutputFilePath(file, mung, "incbin.h")
+		Local path:String = OutputFilePath(file, mung, "incbin.c")
 
 		SaveText(trans.JoinLines("incbin"), path)
 	End If

+ 30 - 12
ctranslator.bmx

@@ -3984,7 +3984,11 @@ End Rem
 			Next
 		
 			' process nested functions for new
-			Local decl:TFuncDecl = classDecl.FindFuncDecl("new",,,,,,SCOPE_CLASS_HEIRARCHY)
+			Local decl:TFuncDecl
+			Try
+				decl = classDecl.FindFuncDecl("new",,,,,True,SCOPE_CLASS_HEIRARCHY)
+			Catch e:String
+			End Try
 			If decl And decl.scope = classDecl Then ' only our own New method, not any from superclasses
 				decl.Semant
 				' emit nested protos
@@ -5304,9 +5308,11 @@ End Rem
 			ib.length = buf.length
 
 			Emit "unsigned char " + ident + "[] = {"
-			Local s:String
+			Local sb:TStringBuffer = New TStringBuffer
 
 			Local hx:Short[2]
+			Local lines:Int
+			Local count:Int
 			For Local i:Int = 0 Until buf.length
 				Local val:Int = buf[i]
 
@@ -5316,17 +5322,27 @@ End Rem
 					hx[k]=n
 					val:Shr 4
 				Next
-				s :+ "0x" + String.FromShorts( hx,2 )
+				sb.Append("0x").AppendShorts( hx,2 )
 
-				s :+ ","
+				sb.Append(",")
+				
+				count :+ 5
 
-				If s.length > 80 Then
-					Emit s
-					s = ""
+				If count > 80 Then
+					sb.Append("~n")
+					count = 0
+					lines :+ 1
+				End If
+				
+				If lines > 100 Then
+					Emit sb.ToString()
+					sb.SetLength(0)
+					lines = 0
 				End If
+				
 			Next
 
-			Emit s
+			Emit sb.ToString()
 			Emit "};"
 
 		End If
@@ -5558,8 +5574,8 @@ End If
 			Local mung:String = FileMung(False)
 
 			Local name:String = StripAll(app.mainModule.filepath)
-			Local file:String = name + ".bmx" + mung + ".incbin.h"
-			Local filepath:String = OutputFilePath(opt_filepath, mung, "incbin.h")
+			Local file:String = name + ".bmx" + mung + ".incbin.c"
+			Local filepath:String = OutputFilePath(opt_filepath, mung, "incbin.c")
 
 			If IncBinRequiresRebuild(filepath, app.incbins) Then
 
@@ -5578,8 +5594,6 @@ End If
 			End If
 
 			SetOutput("pre_source")
-
-			Emit "#include ~q" + file + "~q"
 		End If
 	End Method
 
@@ -5732,6 +5746,10 @@ End If
 			EmitFuncDecl(fdecl, False)
 		Next
 
+		' incbin decls
+		For Local ib:TIncbin = EachIn app.incbins
+			Emit "extern unsigned char * " + app.munged + "_ib_" + ib.id + ";"
+		Next
 
 		Emit "static int " + app.munged + "_inited" + " = 0;"
 

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.96"
+Const version:String = "0.97"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1

+ 1 - 0
stringbuffer_common.bmx

@@ -54,6 +54,7 @@ Extern
 	Function bmx_stringbuffer_removecharat(buffer:Byte Ptr, index:Int)
 	Function bmx_stringbuffer_append_cstring(buffer:Byte Ptr, chars:Byte Ptr)
 	Function bmx_stringbuffer_append_utf8string(buffer:Byte Ptr, chars:Byte Ptr)
+	Function bmx_stringbuffer_append_shorts(buffer:Byte Ptr, shorts:Short Ptr, length:Int)
 
 	Function bmx_stringbuffer_splitbuffer_length:Int(splitPtr:Byte Ptr)
 	Function bmx_stringbuffer_splitbuffer_text:String(splitPtr:Byte Ptr, index:Int)

+ 9 - 1
stringbuffer_core.bmx

@@ -137,7 +137,15 @@ Type TStringBuffer
 		bmx_stringbuffer_append_utf8string(buffer, chars)
 		Return Self
 	End Method
-	
+
+	Rem
+	bbdoc: Appends an array of shorts onto the string builder.
+	End Rem
+	Method AppendShorts:TStringBuffer(shorts:Short Ptr, length:Int)
+		bmx_stringbuffer_append_shorts(buffer, shorts, length)
+		Return Self
+	End Method
+
 	Rem
 	bbdoc: Finds first occurance of a sub string.
 	returns: -1 if @subString not found.

+ 10 - 0
stringbuffer_glue.c

@@ -501,6 +501,16 @@ void bmx_stringbuffer_append_utf8string(struct MaxStringBuffer * buf, const char
 	}
 }
 
+void bmx_stringbuffer_append_shorts(struct MaxStringBuffer * buf, short * shorts, int length) {
+	if (length > 0) {
+		bmx_stringbuffer_resize(buf, buf->count + length);
+		BBChar * p = buf->buffer + buf->count;
+		memcpy(p, shorts, length * sizeof(BBChar));
+		
+		buf->count += length;
+	}	
+}
+
 /* ----------------------------------------------------- */
 
 int bmx_stringbuffer_splitbuffer_length(struct MaxSplitBuffer * buf) {