void Assembler::ResolveArguments() { for (ast::Instruction& instr : parsedProgram){ if (instr.op.type() != typeid(Op)){ ast::Directive dir = boost::get<ast::Directive>(instr.op); if (dir == ast::Directive::DATA){ instr.encodedInstruction = EvaluateArgument(instr.ArgC()); } continue; } ast::OptionalArg a(instr.ArgA()); ast::OptionalArg b(instr.ArgB()); ast::Argument& c = instr.ArgC(); Op op = boost::get<Op>(instr.op); if (op == Op::JUMP){ //only op with optional ArgC. if (ast::IsRegister(c)){ instr.encodedInstruction = instr.encodedOp | EncodeC(EvaluateArgument(c)); } else { instr.encodedInstruction = instr.encodedOp | EncodeAddr(EvaluateArgument(c)); } } else if (ThreeArgs(op)){ if (!a || !b){ throw ArgumentException("Expected three arguments.", instr.lineNumber); } if (!ast::IsRegister(c)){ throw ArgumentException("C must be a register.", instr.lineNumber); } instr.encodedInstruction = instr.encodedOp | EncodeA(EvaluateArgument(a.get())) | EncodeB(EvaluateArgument(b.get())) | EncodeC(EvaluateArgument(c)); } else { if (!b){ throw ArgumentException("Expected two arguments, got one.", instr.lineNumber); } if (a){ throw ArgumentException("Expected two arguments, got three.", instr.lineNumber); } if (ast::IsRegister(b.get())){ instr.encodedInstruction = instr.encodedOp | EncodeB(EvaluateArgument(b.get())) | EncodeC(EvaluateArgument(c)); } else { instr.encodedInstruction = instr.encodedOp | EncodeAddr(EvaluateArgument(b.get())) | EncodeC(EvaluateArgument(c)); } } } }
/// main int main(int argc,char **argv) { int quality = -1; int hdrquality = -1; int maxerror = 0; int levels = 0; int restart = 0; int lsmode = -1; // Use JPEGLS int hiddenbits = 0; // hidden DCT bits int riddenbits = 0; // hidden bits in the residual domain int ahiddenbits = 0; // hidden DCT bits in the base alpha codestream int ariddenbits = 0; // hidden DCT bits in the residual alpha codestream. int resprec = 8; // precision in the residual domain int aresprec = 8; // precision of the residual alpha double gamma = 0.0; bool pyramidal = false; bool residuals = false; int colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_YCBCR; bool lossless = false; bool optimize = false; bool accoding = false; bool qscan = false; bool progressive = false; bool writednl = false; bool noiseshaping = false; bool rprogressive = false; bool rsequential = false; bool raccoding = false; bool serms = false; bool aserms = false; bool abypass = false; bool losslessdct = false; bool dctbypass = false; bool openloop = false; bool deadzone = false; bool lagrangian = false; bool dering = false; bool aopenloop = false; bool adeadzone = false; bool alagrangian = false; bool adering = false; bool xyz = false; bool cxyz = false; bool separate = false; bool noclamp = false; bool setprofile = false; bool upsample = true; bool median = true; int splitquality = -1; int profile = 2; // profile C. const char *sub = NULL; const char *ressub = NULL; const char *ldrsource = NULL; const char *lsource = NULL; const char *alpha = NULL; // source or target of the alpha plane bool alpharesiduals = false; int alphamode = JPGFLAG_ALPHA_REGULAR; // alpha mode int matte_r = 0,matte_g = 0,matte_b = 0; // matte color for alpha. int alphaquality = 70; int alphahdrquality = 0; int alphasplitquality = -1; int tabletype = 0; // quantization table types int residualtt = 0; int alphatt = 0; int residualalphatt = 0; int smooth = 0; // histogram smoothing PrintLicense(); fflush(stdout); while(argc > 3 && argv[1][0] == '-') { if (!strcmp(argv[1],"-q")) { quality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-Q")) { hdrquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-quality")) { splitquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-profile")) { const char *s = ParseString(argc,argv); setprofile = true; if (!strcmp(s,"a") || !strcmp(s,"A")) { profile = 0; } else if (!strcmp(s,"b") || !strcmp(s,"B")) { profile = 1; } else if (!strcmp(s,"c") || !strcmp(s,"C")) { profile = 2; } else if (!strcmp(s,"d") || !strcmp(s,"D")) { profile = 4; } else { fprintf(stderr,"unknown profile definition %s, only profiles a,b,c and d exist", s); return 20; } } else if (!strcmp(argv[1],"-m")) { maxerror = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-md")) { median = true; argv++; argc--; } else if (!strcmp(argv[1],"-ct")) { median = false; argv++; argc--; } else if (!strcmp(argv[1],"-sm")) { smooth = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-z")) { restart = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-r")) { residuals = true; argv++; argc--; } else if (!strcmp(argv[1],"-R")) { hiddenbits = ParseInt(argc,argv); if (hiddenbits < 0 || hiddenbits > 4) { fprintf(stderr,"JPEG XT allows only between 0 and 4 refinement bits.\n"); return 20; } } else if (!strcmp(argv[1],"-rR")) { riddenbits = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-n")) { writednl = true; argv++; argc--; } else if (!strcmp(argv[1],"-c")) { colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_NONE; argv++; argc--; } else if (!strcmp(argv[1],"-cls")) { colortrafo = JPGFLAG_MATRIX_COLORTRANSFORMATION_LSRCT; argv++; argc--; } else if (!strcmp(argv[1],"-sp")) { separate = true; argv++; argc--; } else if (!strcmp(argv[1],"-s")) { sub = ParseString(argc,argv); } else if (!strcmp(argv[1],"-sr")) { ressub = ParseString(argc,argv); } else if (!strcmp(argv[1],"-ncl")) { noclamp = true; argv++; argc--; } else if (!strcmp(argv[1],"-al")) { alpha = ParseString(argc,argv); } else if (!strcmp(argv[1],"-am")) { alphamode = ParseInt(argc,argv); if (alphamode < 0 || alphamode > 3) { fprintf(stderr,"the alpha mode specified with -am must be between 0 and 3\n"); return 20; } } else if (!strcmp(argv[1],"-ab")) { const char *matte = ParseString(argc,argv); if (sscanf(matte,"%d,%d,%d",&matte_r,&matte_g,&matte_b) != 3) { fprintf(stderr,"-ab expects three numeric arguments separated comma, i.e. r,g,b\n"); return 20; } } else if (!strcmp(argv[1],"-all")) { aserms = true; argv++; argc--; } else if (!strcmp(argv[1],"-alo")) { abypass = true; argv++; argc--; } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-p")) { lossless = true; argv++; argc--; } #endif else if (!strcmp(argv[1],"-h")) { optimize = true; argv++; argc--; } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-a")) { accoding = true; argv++; argc--; } else if (!strcmp(argv[1],"-ra")) { raccoding = true; argv++; argc--; } #endif else if (!strcmp(argv[1],"-qv")) { qscan = true; argv++; argc--; } else if (!strcmp(argv[1],"-v")) { progressive = true; argv++; argc--; } else if (!strcmp(argv[1],"-rv")) { rprogressive = true; argv++; argc--; } else if (!strcmp(argv[1],"-rs")) { rsequential = true; argv++; argc--; } else if (!strcmp(argv[1],"-r12")) { resprec = 12; residuals = true; argv++; argc--; } else if (!strcmp(argv[1],"-rl")) { losslessdct = true; argv++; argc--; } else if (!strcmp(argv[1],"-ro")) { dctbypass = true; argv++; argc--; } else if (!strcmp(argv[1],"-xyz")) { xyz = true; argv++; argc--; } else if (!strcmp(argv[1],"-cxyz")) { cxyz = true; argv++; argc--; } else if (!strcmp(argv[1],"-N")) { noiseshaping = true; argv++; argc--; } else if (!strcmp(argv[1],"-ol")) { openloop = true; argv++; argc--; } else if (!strcmp(argv[1],"-U")) { upsample = false; argv++; argc--; } else if (!strcmp(argv[1],"-dz")) { deadzone = true; argv++; argc--; #if ACCUSOFT_CODE } else if (!strcmp(argv[1],"-oz")) { lagrangian = true; argv++; argc--; } else if (!strcmp(argv[1],"-ozn")) { oznew = true; argv++; argc--; } else if (!strcmp(argv[1],"-dr")) { dering = true; argv++; argc--; #endif } else if (!strcmp(argv[1],"-qt")) { tabletype = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-rqt")) { residualtt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aqt")) { alphatt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-arqt")) { residualalphatt = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aol")) { aopenloop = true; argv++; argc--; } else if (!strcmp(argv[1],"-adz")) { adeadzone = true; argv++; argc--; #if ACCUSOFT_CODE } else if (!strcmp(argv[1],"-aoz")) { alagrangian = true; argv++; argc--; } else if (!strcmp(argv[1],"-adr")) { adering = true; argv++; argc--; #endif } else if (!strcmp(argv[1],"-ldr")) { ldrsource = ParseString(argc,argv); } else if (!strcmp(argv[1],"-l")) { serms = true; argv++; argc--; } else if (!strcmp(argv[1],"-g")) { gamma = ParseDouble(argc,argv); } else if (!strcmp(argv[1],"-gf")) { lsource = ParseString(argc,argv); } else if (!strcmp(argv[1],"-aq")) { alphaquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aQ")) { alphahdrquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-aquality")) { alphasplitquality = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-ar")) { alpharesiduals = true; argv++; argc--; } else if (!strcmp(argv[1],"-ar12")) { alpharesiduals = true; aresprec = 12; argv++; argc--; } else if (!strcmp(argv[1],"-aR")) { ahiddenbits = ParseInt(argc,argv); } else if (!strcmp(argv[1],"-arR")) { ariddenbits = ParseInt(argc,argv); } #if ACCUSOFT_CODE else if (!strcmp(argv[1],"-y")) { levels = ParseInt(argc,argv); if (levels == 0 || levels == 1) { // In this mode, the hierarchical model is used for lossless coding levels++; pyramidal = false; } else { pyramidal = true; } } #endif else if (!strcmp(argv[1],"-ls")) { lsmode = ParseInt(argc,argv); } else { fprintf(stderr,"unsupported command line switch %s\n",argv[1]); return 20; } } // // Use a very simplistic quality split. if (splitquality >= 0) { switch(profile) { case 0: break; case 1: break; case 2: case 4: SplitQualityC(splitquality,residuals,quality,hdrquality); break; } } // // The alpha channel is encoded with something that works like part 6. if (alphasplitquality > 0) { SplitQualityC(alphasplitquality,alpharesiduals,alphaquality,alphahdrquality); } if (argc != 3) { if (argc > 3) { fprintf(stderr,"Error in argument parsing, argument %s not understood or parsed correctly.\n" "Run without arguments for a list of command line options.\n\n", argv[1]); exit(20); } PrintUsage(argv[0]); return 5; } if (quality < 0 && lossless == false && lsmode < 0) { Reconstruct(argv[1],argv[2],colortrafo,alpha,upsample); } else { switch(profile) { case 0: fprintf(stderr,"**** Profile A encoding not supported due to patented IPRs.\n"); break; case 1: fprintf(stderr,"**** Profile B encoding not supported due to patented IPRs.\n"); break; case 2: case 4: if (setprofile && ((residuals == false && hiddenbits == false && profile != 4) || profile == 2)) residuals = true; EncodeC(argv[1],ldrsource,argv[2],lsource,quality,hdrquality, tabletype,residualtt,maxerror, colortrafo,lossless,progressive, residuals,optimize,accoding, rsequential,rprogressive,raccoding, qscan,levels,pyramidal,writednl,restart, gamma, lsmode,noiseshaping,serms,losslessdct, openloop,deadzone,lagrangian,dering, xyz,cxyz, hiddenbits,riddenbits,resprec,separate, median,noclamp,smooth,dctbypass, sub,ressub, alpha,alphamode,matte_r,matte_g,matte_b, alpharesiduals,alphaquality,alphahdrquality, alphatt,residualalphatt, ahiddenbits,ariddenbits,aresprec, aopenloop,adeadzone,alagrangian,adering, aserms,abypass); break; } } return 0; }