// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #include "a.h" /* * Helpers for building cmd/gc. */ // gcopnames creates opnames.h from go.h. // It finds the OXXX enum, pulls out all the constants // from OXXX to OEND, and writes a table mapping // op to string. void gcopnames(char *dir, char *file) { char *p, *q; int i, j, end; Buf in, b, out; Vec lines, fields; binit(&in); binit(&b); binit(&out); vinit(&lines); vinit(&fields); bwritestr(&out, bprintf(&b, "// auto generated by go tool dist\n")); bwritestr(&out, bprintf(&b, "static char *opnames[] = {\n")); readfile(&in, bprintf(&b, "%s/go.h", dir)); splitlines(&lines, bstr(&in)); i = 0; while(i= '0' && *s <= '9'; ++s) val = val * 10 + (*s - '0'); *end = s; return val; } // mkanames reads [5689].out.h and writes anames[5689].c // The format is much the same as the Go opcodes above. // It also writes out cnames array for C_* constants and the dnames // array for D_* constants. void mkanames(char *dir, char *file) { int i, j, ch, n, unknown; Buf in, b, out, out2; Vec lines; char *p, *p2; Vec dnames[128]; binit(&b); binit(&in); binit(&out); binit(&out2); vinit(&lines); for(i=0; i\n")); bwritestr(&out, bprintf(&b, "#include \n")); bwritestr(&out, bprintf(&b, "#include \n")); bwritestr(&out, bprintf(&b, "#include \n")); bwritestr(&out, bprintf(&b, "#include \"../cmd/%cl/%c.out.h\"\n", ch, ch)); bwritestr(&out, bprintf(&b, "\n")); bwritestr(&out, bprintf(&b, "char* anames%c[] = {\n", ch)); for(i=0; i0) bwriteb(&out, &out2); j=unknown=0; n=-1; for(i=0; i0){ bwritestr(&out, bprintf(&b, "char* dnames%c[D_LAST] = {\n", ch)); for(i=0; i