GCC back-end and Assembly release (46)

Source: Internet
Author: User
16. gengenrtl tool 16.1. Overview

This tool generates genrtl. h and genrtl. c from RTL. Def. These output files provide functions that generate various RTL objects according to the definitions in the RTL. Def file.

 

340Int

341Main (INT argc, char ** argv) inGengenrtl. c

342{

343Find_formats ();

344Genlegend ();

345

346If (argc = 2 & argv [1] [0] = '-' & argv [1] [1] = 'H ')

347Genheader ();

348Else

349Gencode ();

350

351If (ferror (stdout) | fflush (stdout) | fclose (stdout ))

352Return fatal_exit_code;

353

354Return success_exit_code;

355}

 

As for the RTX format, the details are as follows:

"*" Is not defined and can cause a warning message.

The "0" domain is not used (or used in a dependency phase) and does not output anything.

"I" is an integer that outputs this integer.

Ø "N" is similar to "I", but it outputs items from note_insn_name

Ø "W" is an integer whose width is host_bits_per_wide_int. This integer is output.

Ø "S" a string pointer to output this string

Ø "S" is similar to "S", but optional: The contained RTX may end before this operand.

"T" is similar to "S", but it is specially processed by RTL reader; it only appears in the machine description mode.

Ø "E" refers to a RTL expression pointer and outputs this expression.

Ø "E" refers to a pointer to several RTL expressions and outputs the RTL expression list.

Ø "v" is similar to "E", but optional: The contained RTX may end before this operand.

Ø "U" refers to a pointer pointing to other commands and outputs the UID of this command.

"B" refers to a pointer to the Bitmap header.

"B" is a pointer to a basic block.

"T" is a tree pointer.

 

165Static void

166Find_formats (void) inGengenrtl. c

167{

168Unsigned int I;

169

170For (I = 0; I <num_rtx_code; I ++)

171{

172Const char ** F;

173

174If (special_format (Defs[I]. Format ))

175Continue;

176

177For (F =Formats; * F; F ++)

178If (! Strcmp (* F,Defs[I]. Format ))

179Break;

180

181If (* f = 0)

182* F =Defs[I]. format;

183}

184}

 

In the 174 rowsDefsThe definition is as follows. It is extended from RTL. Def.

 

36# Definedef_rtl_expr (Enum, name, format, class) {# Enum, name, format },

37

38Static const structrtx_definition defs [] =

39{

40# Include "RTL. Def"/* rtlexpressions are supported ented here */

41};

 

26Struct rtx_definition

27{

28Const char * constenumname, * const name, * const format;

29};

 

130Static int

131Special_format (const char * FMT) inGengenrtl. c

132{

133Return (strchr (FMT ,'*')! = 0

134| Strchr (FMT, 'V ')! = 0

135| Strchr (FMT,'s ')! = 0

136| Strchr (FMT, 'n ')! = 0 );

137}

16.2. Output genrtl. h

ExceptSpecial_formatThe filtered format will be saved inFormat. Genrtl. hGenheaderGenerate.

 

296Static void

297Genheader (void) inGengenrtl. c

298{

299Unsigned int I;

300Const char ** FMT;

301

302Puts ("# ifndef gcc_genrtl_h ");

303Puts ("# define gcc_genrtl_h \ n ");

304

305For (FMt =Formats; * FMT; ++ FMT)

306Gendecl (* FMT );

307

308Putchar ('\ n ');

309

310For (I = 0; I <num_rtx_code; I ++)

311If (! Special_format (Defs[I]. Format ))

312Genmacro (I );

313

314Puts ("\ n # endif/* gcc_genrtl_h */");

315}

 

Note that in the above 306 rows, the format must passSpecial_format.GendeclGenerate the declaration of the RTX generation function.

 

188Static void

189Gendecl (const char * Format) inGengenrtl. c

