summaryrefslogtreecommitdiff
path: root/src/model_generation.py
diff options
context:
space:
mode:
authorRahul P2019-11-19 12:32:39 +0530
committerGitHub2019-11-19 12:32:39 +0530
commita6c0b36fcaba6c1f2d366432b2386122674b4782 (patch)
tree18a02155e45110fd6419139e48f6d9b277ab9870 /src/model_generation.py
parent2fe70dd26008b0f4920928d592290614bf47ce5d (diff)
parent6e12269c0681dcfb0d1ec927670fb9d69464af9c (diff)
downloadnghdl-a6c0b36fcaba6c1f2d366432b2386122674b4782.tar.gz
nghdl-a6c0b36fcaba6c1f2d366432b2386122674b4782.tar.bz2
nghdl-a6c0b36fcaba6c1f2d366432b2386122674b4782.zip
Merge pull request #29 from rahulp13/master
Updated nghdl
Diffstat (limited to 'src/model_generation.py')
-rw-r--r--src/model_generation.py241
1 files changed, 174 insertions, 67 deletions
diff --git a/src/model_generation.py b/src/model_generation.py
index 15dc3e6..dffd690 100644
--- a/src/model_generation.py
+++ b/src/model_generation.py
@@ -41,6 +41,7 @@ for item in vhdl_data:
#print "Scan Data",scan_data
port_info=[]
+port_vector_info = []
for item in scan_data:
print "Scan Data :",item
@@ -67,7 +68,12 @@ for item in scan_data:
lhs=temp.split(item)[0]
rhs=temp.split(item)[1]
bit_info=re.compile(r"\s*downto\s*",flags=re.I).split(rhs)[0]
- port_info.append(lhs+":"+str(int(bit_info)+int(1)))
+ if bit_info:
+ port_info.append(lhs+":"+str(int(bit_info)+int(1)))
+ port_vector_info.append(1)
+ else:
+ port_info.append(lhs+":"+str(int(1)))
+ port_vector_info.append(0)
print "Port Info :",port_info
@@ -92,7 +98,9 @@ data=read_file.readlines()
read_file.close()
#Extracting input and output port list from data
+print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
for line in data:
+ print line
if re.match(r'^\s*$', line):
pass
#print "Blank Line"
@@ -135,7 +143,7 @@ cfunc=open('cfunc.mod','w')
print "Building content for cfunc.mod file"
comment='''/* This is cfunc.mod file auto generated by gen_con_info.py
-Developed by Fahim at IIT Bombay */ \n
+Developed by Fahim, Rahul at IIT Bombay */ \n
'''
header='''
@@ -205,10 +213,12 @@ systime_info='''
time_t systime;
systime = time(NULL);
printf(ctime(&systime));
- printf("Client-Initialising ngspice \\n");
+ printf("Client-Initialising GHDL...");
fprintf(log_client,"Setup Client Server Connection at %s \\n",ctime(&systime));
'''
+
+
init_else='''
printf("Client-Inside else of INIT \\n");
fprintf(log_client,"Inside else of INIT \\n");
@@ -216,46 +226,88 @@ init_else='''
'''
els_evt_ptr=[]
-els_evt_count1=[]
+els_evt_count1=0
+els_evt_count2=0
for item in output_port:
- els_evt_count2=0
els_evt_ptr.append("_op_"+item.split(":")[0]+" = cm_event_get_ptr("+str(els_evt_count1)+","+str(els_evt_count2)+");")
els_evt_count2=els_evt_count2+1
els_evt_ptr.append("_op_"+item.split(":")[0]+"_old"+" = cm_event_get_ptr("+str(els_evt_count1)+","+str(els_evt_count2)+");")
els_evt_count1=els_evt_count1+1
-client_setup='''
- /* Client setup */
- //Default hostname assignment
- host = gethostbyname("127.0.0.1");
- printf("Client-Creating Client Socket \\n");
- fprintf(log_client,"Creating client socket \\n");
+client_setup_ip='''
+ /* Client Setup IP Addr */
+ FILE *fptr;
+ int ip_count = 0;
+ char* my_ip = malloc(16);
+
+ char ip_filename[40];
+ sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt", getpid());
+
+ fptr = fopen(ip_filename, "r");
+ if (fptr)
+ {
+ char line[20];
+ while(fscanf(fptr, "%s", line) == 1) {
+ ip_count++;
+ }
+
+ fclose(fptr);
+ }
+
+ if (ip_count < 255) {
+ sprintf(my_ip, "127.0.0.%d", ip_count+1);
+ } else {
+ sprintf(my_ip, "127.0.%d.1", (ip_count+1)%256);
+ }
+
+ fptr = fopen(ip_filename, "a");
+ if (fptr)
+ {
+ fprintf(fptr, "%s\\n", my_ip);
+ fclose(fptr);
+ } else {
+ perror("fopen() - Common IP");
+ exit(1);
+ }
+
+ STATIC_VAR(my_ip) = my_ip;
+'''
+
+client_fetch_ip='''
+ /* Client Fetch IP Addr */
+
+ char* my_ip = STATIC_VAR(my_ip);
+
+ host = gethostbyname(my_ip);
+ printf("\\n\\nClient-Creating Socket \\n");
+ fprintf(log_client,"Creating client socket \\n");
'''
+
create_socket='''
- //Creating socket for client
- if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- {
- perror("Client-Error while creating client Socket \\n");
- fprintf(log_client,"Error while creating client sockte \\n");
- exit(1);
- }
-
- printf("Client-Client Socket created successfully \\n");
- printf("Client- Socket Id : %d \\n",socket_fd);
- fprintf(log_client,"Client-Client Socket created successfully \\n");
- fprintf(log_client,"Client- Socket Id : %d \\n",socket_fd);
-
- // memset(&server_addr, 0, sizeof(server_addr));
- server_addr.sin_family = AF_INET;
- server_addr.sin_port = htons(sock_port);
- server_addr.sin_addr = *((struct in_addr *)host->h_addr);
- bzero(&(server_addr.sin_zero),8);
+ //Creating socket for client
+ if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+ {
+ perror("Client-Error while creating client Socket \\n");
+ fprintf(log_client,"Error while creating client socket \\n");
+ exit(1);
+ }
+
+ printf("Client-Client Socket created successfully \\n");
+ printf("Client- Socket Id : %d \\n",socket_fd);
+ fprintf(log_client,"Client-Client Socket created successfully \\n");
+ fprintf(log_client,"Client- Socket Id : %d \\n",socket_fd);
+
+ // memset(&server_addr, 0, sizeof(server_addr));
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = htons(sock_port);
+ server_addr.sin_addr = *((struct in_addr *)host->h_addr);
+ bzero(&(server_addr.sin_zero),8);
'''
connect_server='''
- printf("Client-Connecting to server \\n");
+ printf("Client-Connecting to server \\n");
fprintf(log_client,"Client-Connecting to server \\n");
//Conneting to server
@@ -418,9 +470,9 @@ els_time_limit='''
fprintf(log_client,"Socket Id : %d & Message sent : %s for END signal \\n",socket_fd,send_data);
}
flag++;
- close(socket_fd);
}
+ close(socket_fd);
'''
@@ -463,10 +515,12 @@ for item in cm_event_get_ptr:
cfunc.write("\n")
cfunc.write(systime_info)
cfunc.write("\n")
-cfunc.write("\t\tchar command[1024];")
-cfunc.write('\t\tsnprintf(command,1024,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/start_server.sh %d &",sock_port);\n')
-cfunc.write('\t\tsystem(command);')
-cfunc.write("\t}")
+cfunc.write(client_setup_ip)
+cfunc.write("\n")
+cfunc.write("\t\tchar command[1024];\n")
+cfunc.write('\t\tsnprintf(command,1024,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/start_server.sh %d %s &",sock_port, my_ip);')
+cfunc.write('\n\t\tsystem(command);')
+cfunc.write("\n\t}")
cfunc.write("\n")
cfunc.write("\telse\n\t{\n")
@@ -476,7 +530,7 @@ for item in els_evt_ptr:
cfunc.write("\t}")
cfunc.write("\n\n")
cfunc.write("\tif(flag==0)\n\t{")
-cfunc.write(client_setup)
+cfunc.write(client_fetch_ip)
cfunc.write(create_socket)
cfunc.write(connect_server)
cfunc.write(time_limit)
@@ -590,6 +644,16 @@ Null_Allowed: yes no
'''
+static_table='''
+
+STATIC_VAR_TABLE:
+
+Static_Var_Name: my_ip
+Data_Type: pointer
+Description: "connect to ghdlserver through this ip"
+
+'''
+
#Writing all the content in ifspec file
ifspec.write(ifspec_comment)
@@ -605,6 +669,8 @@ for item in out_port_table:
ifspec.write("\n")
ifspec.write(parameter_table)
+ifspec.write("\n")
+ifspec.write(static_table)
ifspec.close()
@@ -612,8 +678,11 @@ ifspec.close()
print "Starting with testbench file"
testbench=open(fname.split('.')[0]+'_tb.vhdl','w')
+print fname.split('.')[0] + '_tb.vhdl'
#comment
-comment_vhdl="--------------------------------------------------------------------------------\n--This testbench has been created by Ambikeshwar Srivastava, FOSSEE, IIT Bombay\n-------------------------------------------------------------------------------"
+comment_vhdl="--------------------------------------------------------------------------------\n--This testbench has been created by Ambikeshwar Srivastava, FOSSEE, IIT Bombay\n--------------------------------------------------------------------------------\n"
+comment_vhdl+="--------------------------------------------------------------------------------\n--Modified by Rahul Paknikar, FOSSEE, IIT Bombay\n"
+comment_vhdl+="--retrieves the IP-Addr from sock_pkg and forwards it to the ghdlserver\n--------------------------------------------------------------------------------\n"
#Adding header, entity and architecture statement
tb_header='''
library ieee;
@@ -636,16 +705,32 @@ arch="architecture "+fname.split('.')[0]+"_tb_beh of "+fname.split('.')[0]+"_tb
components=[]
components.append("\tcomponent "+fname.split('.')[0]+" is\n\t\tport(\n\t\t\t\t")
+port_vector_count = 0
+
for item in input_port:
- components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
- #if item.split(":")[1] != '1':
- # components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
- #else:
- # components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
+ if port_vector_info[port_vector_count]:
+ components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
+ else:
+ components.append(item.split(':')[0]+": in std_logic;\n\t\t\t\t")
+
+ port_vector_count += 1
+ #if item.split(":")[1] != '1':
+ # components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
+ #else:
+ # components.append(item.split(':')[0]+": in std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
for item in output_port[:-1]:
- components.append(item.split(':')[0]+": out std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
-components.append(output_port[-1].split(':')[0]+": out std_logic_vector("+str(int(output_port[-1].split(':')[1])-int(1))+" downto 0)\n\t\t\t\t")
+ if port_vector_info[port_vector_count]:
+ components.append(item.split(':')[0]+": out std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n\t\t\t\t")
+ else:
+ components.append(item.split(':')[0]+": out std_logic;\n\t\t\t\t")
+
+ port_vector_count += 1
+
+if port_vector_info[port_vector_count]:
+ components.append(output_port[-1].split(':')[0]+": out std_logic_vector("+str(int(output_port[-1].split(':')[1])-int(1))+" downto 0)\n\t\t\t\t")
+else:
+ components.append(output_port[-1].split(':')[0]+": out std_logic\n\t\t\t\t")
#if item.split(":")[1] != '1':
# components.append(item.split(':')[0]+": out std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0)\n\t\t\t\t")
#else:
@@ -658,8 +743,15 @@ components.append("\tend component;\n\n")
signals=[]
signals.append("\tsignal clk_s : std_logic := '0';\n")
+port_vector_count = 0
+
for item in input_port:
- signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
+ if port_vector_info[port_vector_count]:
+ signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
+ else:
+ signals.append("\tsignal "+item.split(':')[0]+": std_logic;\n")
+ port_vector_count += 1
+
#if item.split(":")[1] != '1':
# signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
#else:
@@ -667,7 +759,11 @@ for item in input_port:
for item in output_port:
- signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
+ if port_vector_info[port_vector_count]:
+ signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
+ else:
+ signals.append("\tsignal "+item.split(':')[0]+": std_logic;\n")
+ port_vector_count += 1
#if item.split(":")[1] != '1':
# signals.append("\tsignal "+item.split(':')[0]+": std_logic_vector("+str(int(item.split(':')[1])-int(1))+" downto 0);\n")
#else:
@@ -692,7 +788,7 @@ map.append("\t\t\t);")
tb_clk= "clk_s <= not clk_s after 5 us;\n\n"
#Adding Process block for Vhpi
process_Vhpi=[]
-process_Vhpi.append("\tprocess\n\t\tvariable sock_port : integer;\n\t\tbegin\n\t\tsock_port := sock_pkg_fun;\n\t\tVhpi_Initialize(sock_port);\n\t\twait until clk_s = '1';\n\t\twhile true loop\n\t\t\twait until clk_s = '0';\n\t\t\tVhpi_Listen;\n\t\t\twait for 1 us;\n\t\t\tVhpi_Send;\n\t\tend loop;\n\t\twait;\n\tend process;\n\n")
+process_Vhpi.append("\tprocess\n\t\tvariable sock_port : integer;\n\t\ttype string_ptr is access string;\n\t\tvariable sock_ip : string_ptr;\n\t\tbegin\n\t\tsock_port := sock_port_fun;\n\t\tsock_ip := new string'(sock_ip_fun);\n\t\tVhpi_Initialize(sock_port, Pack_String_To_Vhpi_String(sock_ip.all));\n\t\twait until clk_s = '1';\n\t\twhile true loop\n\t\t\twait until clk_s = '0';\n\t\t\tVhpi_Listen;\n\t\t\twait for 1 us;\n\t\t\tVhpi_Send;\n\t\tend loop;\n\t\twait;\n\tend process;\n\n")
#Adding process block
process=[]
process.append("\tprocess\n\n")
@@ -708,17 +804,28 @@ process.append("\tbegin\n")
process.append("\t\twhile true loop\n")
process.append("\t\t\twait until clk_s = '0';\n\n")
+port_vector_count = 0
+
for item in input_port:
process.append('\t\t\tobj_ref := Pack_String_To_Vhpi_String("'+item.split(':')[0]+'");\n')
process.append('\t\t\tVhpi_Get_Port_Value(obj_ref,'+item.split(':')[0]+'_v,'+item.split(':')[1]+');\n')
process.append('\t\t\tassert false report "Get port value '+item.split(':')[0]+' returns " &'+item.split(':')[0]+'_v severity note;\n')
- process.append('\t\t\t'+item.split(':')[0]+' <= Unpack_String('+item.split(':')[0]+'_v,'+item.split(':')[1]+');\n')
+ if port_vector_info[port_vector_count]:
+ process.append('\t\t\t'+item.split(':')[0]+' <= Unpack_String('+item.split(':')[0]+'_v,'+item.split(':')[1]+');\n')
+ else:
+ process.append('\t\t\t'+item.split(':')[0]+' <= To_Std_Logic('+item.split(':')[0]+'_v'+');\n')
+ port_vector_count += 1
process.append("\n")
process.append('\t\t\twait for 1 us;\n')
for item in output_port:
- process.append('\t\t\t'+item.split(':')[0]+'_v := Pack_String_To_Vhpi_String(Convert_SLV_To_String('+item.split(':')[0]+'));\n')
+ if port_vector_info[port_vector_count]:
+ process.append('\t\t\t'+item.split(':')[0]+'_v := Pack_String_To_Vhpi_String(Convert_SLV_To_String('+item.split(':')[0]+'));\n')
+ else:
+ process.append('\t\t\t'+item.split(':')[0]+'_v := Pack_String_To_Vhpi_String(To_String('+item.split(':')[0]+'));\n')
+ port_vector_count += 1
+
process.append('\t\t\tobj_ref := Pack_String_To_Vhpi_String("'+item.split(':')[0]+'");\n')
process.append('\t\t\tVhpi_Set_Port_Value(obj_ref,'+item.split(':')[0]+'_v,'+item.split(':')[1]+');\n')
process.append('\t\t\tassert false report "Set port value '+item.split(':')[0]+' returns " &'+item.split(':')[0]+'_v severity note;\n')
@@ -764,12 +871,9 @@ start_server = open('start_server.sh','w')
start_server.write("#!/bin/bash\n\n")
start_server.write("###This server run ghdl testebench for infinite time till ngspice send END signal to stop it\n\n")
-start_server.write("#gcc -c ghdlserver.c\n")
-start_server.write("#ghdl -a Utility_Package.vhdl &&\n")
-start_server.write("#ghdl -a Vhpi_Package.vhdl &&\n")
start_server.write("cd "+home+"/ngspice-nghdl/src/xspice/icm/ghdl/"+fname.split('.')[0]+"/DUTghdl/\n")
start_server.write("chmod 775 sock_pkg_create.sh &&\n")
-start_server.write("./sock_pkg_create.sh $1 &&\n")
+start_server.write("./sock_pkg_create.sh $1 $2 &&\n")
start_server.write("ghdl -a sock_pkg.vhdl &&\n")
start_server.write("ghdl -a "+fname+" &&\n")
start_server.write("ghdl -a "+fname.split('.')[0]+"_tb.vhdl &&\n")
@@ -783,21 +887,24 @@ start_server.close()
sock_pkg_create = open('sock_pkg_create.sh','w')
sock_pkg_create.write("#!/bin/bash\n\n")
-sock_pkg_create.write("##This file create sock_pkg_create.vhdl file and set the instance id from parameter based on parameter\n\n")
+sock_pkg_create.write("##This file creates sock_pkg.vhdl file and sets the port and ip from parameters passed to it\n\n")
sock_pkg_create.write("echo \"library ieee;\n")
sock_pkg_create.write("package sock_pkg is\n")
-sock_pkg_create.write("\tfunction sock_pkg_fun return integer;\n")
+sock_pkg_create.write("\tfunction sock_port_fun return integer;\n")
+sock_pkg_create.write("\tfunction sock_ip_fun return string;\n")
sock_pkg_create.write("end;\n\n")
-sock_pkg_create.write("\tpackage body sock_pkg is\n")
-sock_pkg_create.write("\t function sock_pkg_fun return integer is")
-sock_pkg_create.write("\t\tvariable sock_id : integer;\n")
+sock_pkg_create.write("package body sock_pkg is\n")
+sock_pkg_create.write("\tfunction sock_port_fun return integer is\n")
+sock_pkg_create.write("\t\tvariable sock_port : integer;\n")
sock_pkg_create.write("\t\t\tbegin\n")
-sock_pkg_create.write("\t\t\t\tsock_id := $1;\n")
-sock_pkg_create.write("\t\t\t\treturn sock_id;\n")
-sock_pkg_create.write("\t\t\tend function;\n")
-sock_pkg_create.write("\t\tend package body;\" > sock_pkg.vhdl")
-
-
-
-
-
+sock_pkg_create.write("\t\t\t\tsock_port := $1;\n")
+sock_pkg_create.write("\t\t\t\treturn sock_port;\n")
+sock_pkg_create.write("\t\t\tend function;\n\n")
+sock_pkg_create.write("\tfunction sock_ip_fun return string is\n")
+sock_pkg_create.write("\t\ttype string_ptr is access string;\n")
+sock_pkg_create.write("\t\tvariable sock_ip : string_ptr;\n")
+sock_pkg_create.write("\t\t\tbegin\n")
+sock_pkg_create.write('\t\t\t\tsock_ip := new string\'(\\"$2\\");\n')
+sock_pkg_create.write("\t\t\t\treturn sock_ip.all;\n")
+sock_pkg_create.write("\t\t\tend function;\n\n")
+sock_pkg_create.write("\t\tend package body;\" > sock_pkg.vhdl") \ No newline at end of file