Skip to content

Commit f7ac602

Browse files
committed
fix missing file
1 parent 1c5e4cf commit f7ac602

File tree

4 files changed

+84
-23
lines changed

4 files changed

+84
-23
lines changed

.gitignore

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ cac-test-*
1414
*.o
1515
*.obj
1616
*.lst
17-
out.asm
18-
out.com
19-
out.bin
20-
test.cal
21-
out.c
22-
out
23-
out.o
24-
out.exe
25-
out*
17+
/test.cal
18+
/out
19+
/out.*

source/backends/x86_64.d

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class BackendX86_64 : CompilerBackend {
5353

5454
this() {
5555
output = new Output();
56-
output.macros["QWORD"] = useGas? "qword ptr" : "qword";
57-
output.macros["DWORD"] = useGas? "dword ptr" : "dword";
58-
output.macros["WORD"] = useGas? "word ptr" : "word";
59-
output.macros["BYTE"] = useGas? "byte ptr" : "byte";
60-
6156
addrSize = 8;
6257

6358
version (linux) {
@@ -272,7 +267,7 @@ class BackendX86_64 : CompilerBackend {
272267
foreach (global ; globals) {
273268
if (global.type.hasInit && !global.type.ptr) {
274269
output ~= format(
275-
"lea rax, qword [__global_%s]\n", global.name.Sanitise()
270+
"lea rax, __global_%s\n", global.name.Sanitise()
276271
);
277272
output ~= "mov [r15], rax\n";
278273
output ~= "add r15, 8\n";
@@ -301,6 +296,11 @@ class BackendX86_64 : CompilerBackend {
301296
}
302297

303298
override void Init() {
299+
output.macros["QWORD"] = useGas? "qword ptr" : "qword";
300+
output.macros["DWORD"] = useGas? "dword ptr" : "dword";
301+
output.macros["WORD"] = useGas? "word ptr" : "word";
302+
output.macros["BYTE"] = useGas? "byte ptr" : "byte";
303+
304304
string[] oses = ["linux", "bare-metal", "osx", "freebsd"];
305305
if (!oses.canFind(os)) {
306306
ErrorNoInfo("Backend doesn't support operating system '%s'", os);
@@ -376,7 +376,7 @@ class BackendX86_64 : CompilerBackend {
376376
// call destructors
377377
foreach (global ; globals) {
378378
if (global.type.hasDeinit && !global.type.ptr) {
379-
output ~= format("lea rax, qword [__global_%s]\n", Sanitise(global.name));
379+
output ~= format("lea rax, __global_%s\n", Sanitise(global.name));
380380
output ~= "mov [r15], rax\n";
381381
output ~= "add r15, 8\n";
382382
output ~= format("call __type_deinit_%s\n", Sanitise(global.type.name));
@@ -624,7 +624,7 @@ class BackendX86_64 : CompilerBackend {
624624
// push parameters
625625
foreach_reverse (i ; 6 .. word.params.length) {
626626
output ~= format(
627-
"push qword [r15 - %d]\n", (word.params.length - i) * 8
627+
"push $(QWORD) [r15 - %d]\n", (word.params.length - i) * 8
628628
);
629629
}
630630
}
@@ -673,13 +673,15 @@ class BackendX86_64 : CompilerBackend {
673673

674674
if (crash) {
675675
output ~= format("lea rax, __global_%s\n", Sanitise("_cal_exception"));
676-
output ~= "cmp qword [rax], 0\n";
676+
output ~= "cmp $(QWORD) [rax], 0\n";
677677
output ~= format("jne __func__%s\n", Sanitise("__x86_64_exception"));
678678
}
679679
else {
680680
string temp = TempLabel();
681681

682-
output ~= format("cmp qword [__global_%s], 0\n", Sanitise("_cal_exception"));
682+
output ~= format(
683+
"cmp $(QWORD) [__global_%s], 0\n", Sanitise("_cal_exception")
684+
);
683685
output ~= format("je %s\n", temp);
684686
output ~= "mov r15, r14\n";
685687
CompileReturn(node);
@@ -1269,7 +1271,7 @@ class BackendX86_64 : CompilerBackend {
12691271
auto var = GetGlobal(node.func);
12701272

12711273
output ~= format(
1272-
"lea rax, qword [__global_%s]\n", node.func.Sanitise()
1274+
"lea rax, __global_%s\n", node.func.Sanitise()
12731275
);
12741276
output ~= "mov [r15], rax\n";
12751277
output ~= "add r15, 8\n";
@@ -1301,7 +1303,7 @@ class BackendX86_64 : CompilerBackend {
13011303
}
13021304
else {
13031305
output ~= format(
1304-
"lea rax, qword [__global_%s + %d]\n", name.Sanitise(), offset
1306+
"lea rax, [__global_%s + %d]\n", name.Sanitise(), offset
13051307
);
13061308
}
13071309

@@ -1561,7 +1563,7 @@ class BackendX86_64 : CompilerBackend {
15611563
++ blockCounter;
15621564

15631565
output ~= format("lea rax, __global_%s\n", Sanitise("_cal_exception"));
1564-
output ~= "cmp qword [rax], 0\n";
1566+
output ~= "cmp $(QWORD) [rax], 0\n";
15651567
output ~= format("je __catch_%d_end\n", blockCounter);
15661568

15671569
// function errored, assume that all it did was consume parameters

source/output.d

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module callisto.output;
2+
3+
import std.file;
4+
import std.stdio;
5+
import std.format;
6+
import std.string;
7+
import std.algorithm;
8+
import core.stdc.stdlib : exit;
9+
10+
// this will eventually be used for generating ASMMod files
11+
// but for now i'm using it because GNU Assembler is the worst piece of software to
12+
// ever exist
13+
class Output {
14+
string output;
15+
string outFile;
16+
string[string] macros;
17+
18+
this() {
19+
20+
}
21+
22+
void Error(Char, A...)(string source, in Char[] fmt, A args) {
23+
stderr.writefln("Output error from source: %s", source);
24+
stderr.writeln(format(fmt, args));
25+
exit(1);
26+
}
27+
28+
void opOpAssign(string op: "~")(char ch) {
29+
output ~= ch;
30+
}
31+
32+
void opOpAssign(string op: "~")(string text) {
33+
for (size_t i = 0; i < text.length; ++ i) {
34+
if (text[i .. $].startsWith("$(")) {
35+
if (text[i .. $].length == 2) {
36+
Error(text, "Incomplete macro invocation");
37+
}
38+
39+
string macroName = text[i + 2 .. $];
40+
41+
if (!macroName.canFind(')')) {
42+
Error(text, "Incomplete macro invocation");
43+
}
44+
45+
macroName = macroName[0 .. macroName.indexOf(')')];
46+
47+
if (macroName !in macros) {
48+
Error(text, "Macro '%s' doesn't exist", macroName);
49+
}
50+
51+
output ~= macros[macroName];
52+
i = macroName.length + i + 2;
53+
}
54+
else {
55+
output ~= text[i];
56+
}
57+
}
58+
}
59+
60+
void Finish() {
61+
std.file.write(outFile, output);
62+
}
63+
}
64+
65+

std

0 commit comments

Comments
 (0)