From patchwork Fri Mar 18 02:29:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 642671 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2I2TSn0026736 for ; Fri, 18 Mar 2011 02:29:52 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E7D829E830 for ; Thu, 17 Mar 2011 19:29:27 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from cloud01.chad-versace.us (184-106-247-128.static.cloud-ips.com [184.106.247.128]) by gabe.freedesktop.org (Postfix) with ESMTP id 18FDB9E765 for ; Thu, 17 Mar 2011 19:29:09 -0700 (PDT) Received: from localhost.localdomain (unknown [67.208.96.87]) by cloud01.chad-versace.us (Postfix) with ESMTPSA id AD3201D406F; Fri, 18 Mar 2011 02:29:36 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Thu, 17 Mar 2011 19:29:03 -0700 Message-Id: <1300415343-3321-1-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.3.4 Subject: [Intel-gfx] [PATCH] intel-gen4asm: have a C-like binary output X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 18 Mar 2011 02:29:52 +0000 (UTC) diff --git a/src/main.c b/src/main.c index def2655..785cce8 100644 --- a/src/main.c +++ b/src/main.c @@ -40,10 +40,13 @@ extern int errors; long int gen_level = 4; int advanced_flag = 0; /* 0: in unit of type, 1: in unit of data element size */ +int binary_like_output = 0; /* 0: default type, 1: nice c like output */ int need_export = 0; char *input_filename = ""; char *export_filename = NULL; +const char const *binary_prepend = "static const char gen4_bytes[] = {\n"; + struct brw_program compiled_program; struct program_defaults program_defaults; @@ -53,6 +56,7 @@ static struct declared_register *declared_register_table[HASHSZ]; static const struct option longopts[] = { {"advanced", no_argument, 0, 'a'}, + {"binary", no_argument, 0, 'b'}, {"export", required_argument, 0, 'e'}, {"input_list", required_argument, 0, 'l'}, {"output", required_argument, 0, 'o'}, @@ -65,6 +69,7 @@ static void usage(void) fprintf(stderr, "usage: intel-gen4asm [options] inputfile\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, "\t-a, --advanced Set advanced flag\n"); + fprintf(stderr, "\t-b, --binary C style binary output\n"); fprintf(stderr, "\t-e, --export {exportfile} Export label file\n"); fprintf(stderr, "\t-l, --input_list {entrytablefile} Input entry_table_list file\n"); fprintf(stderr, "\t-o, --output {outputfile} Specify output file\n"); @@ -168,6 +173,38 @@ static int is_entry_point(char *s) return 0; } +static void +print_instruction(FILE *output, struct brw_program_instruction *entry) +{ + if (binary_like_output) { + fprintf(output, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x," + "0x%02x, 0x%02x, 0x%02x, 0x%02x," + "0x%02x, 0x%02x, 0x%02x, 0x%02x," + "0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", + ((unsigned char *)(&entry->instruction))[0], + ((unsigned char *)(&entry->instruction))[1], + ((unsigned char *)(&entry->instruction))[2], + ((unsigned char *)(&entry->instruction))[3], + ((unsigned char *)(&entry->instruction))[4], + ((unsigned char *)(&entry->instruction))[5], + ((unsigned char *)(&entry->instruction))[6], + ((unsigned char *)(&entry->instruction))[7], + ((unsigned char *)(&entry->instruction))[8], + ((unsigned char *)(&entry->instruction))[9], + ((unsigned char *)(&entry->instruction))[10], + ((unsigned char *)(&entry->instruction))[11], + ((unsigned char *)(&entry->instruction))[12], + ((unsigned char *)(&entry->instruction))[13], + ((unsigned char *)(&entry->instruction))[14], + ((unsigned char *)(&entry->instruction))[15]); + } else { + fprintf(output, " { 0x%08x, 0x%08x, 0x%08x, 0x%08x },\n", + ((int *)(&entry->instruction))[0], + ((int *)(&entry->instruction))[1], + ((int *)(&entry->instruction))[2], + ((int *)(&entry->instruction))[3]); + } +} int main(int argc, char **argv) { char *output_file = NULL; @@ -177,7 +214,7 @@ int main(int argc, char **argv) struct brw_program_instruction *entry, *entry1, *tmp_entry; int err, inst_offset; char o; - while ((o = getopt_long(argc, argv, "e:l:o:g:a", longopts, NULL)) != -1) { + while ((o = getopt_long(argc, argv, "e:l:o:g:ab", longopts, NULL)) != -1) { switch (o) { case 'o': if (strcmp(optarg, "-") != 0) @@ -198,6 +235,9 @@ int main(int argc, char **argv) case 'a': advanced_flag = 1; break; + case 'b': + binary_like_output = 1; + break; case 'e': need_export = 1; @@ -317,20 +357,21 @@ int main(int argc, char **argv) } + if (binary_like_output) + fprintf(output, "%s", binary_prepend); + for (entry = compiled_program.first; entry != NULL; entry = entry1) { entry1 = entry->next; if (!entry->islabel) - fprintf(output, " { 0x%08x, 0x%08x, 0x%08x, 0x%08x },\n", - ((int *)(&entry->instruction))[0], - ((int *)(&entry->instruction))[1], - ((int *)(&entry->instruction))[2], - ((int *)(&entry->instruction))[3]); + print_instruction(output, entry); else free(entry->string); free(entry); } + if (binary_like_output) + fprintf(output, "};"); free_register_table(); fflush (output);