def assemble(options): download_bytes, download_str, download_type, version = \ token_assembler.assemble_file(options.srcPath, options.debug) if (len(download_bytes) == 0): print("ERROR - No output produced") return # some sort of output print( "Assembly completed of %s type file: %s -- created %d bytes of tokens and header" % (download_type, options.srcPath, len(download_str))) versionNumber = (version[0] << 4) + version[1] versionString = chr(versionNumber) + chr(255 - versionNumber) # print(versionNumber, ord(versionString[0]), ord(versionString[1]), download_type) full_download_str = versionString + download_str full_download_bytes = [versionNumber, 255 - versionNumber] full_download_bytes.extend(download_bytes) print(len(full_download_bytes)) if (options.binFile is not None): if (options.preamble): download_str = full_download_str print("Writing %d bytes to file: %s" % (len(download_str), options.binFile.name)) options.binFile.write(download_str) options.binFile.close() if (options.wavFilename is not None): audioFile = audio.Output(".", options.wavFilename) audioFile.WriteWav(full_download_bytes)
def main(args): # Do the parsing first p = program.Program() rtc = parser.Parse(args.srcPath.name, p) # LOG.log("PAR rtc:{:d}".format(rtc)) if (rtc == 0): rtc = optimiser.Optimise(p) # LOG.log("OPT rtc:{:d}".format(rtc)) if (rtc == 0): rtc, statements = compiler.Compile(p, args.compilerOpt) # LOG.log("COM rtc:{:d}".format(rtc)) if (args.listing is not None): for s in statements: args.listing.write(s + "\n") args.listing.close() if (rtc == 0): # clear global memory hl_parser.reset_devices_and_locations() token_assembler.reset_tokens() # print(statements) dBytes, dString, dType, version = token_assembler.assemble_lines(statements, False) # print("Size:", len(dBytes), len(dString), dType, version) if (len(dBytes) == 0 or dType == 0 or version == 0): rtc = 1 elif (not args.checkOnly) and (not args.nowav): versionNumber = (version[0] << 4) + version[1] versionString = chr(versionNumber) + chr(255 - versionNumber) # print(versionNumber, ord(versionString[0]), ord(versionString[1]), download_type) if (not args.nowav): absSrcPath = os.path.abspath(args.srcPath.name) path = os.path.dirname(absSrcPath) a = audio.Output(path) io.Out.DebugRaw("WavPath:", a.GetWavPath()) io.Out.SetWavFilename(a.GetWavPath()) full_download_str = versionString + dString full_download_bytes = [versionNumber, 255 - versionNumber] full_download_bytes.extend(dBytes) # print(len(full_download_bytes)) LOG.log("WAV size:{:d} ver:{:d} name:{:s}".format(len(full_download_bytes), versionNumber, a.GetWavPath())) a.WriteWav(full_download_bytes) if (args.binary is not None): args.binary.write(full_download_str) args.binary.close() return rtc
LOG.log("START - Cmd line:{}".format(sys.argv[1:])) rtc = 1 # Console so that debugging can work while we do the parsing io.Out.SetSink(io.SINK.CONSOLE) io.Out.DebugRaw("Command line args", sys.argv[1:]) parsed = ProcessCommandArgs(sys.argv[1:]) io.Out.DebugRaw("Command line args", parsed) if parsed.x: if parsed.x == "pass": # want to output a wav file and json which has error = False absSrcPath = os.path.abspath(parsed.srcPath.name) path = os.path.dirname(absSrcPath) a = audio.Output(path) io.Out.DebugRaw("WavPath:", a.GetWavPath()) io.Out.SetWavFilename(a.GetWavPath()) io.Out.ForceJsonError(False) a.CreateDebugWav() rtc = 0 elif parsed.x == "fail": # want to output NO wav file and json which has error = True io.Out.Error(io.TS.ELPY_SPECIAL_FAIL, "Debug Error") else: io.Out.FatalRaw("Invalid special option: {}".format(parsed.x))
io.Out.SetSink(io.SINK.CONSOLE) io.Out.DebugRaw("Command line args", sys.argv[1:]) parsed = ProcessCommandArgs(sys.argv[1:]) io.Out.DebugRaw("Command line args", parsed) if not parsed.targetFile: parsed.targetFile = [""] if parsed.x: if parsed.x == "pass": # want to output a wav file and json which has error = False absSrcPath = os.path.abspath(parsed.srcPath.name) path = os.path.dirname(absSrcPath) a = audio.Output(path, parsed.targetFile[0]) io.Out.DebugRaw("WavPath:", a.GetWavPath()) io.Out.SetWavFilename(a.GetWavPath()) io.Out.ForceJsonError(False) a.CreateDebugWav() rtc = 0 elif parsed.x == "fail": # want to output NO wav file and json which has error = True io.Out.Error(io.TS.ELPY_SPECIAL_FAIL, "Debug Error") else: io.Out.FatalRaw("Invalid special option: {}".format(parsed.x))