3D-ICE 3.0.0
stack_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
41#include "stack_file_parser.h"
42
43#include "../bison/stack_description_parser.h"
44#include "../flex/stack_description_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 stack_description_parse
52(
54 Analysis_t *analysis,
55 Output_t *output,
56 yyscan_t scanner
57) ;
58
59/******************************************************************************/
60
62(
63 String_t filename,
65 Analysis_t *analysis,
66 Output_t *output
67)
68{
69 FILE* input ;
70 int result ;
71 yyscan_t scanner ;
72
73 input = fopen (filename, "r") ;
74 if (input == NULL)
75 {
76 fprintf (stderr, "Unable to open stack file %s\n", filename) ;
77
78 return TDICE_FAILURE ;
79 }
80
81 string_copy (&stkd->FileName, &filename) ; // FIXME memory leak
82
83 stack_description_lex_init (&scanner) ;
84 stack_description_set_in (input, scanner) ;
85
86 result = stack_description_parse (stkd, analysis, output, scanner) ;
87
88 stack_description_lex_destroy (scanner) ;
89 fclose (input) ;
90
91// From Bison manual:
92// The value returned by yyparse is 0 if parsing was successful (return is
93// due to end-of-input). The value is 1 if parsing failed (return is due to
94// a syntax error).
95
96 if (result == 0)
97
98 return TDICE_SUCCESS ;
99
100 else
101
102 return TDICE_FAILURE ;
103}
104
105/******************************************************************************/
106
108(
109 String_t filename,
110 StackDescription_t *stkd,
111 Analysis_t *analysis,
112 Output_t *output
113)
114{
115 FILE *out = fopen (filename, "w") ;
116
117 if (out == NULL)
118 {
119 fprintf (stderr, "Unable to open stack file %s\n", filename) ;
120
121 return TDICE_FAILURE ;
122 }
123
124 stack_description_print (stkd, out, (String_t) "") ;
125
126 fprintf (out, "\n") ;
127
128 analysis_print (analysis, out, (String_t) "") ;
129
130 fprintf (out, "\n") ;
131
132 output_print (output, out, (String_t) "") ;
133
134 fclose (out) ;
135
136 return TDICE_SUCCESS ;
137}
138
139/******************************************************************************/
void analysis_print(Analysis_t *analysis, FILE *stream, String_t prefix)
Definition: analysis.c:123
void output_print(Output_t *output, FILE *stream, String_t prefix)
Definition: output.c:134
void stack_description_print(StackDescription_t *stkd, FILE *stream, String_t prefix)
Error_t parse_stack_description_file(String_t filename, StackDescription_t *stkd, Analysis_t *analysis, Output_t *output)
Error_t generate_stack_description_file(String_t filename, StackDescription_t *stkd, Analysis_t *analysis, Output_t *output)
char * String_t
Definition: string_t.h:55
void string_copy(String_t *dst, String_t *src)
Definition: string_t.c:53
Informations about the type of thermal simulation to be run, timing and its initial settings.
Definition: analysis.h:65
Informations about the type of thermal simulation to be run and its initial settings.
Definition: output.h:69
Structure containing all the informations related to the 3d stack.
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