summaryrefslogtreecommitdiff
path: root/src/model_generation.py
diff options
context:
space:
mode:
authorfossee2019-09-18 17:25:18 +0530
committerfossee2019-09-18 17:25:18 +0530
commite43b6221138d30d9b2ea37c708c9521d4ba926af (patch)
tree67007cb0a3b4f004fe395fdfabbd6c7f64f3f6f6 /src/model_generation.py
parent13b65c2e7ef066d2481e384352402de7cd9ff7fe (diff)
downloadnghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.tar.gz
nghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.tar.bz2
nghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.zip
support for multiple ghdl models
Diffstat (limited to 'src/model_generation.py')
-rw-r--r--src/model_generation.py87
1 files changed, 79 insertions, 8 deletions
diff --git a/src/model_generation.py b/src/model_generation.py
index 772cbb5..40a4b4a 100644
--- a/src/model_generation.py
+++ b/src/model_generation.py
@@ -143,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='''
@@ -217,6 +217,8 @@ systime_info='''
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");
@@ -233,13 +235,80 @@ for item in output_port:
els_evt_count1=els_evt_count1+1
-client_setup='''
- /* Client setup */
- //Default hostname assignment
- host = gethostbyname("127.0.0.1");
+client_setup_ip='''
+ /* Client Setup IP Addr */
+ FILE *fptr;
+ int ip_count = 0;
+ char my_ip[20];
+
+ fptr = fopen("/tmp/NGHDL_COMMON_IP.txt", "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("/tmp/NGHDL_COMMON_IP.txt", "a");
+ if (fptr)
+ {
+ fprintf(fptr, "%s\\n", my_ip);
+ fclose(fptr);
+ } else {
+ perror("fopen() - Common IP");
+ exit(1);
+ }
+
+
+ char ip_filename[300];
+'''
+client_setup_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");'
+client_setup_ip +='''
+ fptr = fopen(ip_filename, "w");
+ if(fptr)
+ {
+ fprintf(fptr, "%s\\n", my_ip);
+ fclose(fptr);
+ } else {
+ perror("fopen() - IP file");
+ exit(1);
+ }
+'''
+
+client_fetch_ip='''
+ /* Client Fetch IP Addr */
+
+ char lo_ip[20];
+ char ip_filename[300];
+'''
+client_fetch_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");\n'
+client_fetch_ip +='''
+ FILE* fp = fopen(ip_filename, "r");
+ if (fp)
+ {
+ if (fscanf(fp, "%s", lo_ip) != EOF)
+ {
+ fclose(fp);
+ }
+ } else {
+ perror("fopen() - NGHDL_IP file");
+ exit(1);
+ }
+
+ host = gethostbyname(lo_ip);
printf("Client-Creating Client 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)
@@ -471,10 +540,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(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 &",sock_port);\n')
cfunc.write('\t\tsystem(command);')
-cfunc.write("\t}")
+cfunc.write("\n\t}")
cfunc.write("\n")
cfunc.write("\telse\n\t{\n")
@@ -484,7 +555,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)