1
0
mirror of https://github.com/pfusik/xasm.git synced 2024-06-20 19:29:41 +00:00

Compare commits

..

No commits in common. "f33c112ac6f24edd6f70e97b2e23e4adb539c88c" and "afb9f7830e6a9846eb86863b2d7e290b0cac95b8" have entirely different histories.

5 changed files with 50 additions and 84 deletions

View File

@ -1,16 +0,0 @@
name: tests
on: [push, pull_request]
jobs:
test:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
dc: [dmd-latest, ldc-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@main
- uses: dlang-community/setup-dlang@v1
with:
compiler: ${{ matrix.dc }}
- run: dub build
- run: dub test

5
.travis.yml Normal file
View File

@ -0,0 +1,5 @@
language: d
d:
- dmd
- gdc
- ldc

View File

@ -1,4 +1,4 @@
[![GitHub Actions](https://github.com/pfusik/xasm/actions/workflows/test.yml/badge.svg)](https://github.com/pfusik/xasm/actions/workflows/test.yml)
[![Build Status](https://travis-ci.com/pfusik/xasm.svg?branch=master)](https://travis-ci.com/github/pfusik/xasm)
xasm
====

View File

@ -25,16 +25,19 @@ import std.math;
import std.path;
import std.stdio;
import std.string;
import std.exception : assumeUnique;
import std.range : empty, front, popFront;
version (Windows) {
import core.sys.windows.windows;
}
const string TITLE = "xasm 3.2.0";
int readByte(File *file) {
char c;
if (file.readf("%c", &c) != 1)
return -1;
return c;
}
File messageStream;
const string TITLE = "xasm 3.2.0";
string sourceFilename = null;
bool[26] options;
@ -42,7 +45,6 @@ string[26] optionParameters;
string[] commandLineDefinitions = null;
string objectFilename = null;
string[] makeSources = null;
immutable(ubyte)[][string] sourceFiles;
int exitCode = 0;
@ -174,14 +176,13 @@ File objectStream;
int objectBytes = 0;
bool getOption(char letter) {
assert(letter >= 'a' && letter <= 'z');
return options[letter - 'a'];
}
void warning(string msg, bool error = false) {
messageStream.flush();
stdout.flush();
version (Windows) {
HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -1086,7 +1087,7 @@ File openInputFile(string filename) {
File openOutputFile(string filename, string msg) {
if (!getOption('q'))
messageStream.writeln(msg);
writeln(msg);
try {
return File(filename, "wb");
} catch (Exception e) {
@ -1184,11 +1185,8 @@ void objectByte(ubyte b) {
} else {
assert(pass2);
if (!optionObject) return;
if (!objectStream.isOpen) {
objectStream = objectFilename == "-"
? stdout
: openOutputFile(objectFilename, "Writing object file...");
}
if (!objectStream.isOpen)
objectStream = openOutputFile(objectFilename, "Writing object file...");
try {
objectStream.write(cast(char) b);
} catch (Exception e) {
@ -2304,6 +2302,7 @@ void assemblyIns() {
}
}
File stream = openInputFile(filename);
scope (exit) stream.close();
try {
stream.seek(offset, offset >= 0 ? SEEK_SET : SEEK_END);
} catch (Exception e) {
@ -2312,13 +2311,13 @@ void assemblyIns() {
if (inOpcode)
length = 1;
while (length != 0) {
ubyte[1] b;
if (stream.rawRead(b).length != 1) {
int b = readByte(&stream);
if (b < 0) {
if (length > 0)
throw new AssemblyError("File is too short");
break;
}
putByte(b[0]);
putByte(cast(ubyte) b);
if (length > 0) length--;
}
}
@ -2797,17 +2796,11 @@ void assemblyLine() {
}
void assemblyFile(string filename) {
immutable(ubyte)[] source = sourceFiles.require(filename, {
File stream = stdin;
if (filename != "-") {
filename = filename.defaultExtension("asx");
if (getOption('p'))
filename = absolutePath(filename);
stream = openInputFile(filename);
}
return stream.byChunk(65536).joiner.array.assumeUnique;
}());
filename = filename.defaultExtension("asx");
if (getOption('p'))
filename = absolutePath(filename);
File stream = openInputFile(filename);
scope (exit) stream.close();
string oldFilename = currentFilename;
int oldLineNo = lineNo;
currentFilename = filename;
@ -2815,18 +2808,16 @@ void assemblyFile(string filename) {
foundEnd = false;
line = "";
readChar: while (!foundEnd) {
if (source.empty)
break;
ubyte b = source.front;
source.popFront;
int b = readByte(&stream);
switch (b) {
case -1:
break readChar;
case '\r':
assemblyLine();
line = "";
if (source.empty)
b = readByte(&stream);
if (b < 0)
break readChar;
b = source.front;
source.popFront;
if (b != '\n')
line ~= cast(char) b;
break;
@ -2953,17 +2944,10 @@ int main(string[] args) {
else {
if (sourceFilename is null)
exitCode = 3;
objectFilename = optionParameters['o' - 'a'];
if (objectFilename is null) {
objectFilename = sourceFilename == "-"
? "-"
: sourceFilename.setExtension("obx");
}
messageStream = objectFilename == "-" ? stderr : stdout;
if (!getOption('q'))
messageStream.writeln(TITLE);
writeln(TITLE);
if (exitCode != 0) {
messageStream.write(
write(
`Syntax: xasm SOURCE [OPTIONS]
-c Include false conditionals in listing
-d LABEL=VALUE Define a label
@ -2978,6 +2962,9 @@ int main(string[] args) {
`);
return exitCode;
}
objectFilename = optionParameters['o' - 'a'];
if (objectFilename is null)
objectFilename = sourceFilename.setExtension("obx");
try {
assemblyPass();
pass2 = true;
@ -2987,24 +2974,22 @@ int main(string[] args) {
} catch (AssemblyError e) {
warning(e.msg, true);
exitCode = 2;
if (objectFilename != "-") {
objectStream.close();
core.stdc.stdio.remove(toStringz(objectFilename));
}
objectStream.close();
core.stdc.stdio.remove(toStringz(objectFilename));
}
listingStream.close();
objectStream.close();
if (exitCode <= 1) {
if (!getOption('q')) {
messageStream.writefln("%d lines of source assembled", totalLines);
writefln("%d lines of source assembled", totalLines);
if (objectBytes > 0)
messageStream.writefln("%d bytes written to the object file", objectBytes);
writefln("%d bytes written to the object file", objectBytes);
}
if (getOption('m')) {
messageStream.writef("%s:", makeEscape(objectFilename));
writef("%s:", makeEscape(objectFilename));
foreach (filename; makeSources)
messageStream.writef(" %s", makeEscape(filename));
messageStream.write("\n\txasm");
writef(" %s", makeEscape(filename));
write("\n\txasm");
for (int i = 1; i < args.length; i++) {
string arg = args[i];
if (isOption(arg)) {
@ -3016,9 +3001,9 @@ int main(string[] args) {
break;
case 'o':
if (arg[0] == '/')
messageStream.writef(" /%c:$@", arg[1]);
writef(" /%c:$@", arg[1]);
else {
messageStream.writef(" -%c $@", arg[1]);
writef(" -%c $@", arg[1]);
++i;
}
break;
@ -3026,18 +3011,18 @@ int main(string[] args) {
if (arg[0] == '-'
&& (letter == 'd' || letter == 'l' || letter == 't')
&& i + 1 < args.length && !isOption(args[i + 1])) {
messageStream.writef(" %s %s", arg, makeEscape(args[++i]));
writef(" %s %s", arg, makeEscape(args[++i]));
}
else {
messageStream.writef(" %s", makeEscape(arg));
writef(" %s", makeEscape(arg));
}
break;
}
continue;
}
messageStream.write(" $<");
write(" $<");
}
messageStream.writeln();
writeln();
}
}
return exitCode;

View File

@ -16,7 +16,6 @@ DESCRIPTION
'SOURCE_FILE' is the name of the source file
(you may omit the default `.asx` extension).
Using '-' as 'SOURCE_FILE' makes *xasm* read from standard input.
When invoked without any options, *xasm* assembles 'SOURCE_FILE'
and writes the result to an object file named 'SOURCE_FILE'
with the extension changed to `.obx`.
@ -52,9 +51,7 @@ Your *make* or shell may require further escaping.
*-o* 'OBJECT_FILE'::
Sets output file name.
Using '-' as 'OBJECT_FILE' makes *xasm* write to standard output.
The default is 'SOURCE_FILE' with the extension changed to `.obx`, or
standard output if standard input was specified as source.
The default is 'SOURCE_FILE' with the extension changed to `.obx`.
[[new_fullpaths]]*-p*::
Prints absolute paths in listing and error messages.
@ -712,11 +709,6 @@ and pseudo commands, except for `MWA`, `MWX` and `MWY`:
HISTORY
-------
Version 3.x.x (20xx-xx-xx)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- source can optionally be read from standard input, and object can be
written to standard output instead of files (by Adrian Matoga)
Version 3.2.0 (2021-06-22)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- <<new_locallabel,local labels>> (contributed by Adrian Matoga)