File tree Expand file tree Collapse file tree 6 files changed +44
-1
lines changed Expand file tree Collapse file tree 6 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 3535 -d - Enables debug symbols (if available)
3636 -l LIB - Links LIB with the linker (if available)
3737 -dv VER - Disables VER
38+ -h FILE - Puts the contents of FILE at the top of the assembly output
3839
3940Backends:
4041 rm86 - Real mode x86 and MS-DOS
@@ -67,6 +68,7 @@ int main(string[] args) {
6768 bool exportSymbols;
6869 string [] link;
6970 string [] disabled;
71+ string header;
7072
7173 for (size_t i = 1 ; i < args.length; ++ i) {
7274 if (args[i][0 ] == ' -' ) {
@@ -204,6 +206,21 @@ int main(string[] args) {
204206 disabled ~= args[i];
205207 break ;
206208 }
209+ case " -h" : {
210+ ++ i;
211+ if (i >= args.length) {
212+ stderr.writeln(" -h expects FILE argument" );
213+ return 1 ;
214+ }
215+
216+ if (header != " " ) {
217+ stderr.writeln(" Header set multiple times" );
218+ return 1 ;
219+ }
220+
221+ header = args[i];
222+ break ;
223+ }
207224 default : {
208225 stderr.writefln(" Unknown flag '%s'" , args[i]);
209226 return 1 ;
@@ -220,6 +237,21 @@ int main(string[] args) {
220237 }
221238 }
222239
240+ if (header == " " ) {
241+ header = backend.DefaultHeader();
242+ }
243+ else {
244+ try {
245+ header = readText(header);
246+ }
247+ catch (Exception e) {
248+ stderr.writefln(" %s: %s" , header, e.msg);
249+ return 1 ;
250+ }
251+ }
252+
253+ backend.output = header ~ ' \n ' ;
254+
223255 if (file == " " ) {
224256 stderr.writeln(" No source files" );
225257 return 1 ;
Original file line number Diff line number Diff line change @@ -168,6 +168,8 @@ class BackendLinux86 : CompilerBackend {
168168
169169 override long MaxInt () => - 1 ;
170170
171+ override string DefaultHeader () => " " ;
172+
171173 override void BeginMain () {
172174 output ~= " __calmain:\n " ;
173175 }
Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ class BackendRM86 : CompilerBackend {
142142
143143 override long MaxInt () => 0xFFFF ;
144144
145+ override string DefaultHeader () => " " ;
146+
145147 override void BeginMain () {
146148 output ~= " __calmain:\n " ;
147149 }
Original file line number Diff line number Diff line change @@ -114,6 +114,11 @@ class BackendUXN : CompilerBackend {
114114
115115 override long MaxInt () => 0xFFFF ;
116116
117+ override string DefaultHeader () => "
118+ |0 @vsp $2 @arraySrc $2 @arrayDest $2
119+ |10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
120+ " ;
121+
117122 override void NewConst (string name, long value, ErrorInfo error = ErrorInfo.init) {
118123 consts[name] = Constant(new IntegerNode(error, value));
119124 }
@@ -148,7 +153,6 @@ class BackendUXN : CompilerBackend {
148153
149154 override void Init () {
150155 output ~= " |0 @vsp $2 @arraySrc $2 @arrayDest $2\n " ;
151- output ~= " |00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2\n " ;
152156 output ~= " |10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1\n " ;
153157 output ~= " |100\n " ;
154158 output ~= " @on-reset\n " ;
Original file line number Diff line number Diff line change @@ -117,6 +117,8 @@ class BackendY32 : CompilerBackend {
117117
118118 override long MaxInt () => 0xFFFFFFFF ;
119119
120+ override string DefaultHeader () => " " ;
121+
120122 override void NewConst (string name, long value, ErrorInfo error = ErrorInfo.init) {
121123 consts[name] = Constant(new IntegerNode(error, value));
122124 }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class CompilerBackend {
2323 abstract string [] FinalCommands ();
2424 abstract long MaxInt ();
2525 abstract void NewConst (string name, long value, ErrorInfo error);
26+ abstract string DefaultHeader ();
2627
2728 abstract void BeginMain ();
2829
You can’t perform that action at this time.
0 commit comments