@@ -16,31 +16,15 @@ var link_options = [];
16
16
17
17
var line_nr_regex = / ( [ \w \. ] + ) [ \w \. \: ~ ] * \( ( [ 0 - 9 ] + ) \) / gi;
18
18
19
- var buffered_log = "" ;
20
- function logFunction ( str ) {
21
- if ( / ^ [ ^ : \s ] + : / . test ( str ) ) {
22
- // If the log starts with a label, we can emit the previously buffered one.
23
- flushLog ( ) ;
24
- buffered_log = str . trim ( ) ;
25
- } else {
26
- // If the log doesn’t start with a label, it’s a follow-up to the previous log,
27
- // so add it to the buffer.
28
- buffered_log += " " + str . trim ( ) ;
29
- }
30
- }
31
-
32
- function flushLog ( ) {
33
- unbufferedLogFunction ( buffered_log ) ;
34
- buffered_log = "" ;
35
- }
36
-
37
- function unbufferedLogFunction ( str ) {
38
- if ( log_callback ) log_callback ( str ) ;
19
+ function logFunction ( str , kind ) {
20
+ if ( log_callback ) log_callback ( str , kind ) ;
39
21
40
22
if (
41
- str . startsWith ( "error: " ) ||
42
- str . startsWith ( "ERROR: " ) ||
43
- str . startsWith ( "warning: " )
23
+ kind == "stderr" && (
24
+ str . startsWith ( "error: " ) ||
25
+ str . startsWith ( "ERROR: " ) ||
26
+ str . startsWith ( "warning: " )
27
+ )
44
28
) {
45
29
var type = "error" ;
46
30
if ( str . startsWith ( "warning: " ) ) type = "warning" ;
@@ -53,6 +37,18 @@ function unbufferedLogFunction(str) {
53
37
}
54
38
}
55
39
40
+ function infoFunction ( str ) {
41
+ logFunction ( str , "info" ) ;
42
+ }
43
+
44
+ function outFunction ( str ) {
45
+ logFunction ( str , "stdout" ) ;
46
+ }
47
+
48
+ function errFunction ( str ) {
49
+ logFunction ( str , "stderr" ) ;
50
+ }
51
+
56
52
export function setLogCallback ( callback ) {
57
53
log_callback = callback ;
58
54
}
@@ -89,7 +85,7 @@ function trigger() {
89
85
}
90
86
91
87
function startCompile ( ) {
92
- if ( log_callback ) log_callback ( null ) ;
88
+ if ( log_callback ) log_callback ( null , null ) ;
93
89
error_list = [ ] ;
94
90
rom_symbols = [ ] ;
95
91
ram_symbols = [ ] ;
@@ -102,7 +98,7 @@ function startCompile() {
102
98
103
99
function runRgbAsm ( targets , obj_files ) {
104
100
var target = targets . pop ( ) ;
105
- logFunction ( "Running: rgbasm " + target + " -o " + target + ".o -Wall" ) ;
101
+ infoFunction ( "Running: rgbasm " + target + " -o " + target + ".o -Wall" ) ;
106
102
createRgbAsm ( {
107
103
arguments : [ target , "-o" , "output.o" , "-Wall" ] ,
108
104
preRun : function ( m ) {
@@ -111,10 +107,9 @@ function runRgbAsm(targets, obj_files) {
111
107
FS . writeFile ( key , value ) ;
112
108
}
113
109
} ,
114
- print : logFunction ,
115
- printErr : logFunction ,
110
+ print : outFunction ,
111
+ printErr : errFunction ,
116
112
} ) . then ( function ( m ) {
117
- flushLog ( ) ;
118
113
if ( repeat ) {
119
114
buildFailed ( ) ;
120
115
return ;
@@ -135,17 +130,16 @@ function runRgbAsm(targets, obj_files) {
135
130
function runRgbLink ( obj_files ) {
136
131
var args = [ "-o" , "output.gb" , "--map" , "output.map" ] . concat ( link_options ) ;
137
132
for ( var name in obj_files ) args . push ( name + ".o" ) ;
138
- logFunction ( "Running: rgblink " + args . join ( " " ) ) ;
133
+ infoFunction ( "Running: rgblink " + args . join ( " " ) ) ;
139
134
createRgbLink ( {
140
135
arguments : args ,
141
136
preRun : function ( m ) {
142
137
var FS = m . FS ;
143
138
for ( var name in obj_files ) FS . writeFile ( name + ".o" , obj_files [ name ] ) ;
144
139
} ,
145
- print : logFunction ,
146
- printErr : logFunction ,
140
+ print : outFunction ,
141
+ printErr : errFunction ,
147
142
} ) . then ( function ( m ) {
148
- flushLog ( ) ;
149
143
if ( repeat ) {
150
144
buildFailed ( ) ;
151
145
return ;
@@ -169,17 +163,16 @@ function runRgbLink(obj_files) {
169
163
}
170
164
171
165
function runRgbFix ( input_rom_file , map_file ) {
172
- logFunction ( "Running: rgbfix -v output.gb -p 0xff" ) ;
166
+ infoFunction ( "Running: rgbfix -v output.gb -p 0xff" ) ;
173
167
createRgbFix ( {
174
168
arguments : [ "-v" , "output.gb" , "-p" , "0xff" ] ,
175
169
preRun : function ( m ) {
176
170
var FS = m . FS ;
177
171
FS . writeFile ( "output.gb" , input_rom_file ) ;
178
172
} ,
179
- print : logFunction ,
180
- printErr : logFunction ,
173
+ print : outFunction ,
174
+ printErr : errFunction ,
181
175
} ) . then ( function ( m ) {
182
- flushLog ( ) ;
183
176
var FS = m . FS ;
184
177
try {
185
178
var rom_file = FS . readFile ( "output.gb" ) ;
@@ -193,7 +186,7 @@ function runRgbFix(input_rom_file, map_file) {
193
186
}
194
187
195
188
function buildFailed ( ) {
196
- logFunction ( "Build failed" ) ;
189
+ infoFunction ( "Build failed" ) ;
197
190
if ( repeat ) {
198
191
repeat = false ;
199
192
trigger ( ) ;
@@ -265,7 +258,7 @@ function buildDone(rom_file, map_file) {
265
258
var total = 0x4000 ;
266
259
if ( section_type . startsWith ( "WRAM" ) ) total = 0x1000 ;
267
260
else if ( section_type . startsWith ( "HRAM" ) ) total = 127 ;
268
- logFunction (
261
+ infoFunction (
269
262
"Space left: " +
270
263
section_type +
271
264
"[" +
@@ -278,8 +271,7 @@ function buildDone(rom_file, map_file) {
278
271
) ;
279
272
}
280
273
}
281
- logFunction ( "Build done" ) ;
282
- flushLog ( ) ;
274
+ infoFunction ( "Build done" ) ;
283
275
done_callback ( rom_file , start_address , addr_to_line ) ;
284
276
}
285
277
}
0 commit comments