Browse Source

Add mode() for types

Peter Colberg 3 years ago
parent
commit
49b7e8d9cb
4 changed files with 26 additions and 2 deletions
  1. 4
    1
      doc/reference.html
  2. 7
    1
      doc/reference.mdwn
  3. 13
    0
      gcc/gcclua.c
  4. 2
    0
      test/tree.lua

+ 4
- 1
doc/reference.html View File

@@ -122,7 +122,7 @@ gcc<span class="ot">.</span>define_macro<span class="ot">(</span><span class="st
122 122
 </dd>
123 123
 </dl>
124 124
 <h2 id="tree-nodes">Tree Nodes</h2>
125
-<p>Any <a href="http://gcc.gnu.org/onlinedocs/gccint/GENERIC.html">tree node</a> provides the following methods:</p>
125
+<p>Any <a href="https://gcc.gnu.org/onlinedocs/gccint/GENERIC.html">tree node</a> provides the following methods:</p>
126 126
 <dl>
127 127
 <dt><code>node:class()</code></dt>
128 128
 <dd><p>Returns tree code class as a string.</p>
@@ -282,6 +282,9 @@ gcc<span class="ot">.</span>define_macro<span class="ot">(</span><span class="st
282 282
 <dd><p>Returns tree node of main variant of type.</p>
283 283
 <p>The main variant excludes qualifiers.</p>
284 284
 </dd>
285
+<dt><code>node:mode()</code></dt>
286
+<dd><p>Returns <a href="https://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html">machine mode</a> as a string.</p>
287
+</dd>
285 288
 <dt><code>node:name()</code></dt>
286 289
 <dd><p>Returns tree node of type name.</p>
287 290
 </dd>

+ 7
- 1
doc/reference.mdwn View File

@@ -121,7 +121,7 @@ Any [tree node] provides the following methods:
121 121
 
122 122
   : Returns tree code as a string.
123 123
 
124
-[tree node]: http://gcc.gnu.org/onlinedocs/gccint/GENERIC.html
124
+[tree node]: https://gcc.gnu.org/onlinedocs/gccint/GENERIC.html
125 125
 
126 126
 
127 127
 ### Declarations
@@ -308,6 +308,10 @@ This tree code class is used for type objects.
308 308
 
309 309
         The main variant excludes qualifiers.
310 310
 
311
+    `node:mode()`
312
+
313
+      : Returns [machine mode] as a string.
314
+
311 315
     `node:name()`
312 316
 
313 317
       : Returns tree node of type name.
@@ -456,6 +460,8 @@ This tree code class is used for type objects.
456 460
 
457 461
           : Returns number of vector elements.
458 462
 
463
+[machine mode]: https://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html
464
+
459 465
 
460 466
 ### Constants
461 467
 

+ 13
- 0
gcc/gcclua.c View File

@@ -25,6 +25,7 @@
25 25
 #endif
26 26
 #if GCCPLUGIN_VERSION >= 4009
27 27
 #include "stringpool.h"
28
+#include "stor-layout.h"
28 29
 #endif
29 30
 #ifdef __cplusplus
30 31
 extern "C" {
@@ -757,6 +758,17 @@ static int gcclua_tree_get_type_min_value(lua_State *L)
757 758
   return 1;
758 759
 }
759 760
 
761
+static int gcclua_tree_get_type_mode(lua_State *L)
762
+{
763
+  const tree *t;
764
+  machine_mode mode;
765
+  luaL_checktype(L, 1, LUA_TUSERDATA);
766
+  t = (const tree *)lua_touserdata(L, 1);
767
+  mode = TYPE_MODE(*t);
768
+  lua_pushstring(L, GET_MODE_NAME(mode));
769
+  return 1;
770
+}
771
+
760 772
 static int gcclua_tree_get_type_name(lua_State *L)
761 773
 {
762 774
   const tree *t;
@@ -1133,6 +1145,7 @@ static const luaL_Reg gcclua_type[] = {
1133 1145
   {"canonical",    gcclua_tree_get_type_canonical},
1134 1146
   {"const",        gcclua_tree_get_type_const},
1135 1147
   {"main_variant", gcclua_tree_get_type_main_variant},
1148
+  {"mode",         gcclua_tree_get_type_mode},
1136 1149
   {"name",         gcclua_tree_get_type_name},
1137 1150
   {"packed",       gcclua_tree_get_type_packed},
1138 1151
   {"restrict",     gcclua_tree_get_type_restrict},

+ 2
- 0
test/tree.lua View File

@@ -410,6 +410,7 @@ function test.vector_2_of_double(decl)
410 410
   assert(decl:type():type():name():class() == "declaration")
411 411
   assert(decl:type():type():name():code() == "type_decl")
412 412
   assert(decl:type():type():name():name():value() == "double")
413
+  assert(decl:type():type():mode() == "DF")
413 414
   assert(decl:type():size():class() == "constant")
414 415
   assert(decl:type():size():code() == "integer_cst")
415 416
   assert(decl:type():size():value() == 128)
@@ -429,6 +430,7 @@ function test.vector_8_of_int(decl)
429 430
   assert(decl:type():type():name():class() == "declaration")
430 431
   assert(decl:type():type():name():code() == "type_decl")
431 432
   assert(decl:type():type():name():name():value() == "int")
433
+  assert(decl:type():type():mode() == "SI")
432 434
   assert(decl:type():size():class() == "constant")
433 435
   assert(decl:type():size():code() == "integer_cst")
434 436
   assert(decl:type():size():value() == 256)

Loading…
Cancel
Save