[r25]: LIME-UNIX / lib / UNIX-shell.awk  Maximize  Restore  History

Download this file

142 lines (135 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/gawk -f
##################################################################
# the LIME-UNIX BE generator
#
#Copyright 2008 Pjotr Kourzanov
#
#This file is part of LIME.
#
#LIME is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2
#as published by the Free Software Foundation.
#
#LIME is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with LIME. If not, see <http://www.gnu.org/licenses/>.
##################################################################
BEGIN { if (!OP) OP="dump"
if (!STDERR) STDERR="/dev/stderr"
state="" #top
}
func handle(tag,body) { return handle_gxf(tag,handle_types(tag,body)) }
END {
merge_types()
if (OP=="app.c") for (f in files) if (f ~ /.gxf$/) genapp_c(f)
if (OP=="edges.c") for (f in files) if (f ~ /.gxf$/) genedges_c(f)
if (OP=="shell.h") for (f in files) if (f ~ /.gxf$/) genshell_h(f)
if (OP=="shell.c") for (f in files) if (f ~ /.gxf$/) genshell_c(f)
}
func genapp_c(f, i,pr,fid,n,c,j,sn,pv,k,fs) {
pr=gensub(/\.[a-z]+$/,"","g",f)
print "#include <unistd.h>"
print "#include <stdio.h>"
for (i=1; i<=nnodes[f]; i++) {
n=nodes[f,i]
# don't include header for unconnected nodes
if (!fanout[f,n] && !fanin[f,n]) continue
c=gensub(/\$[a-z]+$/,"","g",n)
print "#include","\"" c "-shell.h\""
}
print "int main() {"
print space(2) "int r;"
# task id variables
for (i=1; i<=nnodes[f]; i++) {
n=nodes[f,i]
# don't create a task for unconnected nodes
if (!is_connected(f,n)) continue
# {con,de}structors do not have a task id
if (is_structor(f,n)) continue
print space(2) "pid_t",comp_tid(pr,n) ";"
}
# task state variables
for (i=1; i<=nconstructors[f]; i++) {
n=constructors[f,i]
for (j=1; j<=noutports[f,n]; j++) {
p=outports[f,n,j]
sn=peer_node[f,n,p]
print space(2) comp_state(sn),"*" sn "_state;"
}
}
# pipes
print space(2) "// pipe enpoints"
for (i=1; i<=nedges[f]; i++) {
split(edge_from[f,i],fr,SUBSEP); fn=fr[1]; fp=fr[2]
split(edge_to[f,i],to,SUBSEP); tn=to[1]; tp=to[2]
if (is_state(f,fn,"",fp)) continue
print space(2) "int",comp_pipe(fn,fp,tn,tp) "[" 2 "];"
}
# edges
print space(2) "// pipe creation"
for (i=1; i<=nedges[f]; i++) {
split(edge_from[f,i],fr,SUBSEP); fn=fr[1]; fp=fr[2]
split(edge_to[f,i],to,SUBSEP); tn=to[1]; tp=to[2]
if (is_state(f,fn,"",fp)) continue
printf space(2) "if (pipe(%s)==-1) {\n",comp_pipe(fn,fp,tn,tp)
print space(4) "perror(\"pipe\");"
print space(4) "exit(EXIT_FAILURE);"
print space(2) "}"
}
# state initialization, for constructors that are linked to the
# main
print space(2) "//state initialization"
for (i=1; i<=nconstructors[f]; i++) {
c=constructors[f,i]
for (k=1; k<=nnodes[c]; k++) {
n=nodes[c,k]
for (j=1; j<=noutports[c,n]; j++) {
sn=peer_node[f,c,outports[c,n,j]]
printf space(2) "%s_state=(%s*)malloc(%s_STATE_SIZE);\n",
sn,comp_state(sn),sn
}
args=""
for (j=1; j<=nports[c,n]; j++) {
p=ports[c,n,j]
sn=peer_node[f,c,p]
pv=dump_portvar(f,c,n,p,sn ? sn "_" : "")
args=append(args,
(port_const[c,n,p] ? "(const " port_type[c,n,p] "*)" : "")\
pv, ", ")
}
print space(2) scpe(c,n) "(" args ");"
for (j=1; j<=noutports[c,n]; j++) {
p=outports[c,n,j]
sn=peer_node[f,c,p]
printf space(2) "%s_state=%s_BUSY;\n",dump_portvar(f,c,n,p,sn "_"),sn
}
}
}
# task creation
print space(2) "// task creation"
for (i=1; i<=nnodes[f]; i++) {
n=nodes[f,i]
# don't create a task for unconnected nodes
if (!is_connected(f,n)) continue
if (is_structor(f,n)) continue
print space(2) "switch (r=fork()) {"
print space(4) "case -1: perror(\"fork\"); exit(EXIT_FAILURE); "
print space(4) "case 0:"
printf space(6) "%s();\n",comp_shell(n)
print space(6) "exit(EXIT_SUCCESS);"
print space(4) "default:"
printf space(6) "%s = r;\n", comp_tid(pr,n)
print space(6) "break;"
print space(2) "}"
}
print space(2) "return 0;"
print "}"
}
func comp_pipe(fn,fp,tn,tp) { return fn "_" fp "__" tn "_" tp "_pipe" }
@include gen-shell.awk
@include gxf-parser.awk
@include types-parser.awk

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks