Class AbstractCompiler
java.lang.Object
net.emustudio.emulib.plugin.AbstractPlugin
net.emustudio.emulib.plugin.compiler.AbstractCompiler
Compiler base. Implements listeners and the compilation workflow:
- listeners are notified about the start; title and version are reported
- output path is resolved (replacing source file extension by
getOutputExtension()) compile(Path, Path)is called;CompileExceptionor any other exception is reported as an error- listeners are notified about the finish
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCompiler plugin constructor.Nested classes/interfaces inherited from interface Compiler
Compiler.IncludeReference -
Field Summary
Fields inherited from class AbstractPlugin
applicationApi, pluginID, settings -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCompiler(long pluginID, ApplicationApi applicationApi, PluginSettings settings) Creates new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompilerListener(CompilerListener listener) Adds compiler listener.protected abstract voidCompiles the input file into the output file.final voidCompile given input file.protected voidprotected voiderror(SourceCodePosition position, String message) protected abstract StringOutput file extension (without dot), used when output path is not given.protected voidprotected final StringreadSource(Path path) Reads UTF-8 source and reports the exact text to the compilation listeners.voidremoveCompilerListener(CompilerListener listener) Removes compiler listener.static intrunCommandLine(String jarName, String[] args, AbstractCompiler.Factory factory) Command-line runner for compilers.protected voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Compiler
createLexer, findIncludes, getSourceFileTypes, getSourcePositionColumnUnit, isAutomationSupportedMethods inherited from interface Plugin
destroy, getCopyright, getDescription, getDocumentationUrl, getTitle, getVersion, initialize, isShowSettingsSupported, reset, showSettings, startAutomation, stopAutomation
-
Constructor Details
-
AbstractCompiler
Creates new instance.- Parameters:
pluginID- plugin IDapplicationApi- emuStudio APIsettings- plugin custom settings
-
-
Method Details
-
compile
Compiles the input file into the output file.Errors can be reported either by
error(SourceCodePosition, String)or by throwing an exception.- Parameters:
input- input file path (source code)output- output file path- Throws:
Exception- on compilation error
-
getOutputExtension
Output file extension (without dot), used when output path is not given.- Returns:
- output file extension, e.g. "hex"
-
compile
Description copied from interface:CompilerCompile given input file.If output path is not given, it is derived by replacing the source file extension of the input path. Usually a successfully compiled program is loaded in memory.
-
addCompilerListener
Description copied from interface:CompilerAdds compiler listener.- Specified by:
addCompilerListenerin interfaceCompiler- Parameters:
listener- compiler listener
-
removeCompilerListener
Description copied from interface:CompilerRemoves compiler listener.- Specified by:
removeCompilerListenerin interfaceCompiler- Parameters:
listener- compiler listener
-
readSource
Reads UTF-8 source and reports the exact text to the compilation listeners.- Throws:
IOException
-
error
-
error
- Parameters:
position- source position, or nullmessage- message
-
warning
-
info
-
runCommandLine
Command-line runner for compilers. Usage:[-o outputFile] inputFile,--version,--help. Messages are printed to standard error output.- Parameters:
jarName- jar file name used in helpargs- command-line argumentsfactory- compiler constructor, e.g.MyCompiler::new- Returns:
- exit code: 0 if successful, 1 if there were errors
-