GCC's bacl-end & assemble emission (46)

Source: Internet
Author: User
16. toolof gengenrtl16.1. Overview

This tool generates genrtl. h and genrtl. c from RTL. Def. The outputfiles give the functions to generate various RTL objects following thedefinitions in the file RTL. Def.

 

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}

 

For the format of RTX, the detail is as following.

Ø "*" undefined. cancause a warning message

Ø "0" field is unused (or used in a phase-dependent manner) prints nothing

Ø "I" an integer printsthe integer

Ø "N" like "I", but prints entries from 'note _ insn_name'

Ø "W" an integer ofwidth host_bits_per_wide_int prints the integer

Ø "S" a pointer to astring prints the string

Ø "S" like "S", but optional: The containing RTX may end before this operand

Ø "T" like "S", but treated specially by the RTL reader; only found in machinedescription patterns.

Ø "E" a pointer to anrtl expression prints the expression

Ø "E" a pointer to avector that points to a number of RTL expressions prints a list of the rtlexpressions

Ø "v" like "E", but optional: The containing RTX may end before this operand

Ø "U" A pointer toanother insn prints the UID of the insn.

Ø "B" is a pointer to abitmap header.

Ø "B" is a basic blockpointer.

Ø "T" is a treepointer.

 

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}

 

DefsAt line 174 is defined as following. It is expanded 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

Formats lost t those filtered outSpecial_formatWill be saved
Format. Genrtl. H is producedGenheader.

 

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}

 

Notice that at line 306 above, formats must passSpecial_format.GendeclGeneratesthe declaration of the rtx generation functions.

 

188Static void

189Gendecl (const char * Format) inGengenrtl. c

190{

191Constchar * P;

192Int I, Pos;

193

194Printf ("extern rtxgen_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_formatMaps the RTX format to the corresponding C types.

 

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}

 

For def_rtl_expr definition, Enum will be outputRtx_code, While creating RTX object during compilation, most of time,
Rtx_codeWill be specified for the object created. SoGenmacroWill Output Macros for creatingrtx object according
Rtx_code.

 

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 detail of special_rtx is asfollowing.

 

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

The definition of functions creating RTX object are producedGencode.

 

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}

 

Only for normal format object, will define the creation functions.

 

251Static void

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

253{

254Const char * P;

255Int I, J;

256

257/* Start by writing the definition of the functionname 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_formatMaps RTX accessing macros with their formats.

 

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.