This commit is contained in:
Reece Wilson 2019-11-01 07:59:20 +00:00
parent fd99d06b3d
commit 5e4b4831d2
6 changed files with 71 additions and 70 deletions

63
T6/T6Context.js Normal file
View File

@ -0,0 +1,63 @@
const StreamReader = require("./../bin/streamReader.js");
const StreamWriter = require("./../bin/streamWriter.js");
const T6Header = require("./T6Header.js");
const T6Method = require("./T6Method.js");
const dasm = require("./../asm/disassembler.js");
const asm = require("./../asm/assembler.js");
const consts = require("./../constants.js");
const fio = require("fs");
const process = require("process");
function Context() {
this.types = consts;
this.header = new T6Header(this);
this.mainMethod = new T6Method(this);
this.HeaderType = T6Header;
this.MethodType = T6Method;
this.reader = undefined;
this.writer = undefined;
}
Context.prototype.fromBuffer = function(buf) {
this.reader = new StreamReader(buf, this);
this.header.read();
this.mainMethod.read();
}
Context.prototype.fromFile = function(file) {
this.fromBuffer(fio.readFileSync(file));
}
Context.prototype.save = function(file) {
this.writer = new StreamWriter(this);
this.header.write();
this.mainMethod.write();
this.writer.shrink();
if (file)
fio.writeFileSync(file, this.writer.buffer);
}
Context.prototype.disassembleStdout = function() {
var buffer = {msg: ""};
dasm.dsmContext(buffer, this);
process.stdout.write(buffer.msg);
}
Context.prototype.disassembleFile = function(file) {
var buffer = {msg: ""};
dasm.dsmContext(buffer, this);
fio.writeFileSync(file, buffer.msg);
}
Context.prototype.assemble = function(str) {
asm.asmContext(str, this);
}
Context.prototype.assembleFile = function(file) {
this.assemble(fio.readFileSync(file, "utf8"));
}
module.exports = Context;

View File

@ -37,14 +37,13 @@ Header.prototype.read = function() {
for (var i in this.ctx.types.list) {
var type = this.ctx.types.list[i];
var id = this.ctx.reader.readInteger();
if (id != type.id)
{
if (id != type.id){
console.log(fmt("illegal type index %i expected: %s (%i)", id, type.id, type.name));
return false;
}
var str = this.ctx.reader.readCString();
if (str != type.tname)
{
if (str != type.tname){
console.log(fmt("illegal type name %s expected: %s", str, type.tname));
return false;
}

View File

@ -1,5 +1,5 @@
const decoder = require("./instructions/instructionDecoder.js");
const ops = require("./instructions/instructions.js");
const decoder = require("./../instructions/instructionDecoder.js");
const ops = require("./../instructions/instructions.js");
const fmt = require("util").format;
const Constants = require("./T6Constants.js");

View File

@ -1,68 +1,7 @@
const StreamReader = require("./bin/streamReader.js");
const StreamWriter = require("./bin/streamWriter.js");
const fio = require("fs");
const consts = require("./constants.js");
const process = require("process");
const dasm = require("./asm/disassembler.js");
const asm = require("./asm/assembler.js");
const instructions = require("./instructions/instructions.js");
const T6Header = require("./T6Header.js");
const T6Method = require("./T6Method.js");
function Context() {
this.types = consts;
this.header = new T6Header(this);
this.mainMethod = new T6Method(this);
this.HeaderType = T6Header;
this.MethodType = T6Method;
this.reader = undefined;
this.writer = undefined;
}
Context.prototype.fromBuffer = function(buf) {
this.reader = new StreamReader(buf, this);
this.header.read();
this.mainMethod.read();
}
Context.prototype.fromFile = function(file) {
this.fromBuffer(fio.readFileSync(file));
}
Context.prototype.save = function(file) {
this.writer = new StreamWriter(this);
this.header.write();
this.mainMethod.write();
this.writer.shrink();
if (file)
fio.writeFileSync(file, this.writer.buffer);
}
Context.prototype.disassembleStdout = function() {
var buffer = {msg: ""};
dasm.dsmContext(buffer, this);
process.stdout.write(buffer.msg);
}
Context.prototype.disassembleFile = function(file) {
var buffer = {msg: ""};
dasm.dsmContext(buffer, this);
fio.writeFileSync(file, buffer.msg);
}
Context.prototype.assemble = function(str) {
asm.asmContext(str, this);
}
Context.prototype.assembleFile = function(file) {
this.assemble(fio.readFileSync(file, "utf8"));
}
const instructions = require("./instructions/instructions.js");
const T6Context = require("./T6/T6Context.js");
module.exports = {
T6Context: Context,
types: consts,
T6Context: T6Context,
instructions: instructions
}