190{

191Const char * P;

192Int I, Pos;

193

194Printf ("externrtx gen_rtx_fmt _ % s \ t (rtx_code,", format );

195Printf ("Enum machine_modemode ");

196

197/* Write each parameter that is needed andstart a new line when the line

198Wocould overflow .*/

199For (P = format, I = 0, Pos = 75; * P! = 0; P ++)

200If (* P! = '0 ')

201{

202Int ourlen = strlen (type_from_format (* p) + 6 + (I> 9 );

203

204Printf (",");

205If (Pos + ourlen> 76)

206Printf ("\ n \ t"), Pos = 39;

207

208Printf ("% Sarg % d", type_from_format (* P), I ++ );

209Pos + = ourlen;

210}

211

212Printf ("); \ n ");

213}

 

Type_from_formatMap the RTX format to the corresponding C type.

 

61Static const char *

62Type_from_format (int c) inGengenrtl. c

63{

64Switch (c)

65{

66Case 'I ':

67Return "int ";

68

69Case 'W ':

70Return "host_wide_int ";

71

72Case's ':

73Return "const char *";

74

75Case 'E': Case 'U ':

76Return "RTX ";

77

78Case 'E ':

79Return "rtvec ";

80Case 'B ':

81Return "struct bitmap_head_def *";/* Bitmap-typedef not available */

82Case 'T ':

83Return "Union tree_node *";/* tree-typedef not available */

84Case 'B ':

85Return "struct basic_block_def *";/* Basic Block-typedef not available */

86Default:

87Abort ();

88}

89}

 

As for the definition of def_rtl_expr, Enum will be outputRtx_codeWhile most of the time the RTX object is built during compilation,Rtx_codeWill be specified for the constructed object. ThereforeGenmacroFor the RTX object to be constructedRtx_code, Output macro.

 

218Static void

219Genmacro (INT idx) inGengenrtl. c

220{

221Const char * P;

222Int I;

223

224/* We write a macro that definesgen_rtx_rtlcode to be an equivalent

225Gen_rtx_fmt_format where format is thertx_format of rtlcode .*/

226

227If (excluded_rtx (idx ))

228/* Don't define a macro for this code .*/

229Return;

230

231Printf ("# define gen_rtx _ % S % s (mode ",

232Special_rtx (idx )? "Raw _":"",
Defs[Idx]. enumname );

233

234For (P =Defs[Idx]. format, I = 0; * P! = 0; P ++)

235If (* P! = '0 ')

236Printf (", Arg % d", I ++ );

237

238Printf (") \ n gen_rtx_fmt _ % s (% s, (mode )",

239 defs[Idx]. format,Defs[Idx]. enumname );

240

241For (P =Defs[Idx]. format, I = 0; * P! = 0; P ++)

242If (* P! = '0 ')

243Printf (", (ARG % d)", I ++ );

244

245Puts (")");

246}

 

The details of special_rtx are as follows.

 

143Static int

144Special_rtx (INT idx) inGengenrtl. c

145{

146Return (strcmp (Defs[Idx]. enumname, "const_int") = 0

147| Strcmp (Defs[Idx]. enumname, "Reg") = 0

148| Strcmp (Defs[Idx]. enumname, "subreg") = 0

149| Strcmp (Defs[Idx]. enumname, "mem") = 0

150| Strcmp (Defs[Idx]. enumname, "const_vector") = 0 );

151}

16.3. Output genrtl. c

Function Definition for constructing RTX objectsGencodeGenerate.

 

319Static void

320Gencode (void) inGengenrtl. c

321{

322Const char ** FMT;

323

324Puts ("# include \" config. h \"");

325Puts ("# include \" system. h \"");

326Puts ("# include \" coretypes. h \"");

327Puts ("# include \" TM. h \"");

328Puts ("# include \" obstack. h \"");

329Puts ("# include \" RTL. h \"");

330Puts ("# include \" GGC. h \ "\ n ");

331

332For (FMt =Formats; * FMT! = 0; FMT ++)

333Gendef (* FMT );

334}

 

For common format objects only, build functions are defined.

 

251Static void

252Gendef (const char * Format) in
Gengenrtl. c

253{

254Const char * P;

255Int I, J;

256

257/* Start by writing the definition of thefunction NAME AND THE TYPES

258Of thearguments .*/

259

260Printf ("RTX \ ngen_rtx_fmt _ % s (rtx_code, Enum machine_mode mode", format );

261For (P = format, I = 0; * P! = 0; P ++)

262If (* P! = '0 ')

263Printf (", \ n \ t % Sarg % d", type_from_format (* P), I ++ );

264

265Puts (")");

266

267/* Now write out the body of the functionitself, which allocates

268The memory and initializes it .*/

269Puts ("{");

270Puts ("rtx rt ;");

271Puts ("RT = ggc_alloc_rtx (CODE); \ n ");

272

273Puts ("memset (RT, 0, rtx_hdr_size); \ n ");

274Puts ("put_code (RT, Code );");

275Puts ("put_mode (RT, mode );");

276

277For (P = format, I = J = 0; * P; ++ P, ++ I)

278If (* P! = '0 ')

279Printf ("% s (RT, % d) = Arg % d; \ n ",
Accessor_from_format (* P), I, j ++ );

280Else

281Printf ("x0exp (RT, % d) = null_rtx; \ n", I );

282

283Puts ("\ n returnrt; \ n} \ n ");

284}

 

Accessor_from_formatMap the format to the RTX macro that accesses them.

 

93Static const char *

94Accessor_from_format (int c) in
Gengenrtl. c

95{

96Switch (c)

97{

98Case 'I ':

99Return "xint ";

100

101Case 'W ':

102Return "xwint ";

103

104Case's ':

105Return "xstr ";

106

107Case 'E': Case 'U ':

108Return "xexp ";

109

110Case 'E ':

111Return "xvec ";

112

113Case 'B ':

114Return "xbitmap ";

115

116Case 'T ':

117Return "xtree ";

118

119Case 'B ':

120Return "xbbdef ";

121

122Default:

123Abort ();

124}

125}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.