1#! /usr/bin/awk -f 2# $OpenBSD: busop.awk,v 1.1 2003/02/17 01:29:20 henric Exp $ 3# 4# Copyright (c) 2003 Henric Jungheim 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. The name of the author may not be used to endorse or promote products 16# derived from this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29 30function generate_code(text, lines, key2, value2) { 31 for(r in row) { 32 print "/*" 33 print " * Implementing", value[r,"<TYPE>"] 34 print " */" 35 print 36 for(i = 1; i <= lines; ++i) { 37 out = text[i]; 38 for(k in key) 39 gsub(key[k], value[r,key[k]], out); 40 for(k in key2) 41 gsub(key2[k], value2[key2[k]], out); 42 43 print out; 44 } 45 } 46} 47 48BEGIN { 49 lines = 1; 50 raw_lines = 1; 51 split("<NUM> <TYPE> <FMT> <LOAD> <STORE>", key); 52 n = split( \ 53 "1,u_int8_t,%2.2x,lduba,stba;" \ 54 "2,u_int16_t,%4.4x,lduha,stha;" \ 55 "4,u_int32_t,%8.8x,lduwa,stwa;" \ 56 "8,u_int64_t,%16.16llx,ldxa,stxa", row, ";"); 57 for(r in row) { 58 if(split(row[r], tmp, ",") != length(key)) { 59 print "bad column at ", r; 60 print "row =", row[r]; 61 exit; 62 } 63 for(k in key) 64 value[r,key[k]] = tmp[k]; 65 delete tmp; 66 } 67 print "/*" 68 print " * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT." 69 print " */" 70 print 71} 72 73match($0, "^ECHO:") { 74 print substr($0, RLENGTH + 1); 75 next; 76} 77 78match($0, "^NRAW:") { 79 text[lines] = substr($0, RLENGTH + 1); 80 lines++; 81 next; 82} 83 84match($0, "^RAW:") { 85 raw_text[raw_lines] = substr($0, RLENGTH + 1); 86 raw_lines++; 87 next; 88} 89 90{ 91 text[lines] = $0; 92 lines++; 93 raw_text[raw_lines] = $0; 94 raw_lines++; 95} 96 97END { 98 k2[1] = "<RAW>"; k2[2] = "<ASI>"; 99 v2[k2[1]] = ""; 100 v2[k2[2]] = "asi"; 101 generate_code(text, lines, k2, v2); 102 v2[k2[1]] = "raw_"; 103 v2[k2[2]] = "sasi"; 104 generate_code(raw_text, raw_lines, k2, v2); 105} 106 107