示例#1
0
// Grammar match: arguments_list = type argument [= const_value] [,arguments_list]
bool match_arguments_list(TokenState& state, ArgumentsList *ptr_arguments)
{
    ArgumentsList argument_list;

    simple::string token;
    while (state.peek_token(&token) && token != ")")
    {
        if (token == "...")
        {
            // Matched ...
            state.skip();
            argument_list.is_va_arg = true;
            break;
        }

        // Get next argument
        Argument argument;
        if (!match_argument(state, &argument))
            return false;
        argument_list.args.push_back(simple::move(argument));

        if (state.peek_token(&token) && token == ",")
        {
            // Continue to match
            state.skip();
            continue;
        }
    }

    if (!match_word(state, ")"))
    {
        state.error_msg += "Missed ) for prototype.\n";
        return false;
    }

    *ptr_arguments = simple::move(argument_list);
    return true;
}
示例#2
0
static void
parse_options(struct conv_options *o,
	      int argc, char **argv)
{  
  o->mode = SEXP_ADVANCED;
  o->prefer_hex = 0;
  o->once = 0;
  o->lock = 0;
  o->hash = NULL;
  o->width = 72;
  
  for (;;)
    {
      static const struct nettle_hash *hashes[] =
	{ &nettle_md5, &nettle_sha1, &nettle_sha256, NULL };
  
      static const struct option options[] =
	{
	  /* Name, args, flag, val */
	  { "help", no_argument, NULL, OPT_HELP },
	  { "version", no_argument, NULL, 'V' },
	  { "once", no_argument, NULL, OPT_ONCE },
	  { "syntax", required_argument, NULL, 's' },
	  { "hash", optional_argument, NULL, OPT_HASH },
	  { "raw-hash", optional_argument, NULL, OPT_HASH },
	  { "width", required_argument, NULL, 'w' },
#if HAVE_FCNTL_LOCKING
	  { "lock", no_argument, NULL, OPT_LOCK },
#endif
#if 0
	  /* Not yet implemented */
	  { "replace", required_argument, NULL, OPT_REPLACE },
	  { "select", required_argument, NULL, OPT_SELECT },
	  { "spki-hash", optional_argument, NULL, OPT_SPKI_HASH },
#endif
	  { NULL, 0, NULL, 0 }
	};
      int c;
      int option_index = 0;
      unsigned i;
     
      c = getopt_long(argc, argv, "Vs:w:", options, &option_index);

      switch (c)
	{
	default:
	  abort();
	  
	case -1:
	  if (optind != argc)
	    die("sexp-conv: Command line takes no arguments, only options.\n");
	  return;

	case '?':
	  exit(EXIT_FAILURE);
	  
	case 'w':
	  {
	    char *end;
	    int width = strtol(optarg, &end , 0);
	    if (!*optarg || *end || width < 0)
	      die("sexp-conv: Invalid width `%s'.\n", optarg);

	    o->width = width;
	    break;
	  }
	case 's':
	  if (o->hash)
	    werror("sexp-conv: Combining --hash and -s usually makes no sense.\n");
	  if (match_argument(optarg, "advanced"))
	    o->mode = SEXP_ADVANCED;
	  else if (match_argument(optarg, "transport"))
	    o->mode = SEXP_TRANSPORT;
	  else if (match_argument(optarg, "canonical"))
	    o->mode = SEXP_CANONICAL;
	  else if (match_argument(optarg, "hex"))
	    {
	      o->mode = SEXP_ADVANCED;
	      o->prefer_hex = 1;
	    }
	  else
	    die("Available syntax variants: advanced, transport, canonical\n");
	  break;

	case OPT_ONCE:
	  o->once = 1;
	  break;
	
	case OPT_HASH:
	  o->mode = SEXP_CANONICAL;
	  if (!optarg)
	    o->hash = &nettle_sha1;
	  else
	    for (i = 0;; i++)
	      {
		if (!hashes[i])
		  die("sexp_conv: Unknown hash algorithm `%s'\n",
		      optarg);
	      
		if (match_argument(optarg, hashes[i]->name))
		  {
		    o->hash = hashes[i];
		    break;
		  }
	      }
	  break;
#if HAVE_FCNTL_LOCKING
	case OPT_LOCK:
	  o->lock = 1;
	  break;
#endif
	case OPT_HELP:
	  printf("Usage: sexp-conv [OPTION...]\n"
		 "  Conversion:     sexp-conv [OPTION...] <INPUT-SEXP\n"
		 "  Fingerprinting: sexp-conv --hash=HASH <INPUT-SEXP\n\n"
		 "Reads an s-expression on stdin, and outputs the same\n"
		 "sexp on stdout, possibly with a different syntax.\n\n"
		 "       --hash[=ALGORITHM]   Outputs only the hash of the expression.\n"
		 "                            Available hash algorithms:\n"
		 "                            ");
	  for(i = 0; hashes[i]; i++)
	    {
	      if (i) printf(", ");
	      printf("%s", hashes[i]->name);
	    }
	  printf(" (default is sha1).\n"
		 "   -s, --syntax=SYNTAX      The syntax used for the output. Available\n"
		 "                            variants: advanced, hex, transport, canonical\n"
		 "       --once               Process only the first s-expression.\n"
		 "   -w, --width=WIDTH        Linewidth for base64 encoded data.\n"
		 "                            Zero means no limit.\n"
#if HAVE_FCNTL_LOCKING
		 "       --lock               Lock output file.\n"
#endif
		 "       --raw-hash           Alias for --hash, for compatibility\n"
		 "                            with lsh-1.x.\n\n"
		 "Report bugs to " BUG_ADDRESS ".\n");
	  exit(EXIT_SUCCESS);

	case 'V':
	  printf("sexp-conv (" PACKAGE_STRING ")\n");
	  exit (EXIT_SUCCESS);
	}
    }
}
void check_metadata(const halide_filter_metadata_t &md, bool expect_ucon_at_0) {
    // target will vary depending on where we are testing, but probably
    // will contain "x86" or "arm".
    if (!strstr(md.target, "x86") && !strstr(md.target, "arm")) {
        fprintf(stderr, "Expected x86 or arm, Actual %s\n", md.target);
        exit(-1);
    }

    // Not static, since we free make_scalar() results each time
    const halide_filter_argument_t kExpectedArguments[] = {
        {
          "__user_context",
          halide_argument_kind_input_scalar,
          0,
          halide_type_handle,
          64,
          NULL,
          NULL,
          NULL,
        },
        {
          "input",
          halide_argument_kind_input_buffer,
          3,
          halide_type_uint,
          8,
          NULL,
          NULL,
          NULL,
        },
        {
          "b",
          halide_argument_kind_input_scalar,
          0,
          halide_type_uint,
          1,
          make_scalar<bool>(true),
          NULL,
          NULL,
        },
        {
          "i8",
          halide_argument_kind_input_scalar,
          0,
          halide_type_int,
          8,
          make_scalar<int8_t>(8),
          make_scalar<int8_t>(-8),
          make_scalar<int8_t>(127),
        },
        {
          "i16",
          halide_argument_kind_input_scalar,
          0,
          halide_type_int,
          16,
          make_scalar<int16_t>(16),
          make_scalar<int16_t>(-16),
          make_scalar<int16_t>(127),
        },
        {
          "i32",
          halide_argument_kind_input_scalar,
          0,
          halide_type_int,
          32,
          make_scalar<int32_t>(32),
          make_scalar<int32_t>(-32),
          make_scalar<int32_t>(127),
        },
        {
          "i64",
          halide_argument_kind_input_scalar,
          0,
          halide_type_int,
          64,
          make_scalar<int64_t>(64),
          make_scalar<int64_t>(-64),
          make_scalar<int64_t>(127),
        },
        {
          "u8",
          halide_argument_kind_input_scalar,
          0,
          halide_type_uint,
          8,
          make_scalar<uint8_t>(80),
          make_scalar<uint8_t>(8),
          make_scalar<uint8_t>(255),
        },
        {
          "u16",
          halide_argument_kind_input_scalar,
          0,
          halide_type_uint,
          16,
          make_scalar<uint16_t>(160),
          make_scalar<uint16_t>(16),
          make_scalar<uint16_t>(2550),
        },
        {
          "u32",
          halide_argument_kind_input_scalar,
          0,
          halide_type_uint,
          32,
          make_scalar<uint32_t>(320),
          make_scalar<uint32_t>(32),
          make_scalar<uint32_t>(2550),
        },
        {
          "u64",
          halide_argument_kind_input_scalar,
          0,
          halide_type_uint,
          64,
          make_scalar<uint64_t>(640),
          make_scalar<uint64_t>(64),
          make_scalar<uint64_t>(2550),
        },
        {
          "f32",
          halide_argument_kind_input_scalar,
          0,
          halide_type_float,
          32,
          make_scalar<float>(32.1234f),
          make_scalar<float>(-3200.1234f),
          make_scalar<float>(3200.1234f),
        },
        {
          "f64",
          halide_argument_kind_input_scalar,
          0,
          halide_type_float,
          64,
          make_scalar<double>(64.25),
          make_scalar<double>(-6400.25),
          make_scalar<double>(6400.25),
        },
        {
          "h",
          halide_argument_kind_input_scalar,
          0,
          halide_type_handle,
          64,
          NULL,
          NULL,
          NULL,
        },
        {
          "output.0",
          halide_argument_kind_output_buffer,
          3,
          halide_type_float,
          32,
          NULL,
          NULL,
          NULL,
        },
        {
          "output.1",
          halide_argument_kind_output_buffer,
          3,
          halide_type_float,
          32,
          NULL,
          NULL,
          NULL,
        }
    };
    const int kExpectedArgumentCount = (int)sizeof(kExpectedArguments) / sizeof(kExpectedArguments[0]);

    EXPECT_EQ(kExpectedArgumentCount - (expect_ucon_at_0 ? 0 : 1), md.num_arguments);

    const halide_filter_argument_t* expected = &kExpectedArguments[expect_ucon_at_0 ? 0 : 1];
    for (int i = 0; i < md.num_arguments; ++i) {
        fprintf(stdout, "checking arg %d %s\n", i, md.arguments[i].name);
        match_argument(expected[i], md.arguments[i]);
    }

    for (int i = 0; i < kExpectedArgumentCount; ++i) {
        delete kExpectedArguments[i].def;
        delete kExpectedArguments[i].min;
        delete kExpectedArguments[i].max;
    }
}