Plugin: EMIT source
The sample plugin that is supplied with Ziron.
Version 0.5
program WIN32DLL 'EMIT PLUGIN';
#include 'zirplug/framework.zir';
//////////////////////////////
const strLoaded = 'Emit plugin has loaded!';
//////////////////////////////
//
// event_Emit()
// return false to allow the assembler to process this keyword internally.
// return true to tell the assembler this keyword has been processed.
//
function event_Emit() {
uses edi;
char codeBuf[4];
eax = Ziron_ExpectNextToken(zirDATA_TYPE);
if (eax == -1) {
Ziron_FatalError('Expected data type');
return true;
}
edi = Ziron_GetTypeSize();
repeat {
eax = Ziron_GetNextToken();
case (eax) {
state zirHEXADECIMAL:
state zirNUMBER:
codeBuf = Ziron_GetIntValue();
Ziron_EmitCode(@codeBuf, edi);
break;
default:
Ziron_FatalError('Unexpected token type');
return true;
}
eax = Ziron_GetNextToken();
if (eax == zirSEMI_COLON) {
break;
} elseif (eax != zirCOMMA) {
Ziron_FatalError('Unexpected token type');
break;
}
};
return true;
}
function InitPlugin(pointer pGetF) {
Ziron_LoadAll(pGetF); //use framework utility function to load all
//register our keyword
Ziron_RegisterKeyword('emit', @event_Emit);
return strLoaded;
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin;
Save this code in a file such as "emit.zir", it can then be assembled with Ziron 1.1.24.9, finally, put the output dll into the plugins directory.
The extension this plugin brings is the emit keyword, which is used as so:
//a nop opcode
emit byte 0x90;
//push eax; pop eax
emit byte 0x50, 0x58;
//emit the number 5000 into the assembled code as a dword
emit dword 5000;
I will gradually upgrade this plugin as I extend the plugin system.