int main (int argc, char *argv[]) { char *code; int n; int i; OrcProgram **programs; const char *filename = NULL; double sum; orc_init (); orc_test_init (); filename = "bench10.orc"; code = read_file (filename); if (!code) { printf("benchmorc needs bench10.orc file in current directory\n"); exit(1); } n = orc_parse (code, &programs); free (code); #if 0 sum = 0; for(i=0;i<n;i++){ double perf; double weight; perf = orc_test_performance_full (programs[i], 0, NULL); if (perf == 0) { weight = 0; } else { weight = 1.0/perf/281.0; sum++; } printf(" %g, /* %s */\n", weight, programs[i]->name); } printf("sum = %g\n", sum); #else sum = 0; for(i=0;i<n;i++){ double perf; double weight; perf = orc_test_performance_full (programs[i], 0, NULL); /* weight = weights_ginger[i]; */ weight = weights_feathers[i]; /* weight = weights_n900[i]; */ sum += weight * perf; orc_program_free (programs[i]); } free (programs); printf("score %g\n", 100.0/sum); #endif if (error) return 1; return 0; }
int main (int argc, char *argv[]) { char *code; int i; char *output_file = NULL; char *input_file = NULL; char *include_file = NULL; char *compat_version = VERSION; FILE *output; OrcParseError **errors = NULL; int n_errors = 0; orc_init (); for(i=1;i<argc;i++) { if (strcmp(argv[i], "--header") == 0) { mode = MODE_HEADER; } else if (strcmp(argv[i], "--implementation") == 0) { mode = MODE_IMPL; } else if (strcmp(argv[i], "--test") == 0) { mode = MODE_TEST; } else if (strcmp(argv[i], "--assembly") == 0) { mode = MODE_ASSEMBLY; } else if (strcmp(argv[i], "--parse-only") == 0) { mode = MODE_PARSE; } else if (strcmp(argv[i], "--include") == 0) { if (i+1 < argc) { include_file = argv[i+1]; i++; } else { help(); } } else if (strcmp (argv[i], "--output") == 0 || strcmp(argv[i], "-o") == 0) { if (i+1 < argc) { output_file = argv[i+1]; i++; } else { help(); } } else if (strcmp(argv[i], "--target") == 0 || strcmp(argv[i], "-t") == 0) { if (i+1 < argc) { target = argv[i+1]; i++; } else { help(); } } else if (strcmp(argv[i], "--inline") == 0) { use_inline = TRUE; } else if (strcmp(argv[i], "--no-inline") == 0) { use_inline = FALSE; } else if (strcmp(argv[i], "--internal") == 0) { use_internal = TRUE; } else if (strcmp(argv[i], "--no-internal") == 0) { use_internal = FALSE; } else if (strcmp(argv[i], "--init-function") == 0) { if (i+1 < argc) { init_function = argv[i+1]; i++; } else { help(); } } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { help (); } else if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) { verbose = 1; } else if (strcmp(argv[i], "--version") == 0) { fprintf(stderr, "Orc Compiler " PACKAGE_VERSION "\n"); exit (0); } else if (strcmp(argv[i], "--compat") == 0) { if (i+1 < argc) { compat_version = argv[i+1]; i++; } else { help(); } } else if (strcmp(argv[i], "--lazy-init") == 0) { use_lazy_init = TRUE; } else if (strcmp(argv[i], "--no-backup") == 0) { use_backup = FALSE; } else if (strncmp(argv[i], "-", 1) == 0) { fprintf(stderr, "Unknown option: %s\n", argv[i]); exit (1); } else { if (input_file == NULL) { input_file = argv[i]; } else { fprintf(stderr, "More than one input file specified: %s\n", argv[i]); exit (1); } } } if (input_file == NULL) { fprintf(stderr, "No input file specified\n"); exit (1); } if (mode == MODE_ASSEMBLY && orc_target_get_by_name (target) == NULL) { fprintf(stderr, "Unknown target \"%s\"\n", target); exit (1); } if (compat_version) { int major, minor, micro, nano = 0; int n; n = sscanf (compat_version, "%d.%d.%d.%d", &major, &minor, µ, &nano); if (n < 3) { fprintf(stderr, "Unknown version \"%s\"\n", compat_version); exit (1); } compat = ORC_VERSION(major,minor,micro,nano); if (compat < ORC_VERSION(0,4,5,0)) { fprintf(stderr, "Compatibility version \"%s\" not supported. Minimum 0.4.5\n", compat_version); exit (1); } } if (compat >= ORC_VERSION(0,4,11,1)) { use_code = TRUE; } if (output_file == NULL) { switch (mode) { case MODE_IMPL: output_file = "out.c"; break; case MODE_HEADER: output_file = "out.h"; break; case MODE_TEST: output_file = "out_test.c"; break; case MODE_ASSEMBLY: output_file = "out.s"; break; } } code = read_file (input_file); if (!code) { fprintf(stderr, "Could not read input file: %s\n", input_file); exit(1); } orc_parse_code (code, &programs, &n_programs, &errors, &n_errors); if (n_errors > 0) { int i; for (i=0;i<n_errors;i++) { fprintf(stderr, "%s @ %i: error: %s\n", errors[i]->source, errors[i]->line_number, errors[i]->text); } exit (1); } if (programs == NULL) { if (verbose) { fprintf(stderr, "no programs found\n"); } exit(1); } if (verbose) { fprintf(stderr, "%i program%s parsed\n", n_programs, (n_programs > 1) ?"s" :""); } if (mode == MODE_PARSE) { exit (0); } if (init_function == NULL) { init_function = orc_parse_get_init_function (programs[0]); } if (init_function == NULL) { use_lazy_init = TRUE; } output = fopen (output_file, "w"); if (!output) { fprintf(stderr, "Could not write output file: %s\n", output_file); exit(1); } fprintf(output, "\n"); fprintf(output, "/* autogenerated from %s */\n", my_basename(input_file)); fprintf(output, "\n"); if (mode == MODE_IMPL) { fprintf(output, "#ifdef HAVE_CONFIG_H\n"); fprintf(output, "#include \"config.h\"\n"); fprintf(output, "#endif\n"); if (include_file) { fprintf(output, "#include <%s>\n", include_file); } fprintf(output, "\n"); fprintf(output, "%s", orc_target_c_get_typedefs ()); fprintf(output, "\n"); fprintf(output, "#ifndef DISABLE_ORC\n"); fprintf(output, "#include <orc/orc.h>\n"); fprintf(output, "#endif\n"); for(i=0;i<n_programs;i++){ output_code_header (programs[i], output); } if (init_function) { fprintf(output, "\n"); fprintf(output, "void %s (void);\n", init_function); } fprintf(output, "\n"); fprintf(output, "%s", orc_target_get_asm_preamble ("c")); fprintf(output, "\n"); for(i=0;i<n_programs;i++){ output_code (programs[i], output); } fprintf(output, "\n"); if (init_function) { output_init_function (output); fprintf(output, "\n"); } } else if (mode == MODE_HEADER) { char *barrier = get_barrier (output_file); fprintf(output, "#ifndef _%s_\n", barrier); fprintf(output, "#define _%s_\n", barrier); free (barrier); fprintf(output, "\n"); if (include_file) { fprintf(output, "#include <%s>\n", include_file); } fprintf(output, "\n"); fprintf(output, "#ifdef __cplusplus\n"); fprintf(output, "extern \"C\" {\n"); fprintf(output, "#endif\n"); fprintf(output, "\n"); if (init_function) { fprintf(output, "void %s (void);\n", init_function); fprintf(output, "\n"); } fprintf(output, "\n"); if (!use_inline) { fprintf(output, "\n"); fprintf(output, "%s", orc_target_c_get_typedefs ()); for(i=0;i<n_programs;i++){ output_code_header (programs[i], output); } } else { fprintf(output, "\n"); fprintf(output, "#include <orc/orc.h>\n"); fprintf(output, "\n"); for(i=0;i<n_programs;i++){ output_code_execute (programs[i], output, TRUE); } } fprintf(output, "\n"); fprintf(output, "#ifdef __cplusplus\n"); fprintf(output, "}\n"); fprintf(output, "#endif\n"); fprintf(output, "\n"); fprintf(output, "#endif\n"); fprintf(output, "\n"); } else if (mode == MODE_TEST) { fprintf(output, "#include <stdio.h>\n"); fprintf(output, "#include <string.h>\n"); fprintf(output, "#include <stdlib.h>\n"); fprintf(output, "#include <math.h>\n"); if (include_file) { fprintf(output, "#include <%s>\n", include_file); } fprintf(output, "\n"); fprintf(output, "%s", orc_target_c_get_typedefs ()); fprintf(output, "#include <orc/orc.h>\n"); fprintf(output, "#include <orc-test/orctest.h>\n"); fprintf(output, "%s", orc_target_get_asm_preamble ("c")); fprintf(output, "\n"); if (use_backup) { for(i=0;i<n_programs;i++){ fprintf(output, "/* %s */\n", programs[i]->name); output_code_backup (programs[i], output); } } fprintf(output, "\n"); fprintf(output, "static int quiet = 0;\n"); fprintf(output, "static int benchmark = 0;\n"); fprintf(output, "\n"); fprintf(output, "static void help (const char *argv0)\n"); fprintf(output, "{\n"); fprintf(output, " fprintf(stderr, \"Usage:\\n\");\n"); fprintf(output, " fprintf(stderr, \" %%s [OPTION]\\n\", argv0);\n"); fprintf(output, " fprintf(stderr, \"Help Options:\\n\");\n"); fprintf(output, " fprintf(stderr, \" -h, --help Show help options\\n\");\n"); fprintf(output, " fprintf(stderr, \"Application Options:\\n\");\n"); fprintf(output, " fprintf(stderr, \" -b, --benchmark Run benchmark and show results\\n\");\n"); fprintf(output, " fprintf(stderr, \" -q, --quiet Don't output anything except on failures\\n\");\n"); fprintf(output, "\n"); fprintf(output, " exit(0);\n"); fprintf(output, "}\n"); fprintf(output, "\n"); fprintf(output, "int\n"); fprintf(output, "main (int argc, char *argv[])\n"); fprintf(output, "{\n"); fprintf(output, " int error = FALSE;\n"); fprintf(output, " int i;\n"); fprintf(output, "\n"); fprintf(output, " orc_test_init ();\n"); fprintf(output, "\n"); fprintf(output, " for(i=1;i<argc;i++) {\n"); fprintf(output, " if (strcmp(argv[i], \"--help\") == 0 ||\n"); fprintf(output, " strcmp(argv[i], \"-h\") == 0) {\n"); fprintf(output, " help(argv[0]);\n"); fprintf(output, " } else if (strcmp(argv[i], \"--quiet\") == 0 ||\n"); fprintf(output, " strcmp(argv[i], \"-q\") == 0) {\n"); fprintf(output, " quiet = 1;\n"); fprintf(output, " benchmark = 0;\n"); fprintf(output, " } else if (strcmp(argv[i], \"--benchmark\") == 0 ||\n"); fprintf(output, " strcmp(argv[i], \"-b\") == 0) {\n"); fprintf(output, " benchmark = 1;\n"); fprintf(output, " quiet = 0;\n"); fprintf(output, " }\n"); fprintf(output, " }\n"); fprintf(output, "\n"); for(i=0;i<n_programs;i++){ output_code_test (programs[i], output); } fprintf(output, "\n"); fprintf(output, " if (error) {\n"); fprintf(output, " return 1;\n"); fprintf(output, " };\n"); fprintf(output, " return 0;\n"); fprintf(output, "}\n"); } else if (mode == MODE_ASSEMBLY) { fprintf(output, "%s", orc_target_get_asm_preamble (target)); for(i=0;i<n_programs;i++){ output_code_assembly (programs[i], output); } } fclose (output); if (error) { remove (output_file); exit(1); } return 0; }
int main (int argc, char *argv[]) { int i; OrcProgram **programs; const char *filename = NULL; orc_init (); orc_test_init (); for(i=1;i<argc;i++){ if (strcmp(argv[i], "--help") == 0) { printf("Usage:\n"); printf(" orc-bugreport [file.orc]\n"); printf("\n"); printf("Options:\n"); printf(" --help Show help options\n"); printf(" --verbose Increase debugging messages\n"); printf("\n"); printf("Environment Variables:\n"); printf(" ORC_DEBUG=<LEVEL> Set debugging level\n"); printf(" ORC_CODE=[KEYWORDS,...] Modify code generation\n"); printf(" General keywords:\n"); printf(" backup Always use backup function\n"); printf(" debug Generate debuggable code (useful for backtraces on i386)\n"); printf(" SSE keywords:\n"); printf(" -sse2 Disable SSE2\n"); printf(" -sse3 Disable SSE3\n"); printf(" -ssse3 Disable SSEE3\n"); printf(" -sse41 Disable SSE4.1\n"); printf(" -sse42 Disable SSE4.2\n"); printf(" -sse4a Disable SSE4a\n"); printf(" -sse5 Disable SSE5\n"); printf("\n"); exit (0); } filename = argv[i]; } printf("Orc " VERSION " - integrated testing tool\n"); printf("Active backend: %s\n", orc_target_get_name(orc_target_get_default())); { int level1, level2, level3; orc_get_data_cache_sizes(&level1, &level2, &level3); printf("L1 cache: %d\n", level1); printf("L2 cache: %d\n", level2); printf("L3 cache: %d\n", level3); } { int family, model, stepping; orc_get_cpu_family_model_stepping (&family, &model, &stepping); printf("Family/Model/Stepping: %d/%d/%d\n", family, model, stepping); printf("CPU name: %s\n", orc_get_cpu_name ()); } { int i; int flags = orc_target_get_default_flags (orc_target_get_default()); printf("Compiler options: "); for(i=0;i<32;i++){ if (flags & (1<<i)) { printf("%s ", orc_target_get_flag_name (orc_target_get_default(), i)); } } printf("\n"); } if (filename) { int n; int ret; char *code; code = read_file (filename); if (!code) { printf("orc-bugreport: could not read file %s\n", filename); exit(1); } printf("Parsing %s\n", filename); n = orc_parse (code, &programs); for(i=0;i<n;i++){ ret = orc_test_compare_output_full (programs[i], 0); if (!ret) { printf("FAIL: %s\n", programs[i]->name); error = TRUE; } } } else { printf("Opcode test:\n"); test_opcodes(); } if (error) { printf("Errors detected. Please send entire output to [email protected].\n"); return 1; } else { printf("No errors detected.\n"); return 0; } }
int main(int argc, char *argv[]) { char *s, *d; orc_uint8 *src, *dest; OrcProfile prof; OrcProfile prof_libc; double ave, std; double ave_libc, std_libc; double null; int i,j; double cpufreq; int unalign; OrcProgram *p; int level1, level2, level3; int max; /* const uint8_t zero = 0; */ orc_init (); /* cpufreq = 2333e6; */ cpufreq = 1; if (argc > 1) { unalign = strtoul (argv[1], NULL, 0); } else { unalign = 0; } s = malloc(1024*1024*64+1024); d = malloc(1024*1024*64+1024); src = ORC_PTR_OFFSET(ALIGN(s,128),unalign); dest = ALIGN(d,128); orc_profile_init (&prof); for(j=0;j<10;j++){ orc_profile_start(&prof); orc_profile_stop(&prof); } orc_profile_get_ave_std (&prof, &null, &std); { OrcCompileResult result; p = orc_program_new (); orc_program_set_name (p, "orc_memcpy"); /* orc_program_set_name (p, "orc_memset"); */ orc_program_add_destination (p, 1, "d1"); orc_program_add_source (p, 1, "s1"); /* orc_program_add_parameter (p, 1, "p1"); */ orc_program_append (p, "copyb", ORC_VAR_D1, ORC_VAR_S1, ORC_VAR_D1); result = orc_program_compile (p); if (ORC_COMPILE_RESULT_IS_FATAL (result)) { fprintf (stderr, "Failed to compile orc_memcpy\n"); return -1; } } #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif orc_get_data_cache_sizes (&level1, &level2, &level3); if (level3 > 0) { max = (log(level3)/M_LN2 - 6.0) * 10 + 20; } else if (level2 > 0) { max = (log(level2)/M_LN2 - 6.0) * 10 + 20; } else { max = 140; } for(i=0;i<max;i++){ double x = i*0.1 + 6.0; int size = pow(2.0, x); if (flush_cache) { touch (src, (1<<18)); } if (hot_src) { touch (src, size); } if (hot_dest) { touch (dest, size); } orc_profile_init (&prof); for(j=0;j<10;j++){ OrcExecutor _ex, *ex = &_ex; void (*func) (OrcExecutor *); orc_profile_start(&prof); /* orc_memcpy (dest, src, size); */ ex->program = p; ex->n = size; ex->arrays[ORC_VAR_D1] = dest; ex->arrays[ORC_VAR_S1] = (void *)src; func = p->code_exec; func (ex); orc_profile_stop(&prof); if (flush_cache) { touch (src, (1<<18)); } if (hot_src) { touch (src, size); } if (hot_dest) { touch (dest, size); } } orc_profile_init (&prof_libc); for(j=0;j<10;j++){ orc_profile_start(&prof_libc); memcpy (dest, src, size); orc_profile_stop(&prof_libc); if (flush_cache) { touch (src, (1<<18)); } if (hot_src) { touch (src, size); } if (hot_dest) { touch (dest, size); } } orc_profile_get_ave_std (&prof, &ave, &std); orc_profile_get_ave_std (&prof_libc, &ave_libc, &std_libc); ave -= null; ave_libc -= null; /* printf("%d: %10.4g %10.4g %10.4g %10.4g (libc %10.4g)\n", i, ave, std, */ /* ave/(1<<i), cpufreq/(ave/(1<<i)), */ /* cpufreq/(ave_libc/(1<<i))); */ printf("%g %10.4g %10.4g\n", x, cpufreq/(ave/size), cpufreq/(ave_libc/size)); /* printf("%g %10.4g %10.4g\n", x, */ /* 32*(ave/(size)), 32*(ave_libc/(size))); */ fflush (stdout); } orc_program_free (p); free (s); free (d); return 0; }
int main (int argc, char *argv[]) { char *code; int n = 0; int i; OrcProgram **programs; const char *filename = NULL; orc_init (); orc_test_init (); for(i=1;i<argc;i++){ if (strcmp("-x", argv[i]) == 0) { format = FORMAT_HEX; } else if (strcmp("-s", argv[i]) == 0) { format = FORMAT_SIGNED; } else if (strcmp("-u", argv[i]) == 0) { format = FORMAT_UNSIGNED; } else if (strcmp("-f", argv[i]) == 0) { format = FORMAT_FLOAT; } else if (strcmp("-n", argv[i]) == 0) { if (i + 1 < argc) { array_n = strtol (argv[i+1], NULL, 0); i++; } } else { filename = argv[i]; } } if (filename == NULL) { filename = getenv ("testfile"); } if (filename == NULL) { filename = "test.orc"; } code = read_file (filename); if (code) { n = orc_parse (code, &programs); } else { OrcStaticOpcode *opcode; opcode = orc_opcode_find_by_name (filename); if (opcode) { programs = malloc(sizeof(void *)); programs[0] = orc_test_get_program_for_opcode (opcode); n = 1; } else { printf("show_parse [-fsux] (<file.orc>|opcode)\n"); exit(1); } } for(i=0;i<n;i++){ show (programs[i]); } if (error) return 1; return 0; }
int main (int argc, char *argv[]) { // Program banner printf( "----------------------------------\n" "--- Vocli Speech Synthesizer ---\n" "----------------------------------\n" "- Version: %s%*c\n" "- Email: [email protected] -\n" "----------------------------------\n\n", VOCLI_VERSION, abs(23 - strlen(VOCLI_VERSION)), '-'); // Initialize resources printf("Initializing CMU dictionary...\n"); CMUDict dictionary; cmu_init(CMU_PATH, &dictionary); printf("Creating Csound instance...\n"); CSOUND *csound = csoundCreate(NULL); csoundSetOption(csound, "-odac"); // Real time output if (csound == NULL) { cmu_destroy(&dictionary); return error(FAIL, "Unable to create Csound"); } printf("Initializing Vocli orchestra...\n"); int res = orc_init(csound, ORC_PATH); if (res != SUCCESS) { csoundDestroy(csound); cmu_destroy(&dictionary); return error(FAIL, "FATAL: Unable to initialize Vocli orchestra\n"); } // Special character whitelist char ok[] = "'_-"; size_t oklen = strlen(ok); // Input loop bool running = true; char input[512]; printf("\nType '!help' for a list of commands.\n\n"); while (running) { // Prompt string printf("Enter some text> "); // Read text from input fgets(input, 512, stdin); strchomp(input); // Handle commands if (input[0] == '!') { if (strncmp(&input[1], "quit", strlen("quit")) == 0) { putchar('\n'); running = false; } else for (int i = 0; i < num_cmds; i++) { const char *name = Commands[i].name; if (strncmp(&input[1], name, strlen(name)) == 0) Commands[i].callback(&input[1]); } // Skip further input processing continue; } // Reformat string to match the dictionary for (int i = 0, len = strlen(input); i < len; i++) { if (isalnum(input[i])) input[i] = toupper(input[i]); else for (int j = 0; j < oklen; j++) if (input[i] == ok[j]) break; else if (j == oklen - 1) input[i] = ' '; } // Look up and print each word int i; char *word = strtok(input, " "); for (i = 0; word != NULL; i++) { CMUDef *def = cmu_find_word(word, &dictionary); if (def != NULL) { for (int j = 0; j < def->num_phonemes; j++) { // Pass score event char start = i ? '0' : '+'; const ARPAsym *sym = &ARPAbet[def->phonIDs[j]]; printf("%s", sym->name); // Vowel stress if (sym->type == PHON_MONO || sym->type == PHON_DIPTHO) putchar(def->stress[j] + '0'); putchar(' '); } } // Separate each word if ((word = strtok(NULL, " ")) != NULL) printf(" - "); } putchar('\n'); } // Clean up csoundDestroy(csound); // Destroy Csound cmu_destroy(&dictionary); // Destroy CMU dictionary return SUCCESS; }