mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-04 06:30:58 +00:00
directive #embed for sdcc and cmoc
This commit is contained in:
parent
f8462de014
commit
dff5c73d6a
@ -1,4 +1,4 @@
|
|||||||
import { getBasePlatform } from "../common/util";
|
import { convertDataToUint8Array, getBasePlatform } from "../common/util";
|
||||||
import { WorkerBuildStep, WorkerError, WorkerErrorResult, WorkerMessage, WorkerResult, WorkingStore } from "../common/workertypes";
|
import { WorkerBuildStep, WorkerError, WorkerErrorResult, WorkerMessage, WorkerResult, WorkingStore } from "../common/workertypes";
|
||||||
import { PLATFORM_PARAMS } from "./platforms";
|
import { PLATFORM_PARAMS } from "./platforms";
|
||||||
import { TOOLS } from "./workertools";
|
import { TOOLS } from "./workertools";
|
||||||
@ -414,3 +414,20 @@ export function fixParamsWithDefines(path: string, params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function processEmbedDirective(code: string) {
|
||||||
|
let re3 = /^\s*#embed\s+"(.+?)"/gm;
|
||||||
|
// find #embed "filename.bin" and replace with C array data
|
||||||
|
return code.replace(re3, (m, m1) => {
|
||||||
|
let filename = m1;
|
||||||
|
let filedata = store.getFileData(filename);
|
||||||
|
let bytes = convertDataToUint8Array(filedata);
|
||||||
|
if (!bytes) throw new Error('#embed: file not found: "' + filename + '"');
|
||||||
|
let out = '';
|
||||||
|
for (let i = 0; i < bytes.length; i++) {
|
||||||
|
out += bytes[i].toString() + ',';
|
||||||
|
}
|
||||||
|
return out.substring(0, out.length-1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { convertDataToUint8Array, getFilenamePrefix, getRootBasePlatform, safeident } from "../../common/util";
|
import { getRootBasePlatform } from "../../common/util";
|
||||||
import { CodeListingMap, WorkerError } from "../../common/workertypes";
|
import { CodeListingMap, WorkerError } from "../../common/workertypes";
|
||||||
import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, fixParamsWithDefines, putWorkFile, populateExtraFiles, store, populateEntry, anyTargetChanged } from "../builder";
|
import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, fixParamsWithDefines, putWorkFile, populateExtraFiles, store, populateEntry, anyTargetChanged, processEmbedDirective } from "../builder";
|
||||||
import { re_crlf, makeErrorMatcher } from "../listingutils";
|
import { re_crlf, makeErrorMatcher } from "../listingutils";
|
||||||
import { loadNative, moduleInstFn, print_fn, setupFS, execMain, emglobal, EmscriptenModule } from "../wasmutils";
|
import { loadNative, moduleInstFn, print_fn, setupFS, execMain, emglobal, EmscriptenModule } from "../wasmutils";
|
||||||
|
|
||||||
@ -270,22 +270,6 @@ export function linkLD65(step: BuildStep): BuildStepResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function processIncbin(code: string) {
|
|
||||||
let re3 = /^\s*#embed\s+"(.+?)"/gm;
|
|
||||||
// find #embed "filename.bin" and replace with C array data
|
|
||||||
return code.replace(re3, (m, m1) => {
|
|
||||||
let filename = m1;
|
|
||||||
let filedata = store.getFileData(filename);
|
|
||||||
let bytes = convertDataToUint8Array(filedata);
|
|
||||||
if (!bytes) throw new Error('#embed: file not found: "' + filename + '"');
|
|
||||||
let out = '';
|
|
||||||
for (let i = 0; i < bytes.length; i++) {
|
|
||||||
out += bytes[i].toString() + ',';
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function compileCC65(step: BuildStep): BuildStepResult {
|
export function compileCC65(step: BuildStep): BuildStepResult {
|
||||||
loadNative("cc65");
|
loadNative("cc65");
|
||||||
var params = step.params;
|
var params = step.params;
|
||||||
@ -321,7 +305,7 @@ export function compileCC65(step: BuildStep): BuildStepResult {
|
|||||||
mainFilePath: step.path,
|
mainFilePath: step.path,
|
||||||
processFn: (path, code) => {
|
processFn: (path, code) => {
|
||||||
if (typeof code === 'string') {
|
if (typeof code === 'string') {
|
||||||
code = processIncbin(code);
|
code = processEmbedDirective(code);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { getBasePlatform } from "../../common/util";
|
import { getBasePlatform } from "../../common/util";
|
||||||
import { BuildStep, populateFiles, populateExtraFiles, errorResult } from "../builder";
|
import { BuildStep, populateFiles, populateExtraFiles, errorResult, processEmbedDirective } from "../builder";
|
||||||
import { makeErrorMatcher, extractErrors } from "../listingutils";
|
import { makeErrorMatcher, extractErrors } from "../listingutils";
|
||||||
import { PLATFORM_PARAMS } from "../platforms";
|
import { PLATFORM_PARAMS } from "../platforms";
|
||||||
import { load, print_fn, setupFS, execMain, emglobal, EmscriptenModule } from "../wasmutils";
|
import { load, print_fn, setupFS, execMain, emglobal, EmscriptenModule } from "../wasmutils";
|
||||||
@ -24,7 +24,15 @@ export function preprocessMCPP(step: BuildStep, filesys: string) {
|
|||||||
});
|
});
|
||||||
var FS = MCPP.FS;
|
var FS = MCPP.FS;
|
||||||
if (filesys) setupFS(FS, filesys);
|
if (filesys) setupFS(FS, filesys);
|
||||||
populateFiles(step, FS);
|
populateFiles(step, FS, {
|
||||||
|
mainFilePath: step.path,
|
||||||
|
processFn: (path, code) => {
|
||||||
|
if (typeof code === 'string') {
|
||||||
|
code = processEmbedDirective(code);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
});
|
||||||
populateExtraFiles(step, FS, params.extra_compile_files);
|
populateExtraFiles(step, FS, params.extra_compile_files);
|
||||||
// TODO: make configurable by other compilers
|
// TODO: make configurable by other compilers
|
||||||
var args = [
|
var args = [
|
||||||
|
Loading…
Reference in New Issue
Block a user