OpenCores
URL https://opencores.org/ocsvn/vtach/vtach/trunk

Subversion Repositories vtach

[/] [vtach/] [trunk/] [asm/] [solopre.awk] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wd5gnr
#/**********************************************************************
2
#axasm Copyright 2006, 2007, 2008, 2009
3
#by Al Williams (alw@al-williams.com).
4
#
5
#
6
#This file is part of axasm.
7
#
8
#axasm is free software: you can redistribute it and/or modify it
9
#under the terms of the GNU General Public Licenses as published
10
#by the Free Software Foundation, either version 3 of the License, or
11
#(at your option) any later version.
12
#
13
#axasm is distributed in the hope that it will be useful, but
14
#WITHOUT ANY WARRANTY: without even the implied warranty of
15
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
#GNU General Public License for more details.
17
#
18
#You should have received a copy of the GNU General Public License
19
#along with axasm (see LICENSE.TXT).
20
#If not, see http://www.gnu.org/licenses/.
21
#
22
#If a non-GPL license is desired, contact the author.
23
#
24
#This is the assembler preprocessor
25
#
26
#***********************************************************************/
27
# expect -v LFILE=xxx argument (output of label definitions)
28
# allow -v PROC=xxx  (processor type)
29
 
30
# Note there are a few things the target macros must support
31
# LABEL, DEFLABEL - Supports the label system
32
#  DATA, DATA4  - Supports STRING and STRINGPACK
33
# Granted STRING and STRINGPACK ought to be removable somehow
34
 
35
BEGIN {
36
  if (LFILE!="") {
37
    if (PROC=="") {
38
      print "#include <soloasm.inc>";  # default inc file
39
    } else {
40
      print "#include <" PROC ".inc>";
41
    }
42
    print "#include \""  LFILE  "\""
43
    print "" > LFILE
44
    }
45
  }
46
 
47
 
48
# one time init
49
{
50
  if (first != 1) { first=1;   print "#line 1 \"" FILENAME "\""; }
51
}
52
 
53
 
54
# pass through any line directives
55
/^#line / { print; next; }
56
 
57
 
58
# pass through C code and C preprocessor
59
/^[ \t]*##/  {sub("^[ \t]*##","#");  print; next; }
60
/^[ \t]*#/  { sub("^[ \t]*#",""); print; next; }
61
 
62
   {
63
# This won't disturb semicolons if there is a quote
64
# directly after it. This could lead to trouble with
65
# semicolons in quoted strings, for example
66
# so we save just in case and string handling gets all of it
67
 
68
     withsemi=$0
69
     sub(";[^'\"].*$","");  # remove asm comments
70
     op=1;
71
   }
72
 
73
 
74
 
75
 
76
 
77
# deal with labels
78
/^[ \t]*[^ \t,]+:/   {
79
     label=$1;
80
     sub(/:$/,"",label);
81
     print "DEFLABEL("  label  ");" >>LFILE;
82
     printf "LABEL("  label  "); ";
83
     $1="";
84
     op=2;
85
   }
86
 
87
# blank lines (maybe it used to have just a label)
88
/^[ \t]*$/ { print; next; }
89
   {
90
 
91
# note: the below means your .h file that defines the processor
92
# must use uppercase names in macros but you are free to
93
# use mixed case in the assembly
94
# probably should make this an option somehow
95
     mac=toupper($op);
96
     $op="";
97
# unpacked string
98
     if (mac=="STRING") {
99
         $op="";
100
         strng=withsemi
101
         first=0;
102
# scan each letter. Note first quote, copy until 2nd quote
103
         for (i=1;i<length(strng);i++) {
104
             if (substr(strng,i,1)=="\"") {
105
                 if (first==0) { first=1;  continue; }
106
                 break;
107
             }
108
             if (!first) continue;
109
             v=substr(strng,i,1);
110
#            if (v=="\\") { v=substr(strng,i,2); i++; }
111
# handle \xNN \DDD or \C
112
             if (v=="\\") {
113
                 v1=substr(strng,i+1,1);
114
                 if (v1=="x"||v1=="X") {
115
                     v="\\x"
116
                     i+=2;
117
                     v=v substr(strng,i,1)
118
                     v1=substr(strng,i+1,1)
119
                     if ((v1>="0"&&v1<="9")||(tolower(v1)>="a"&&tolower(v1)<="f")) {
120
                             v=v v1
121
                             i++
122
                     }
123
                 }
124
                 else if (v1>="0" && v1<="7") {
125
 
126
                     while (v1>="0" && v1<="7") {
127
                         v=v v1;
128
                         i++;
129
                         v1=substr(strng,i+1,1);
130
                     }
131
                 } else {
132
                     v=substr(strng,i,2);
133
                     i++;
134
                 }
135
 
136
 
137
             }
138
             print "\tDATA('" v "');"
139
 
140
         }
141
         next;
142
     }
143
# packed string. Same logic as STRING
144
     if (mac=="STRINGPACK") {
145
         $op="";
146
         strng=withsemi #  $0;
147
         first=0;
148
         last=0;
149
         for (i=1;i<length(strng);) {
150
             if (substr(strng,i,1)=="\"") {
151
                 i++;
152
                 if (first==0) { first=1;  continue; }
153
                 break;
154
             }
155
             if (!first) { i++; continue; }
156
             printf "\tDATA4("
157
             k=0;
158
             for (j=0;j<4;j++) {
159
# should look at \x type escapes
160
                 v=substr(strng,i+k++,1);
161
# handle \xNN \DDD or \C
162
             if (v=="\\") {
163
                 v1=substr(strng,i+k+1,1);
164
                 if (v1=="x"||v1=="X") {
165
                     v="\\x"
166
                     k+=2;
167
                     v=v substr(strng,k,1)
168
                     v1=substr(strng,k+1,1)
169
                     if ((v1>="0"&&v1<="9")||(tolower(v1)>="a"&&tolower(v1)<="f")) {
170
                             v=v v1
171
                             k++
172
                         }
173
                 }
174
                 else if (v1>="0" && v1<="7") {
175
                     while (v1>="0" && v1<="7") {
176
                         v=v v1;
177
                         k++;
178
                         v1=substr(strng,k+1,1);
179
                     }
180
                 } else {
181
                     v=substr(strng,k,2);
182
                     k++;
183
                 }
184
             }
185
 
186
#                if (v=="\\") { v=substr(strng,i+j,2); j++; }
187
                 if (v=="\"") last=1;
188
                 if (last) v="\\000";
189
                 printf("'" v "'")
190
                 if (j!=3) printf(",");
191
             }
192
             print ");"
193
             i+=k;
194
         }
195
         next;
196
     }
197
# just some generic monadic macro or one with arguments
198
     if ($(op+1)=="") print(mac ";"); else  print(mac  "("  $0   ");");
199
   }
200
 
201
 
202
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.