Skip to content

Commit fb0b030

Browse files
committed
add sanitise to assembly
1 parent f7ac602 commit fb0b030

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

source/backends/x86_64.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class BackendX86_64 : CompilerBackend {
442442

443443
foreach (i, ref array ; arrays) {
444444
if (useGas) {
445-
output ~= format("__array_%d: skip %d\n", i, array.Size());
445+
output ~= format("__array_%d: .skip %d\n", i, array.Size());
446446
}
447447
else {
448448
output ~= format("__array_%d: resb %d\n", i, array.Size());
@@ -454,7 +454,7 @@ class BackendX86_64 : CompilerBackend {
454454
}
455455

456456
// create array source
457-
output ~= "section .text\n";
457+
output ~= format("%ssection .text\n", useGas? "." : "");
458458
foreach (i, ref array ; arrays) {
459459
output ~= format("__array_src_%d: ", i);
460460

source/output.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import std.format;
66
import std.string;
77
import std.algorithm;
88
import core.stdc.stdlib : exit;
9+
import callisto.util;
910

1011
// this will eventually be used for generating ASMMod files
1112
// but for now i'm using it because GNU Assembler is the worst piece of software to
@@ -51,6 +52,22 @@ class Output {
5152
output ~= macros[macroName];
5253
i = macroName.length + i + 2;
5354
}
55+
else if (text[i .. $].startsWith("${")) {
56+
if (text[i .. $].length == 2) {
57+
Error(text, "Incomplete sanitise statement");
58+
}
59+
60+
string input = text[i + 2 .. $];
61+
62+
if (!input.canFind('}')) {
63+
Error(text, "Incomplete sanitise statement");
64+
}
65+
66+
input = input[0 .. input.indexOf('}')];
67+
68+
output ~= input.Sanitise();
69+
i = input.length + i + 2;
70+
}
5471
else {
5572
output ~= text[i];
5673
}

0 commit comments

Comments
 (0)