3D-ICE 3.0.0
floorplan_file_parser.c
1/******************************************************************************
2 * This file is part of 3D-ICE, version 3.1.0 . *
3 * *
4 * 3D-ICE is free software: you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free *
6 * Software Foundation, either version 3 of the License, or any later *
7 * version. *
8 * *
9 * 3D-ICE is distributed in the hope that it will be useful, but WITHOUT *
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
12 * more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along *
15 * with 3D-ICE. If not, see <http://www.gnu.org/licenses/>. *
16 * *
17 * Copyright (C) 2021 *
18 * Embedded Systems Laboratory - Ecole Polytechnique Federale de Lausanne *
19 * All Rights Reserved. *
20 * *
21 * Authors: Arvind Sridhar Alessandro Vincenzi *
22 * Giseong Bak Martino Ruggiero *
23 * Thomas Brunschwiler Eder Zulian *
24 * Federico Terraneo Darong Huang *
25 * Luis Costero Marina Zapater *
26 * David Atienza *
27 * *
28 * For any comment, suggestion or request about 3D-ICE, please register and *
29 * write to the mailing list (see http://listes.epfl.ch/doc.cgi?liste=3d-ice) *
30 * Any usage of 3D-ICE for research, commercial or other purposes must be *
31 * properly acknowledged in the resulting products or publications. *
32 * *
33 * EPFL-STI-IEL-ESL Mail : 3d-ice@listes.epfl.ch *
34 * Batiment ELG, ELG 130 (SUBSCRIPTION IS NECESSARY) *
35 * Station 11 *
36 * 1015 Lausanne, Switzerland Url : http://esl.epfl.ch/3d-ice *
37 ******************************************************************************/
38
39#include <stdio.h> // For the file type FILE
40
42
43#include "../bison/floorplan_parser.h"
44#include "../flex/floorplan_scanner.h"
45
46// From Bison manual:
47// The value returned by yyparse is 0 if parsing was successful (return is
48// due to end-of-input). The value is 1 if parsing failed (return is due to
49// a syntax error).
50
51extern int floorplan_parser_parse
52
53 (Floorplan_t *floorplan, Dimensions_t *dimensions, yyscan_t scanner) ;
54
55/******************************************************************************/
56
58(
59 String_t filename,
60 Floorplan_t *floorplan,
61 Dimensions_t *dimensions
62)
63{
64 FILE *input ;
65 int result ;
66 yyscan_t scanner ;
67
68 input = fopen (filename, "r") ;
69
70 if (input == NULL)
71 {
72 fprintf (stderr, "Unable to open floorplan file %s\n", filename) ;
73
74 return TDICE_FAILURE ;
75 }
76
77 string_copy (&floorplan->FileName, &filename) ; // FIXME memory leak
78
79 floorplan_parser_lex_init (&scanner) ;
80 floorplan_parser_set_in (input, scanner) ;
81 //floorplan_set_debug (1, scanner) ;
82
83 result = floorplan_parser_parse (floorplan, dimensions, scanner) ;
84
85 floorplan_parser_lex_destroy (scanner) ;
86 fclose (input) ;
87
88 if (result == 0)
89
90 return TDICE_SUCCESS ;
91
92 else
93
94 return TDICE_FAILURE ;
95}
96
97/******************************************************************************/
98
100(
101 String_t filename,
102 Floorplan_t *floorplan
103)
104{
105 FILE *out = fopen (filename, "w") ;
106
107 if (out == NULL)
108 {
109 fprintf (stderr, "Unable to open stack file %s\n", filename) ;
110
111 return TDICE_FAILURE ;
112 }
113
114 floorplan_print (floorplan, out, (String_t) "") ;
115
116 fclose (out) ;
117
118 return TDICE_SUCCESS ;
119}
120
121/******************************************************************************/
122
void floorplan_print(Floorplan_t *floorplan, FILE *stream, String_t prefix)
Definition: floorplan.c:152
Error_t generate_floorplan_file(String_t filename, Floorplan_t *floorplan)
Error_t parse_floorplan_file(String_t filename, Floorplan_t *floorplan, Dimensions_t *dimensions)
char * String_t
Definition: string_t.h:55
void string_copy(String_t *dst, String_t *src)
Definition: string_t.c:53
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
The floorplan representing the IC as a set of floorplan elements.
Definition: floorplan.h:69
String_t FileName
Definition: floorplan.h:72
Error_t
Definition: types.h:401
@ TDICE_SUCCESS
The function returns with success.
Definition: types.h:402
@ TDICE_FAILURE
The function retuerns with a generic error.
Definition: types.h:403