//-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- // // Main Java Universal assembler class // //-------------------------------------------------------------------------------------------------- package framework; import java.nio.file.Paths; import java.util.ArrayList; import java.util.LinkedList; import java.util.concurrent.locks.*; import java.lang.Thread; import java.io.File; import java.lang.InterruptedException; public class DVASM { // // Main java class // // These are the arguments // // -i input directory optional single // default to current directory // // -o output directory optional single // default to input directory // // -l output list directory optional single // default to output directory if specified // otherwise default to input directory // // -m macro directory optional multiple // default to input directory // // -a architecture directory or JAR file // optional single // default to this JAR file // // -x architecture extension directory or JAR file // optional single // default to architecture directory or JAR file // // input file name required multiples // .asm file type need not to be specified // this must be the last argument(s) // // // File types are: .asm input file // // .mac macros written in JavaScript // // .o output file // // .html output list in html format // // Output ELF and LIST file inherit the name from the input file, // only the file type changes // // public static void main(String args[]) { String inputDirectory= null; String outputDirectory= null; String listDirectory= null; String archDirectory= null; String archExtDirectory= null; LinkedList inputFiles= new LinkedList(); LinkedList outputFiles= new LinkedList(); LinkedList listFiles= new LinkedList(); ReentrantLock fileListLock= new ReentrantLock(); ArrayList macroDirectories= new ArrayList(); DVMacros macros; int coreNumber= Runtime.getRuntime().availableProcessors(); int i; if (args.length == 0) { System.err.println( "\n" + " DVASM or DaVinci Assembler\n\n" + " Invocation is: java -jar .../.../dvasm.jar OPTIONS INPUT_FILE_NAMES\n\n" + " These are the arguments\n\n" + " -i input directory optional single\n" + " default to current directory\n" + " -o output directory optional single\n" + " default to input directory\n" + " -l output list directory optional single\n" + " default to output directory\n" + " -m macro directory optional multiple\n" + " default to input directory\n" + " -a architecture directory or JAR file optional single\n" + " defaults to this JAR file\n" + " -x extension directory or JAR file optional single\n" + " defaults to architectural directory or JAR file\n" + " input file name required multiples\n" + " .asm file type need not to be specified\n" + " these must be the last argument(s)\n\n" + " File types are: .asm input file\n" + " .mac macros written in JavaScript\n" + " .o output file\n" + " .html output list in html format\n\n" + " Output ELF and LIST file inherit the name from the input file,\n" + " only the file type changes\n\n" + " No arguments to get this output\n\n" ); System.exit(0); } for (i= 0; i < args.length; i++) { if (! args[i].startsWith("-")) break; String option= args[i].substring(1, 2).toLowerCase(); if (args[i].length() < 2 || "iolaxm".indexOf(option) < 0) { System.err.println("DVASM argument error: invalid option"); System.exit(-1); } String optArg= null; if (args[i].length() == 2) { if (i == args.length-1) { System.err.println("DVASM argument error: option with no argument"); System.exit(-1); } i++; optArg= args[i]; } else optArg= args[i].substring(2); // // Check which option // switch (option) { case "i": if (inputDirectory != null) { System.err.println("DVASM argument error: " + "input directory specified more than once"); System.exit(-1); } inputDirectory= optArg; break; case "o": if (outputDirectory != null) { System.err.println("DVASM argument error: " + "output directory specified more than once"); System.exit(-1); } outputDirectory= optArg; break; case "l": if (listDirectory != null) { System.err.println("DVASM argument error: " + "list directory specified more than once"); System.exit(-1); } listDirectory= optArg; break; case "a": if (archDirectory != null) { System.err.println("DVASM argument error: " + "architecture directory/JAR file specified more than once"); System.exit(-1); } archDirectory= new File(optArg).getAbsolutePath(); if (! archDirectory.endsWith(".jar")) archDirectory+= "/"; break; case "x": if (archExtDirectory != null) { System.err.println("DVASM argument error: " + "architecture extension directory/JAR file specified more than once"); System.exit(-1); } archExtDirectory= new File(optArg).getAbsolutePath(); if (! archExtDirectory.endsWith(".jar")) archExtDirectory+= "/"; break; default: macroDirectories.add(optArg); } } if (inputDirectory == null) inputDirectory= new File("").getAbsolutePath(); if (macroDirectories.size() == 0) macroDirectories.add(inputDirectory); if (archExtDirectory == null) archExtDirectory= archDirectory; // // No option - input files from here on // boolean inpDirFlag= false; for (; i < args.length; i++) { String inputFile= Paths.get(args[i]).toString(); if (args[i].endsWith(".asm")) inputFile= args[i].substring(0, args[i].length()-4); String fileName= Paths.get(inputFile).getName(Paths.get(inputFile).getNameCount()-1).toString(); inpDirFlag|= (Paths.get(inputFile).isAbsolute() && inputDirectory != null); if (! Paths.get(inputFile).isAbsolute()) inputFile= Paths.get(inputDirectory, inputFile.toString()).toString(); inputFiles.add(inputFile + ".asm"); String outputFile; if (outputDirectory != null) outputFile= Paths.get(outputDirectory, fileName).toString(); else outputFile= inputFile; outputFiles.add(outputFile + ".o"); String listFile; if (listDirectory != null) listFile= Paths.get(listDirectory, fileName).toString(); else listFile= inputFile; listFiles.add(listFile + ".html"); } if (inputFiles.size() == 0) { System.err.println("DVASM error: No input file(s) specified"); System.exit(-1); } // // Create DVMacros and DVBaseOpCodes instances // try { macros= new DVMacros(macroDirectories); } catch(Exception e) { System.err.println(DVUtil.formatException("\n*** Error while creating DVMacros class", e) + "\n"); return; } // // Create array or threads and start them in a loop // //coreNumber*= 2; if (coreNumber > inputFiles.size()) coreNumber= inputFiles.size(); DVDriver[] drivers= new DVDriver[coreNumber]; DVThread[] driverThreads= new DVThread[coreNumber]; for (i= 0; i < coreNumber; i++) { drivers[i]= new DVDriver(inputFiles, macroDirectories, outputFiles, listFiles, archDirectory, archExtDirectory, macros, fileListLock); driverThreads[i]= new DVThread(drivers[i]); driverThreads[i].start(); } for (i= 0; i < coreNumber; i++) { try { driverThreads[i].join(); } catch(InterruptedException e) { } } } }