Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
  2. (.text+0x18): undefined reference to `main'
  3. /tmp/ccjmG33v.o: In function `plugin_init':
  4. plugin.c:(.text+0x9e): undefined reference to `register_callback'
  5. plugin.c:(.text+0xc6): undefined reference to `register_callback'
  6. collect2: ld returned 1 exit status
  7. make: *** [plugin.o] Error 1
  8.  
  9. PLUGINS_DIR = /usr/lib/gcc/i686-linux-gnu/4.6/plugin/include
  10.  
  11. INCLUDES =
  12. -I$(PLUGINS_DIR)
  13.  
  14. DEFINES = -Dbool=int -DTRUE=1 -DFALSE=0
  15.  
  16. plugin.so : plugin.o
  17. gcc -shared -Wl,-export-dynamic -o plugin.so plugin.o
  18.  
  19. %.o : %.c
  20. gcc $(DEFINES) $(INCLUDES) -fPIC -o $@ $^
  21.  
  22. clean :
  23. rm *.o *.so
  24.  
  25. #include <aspell.h>
  26. #include <gcc-plugin.h>
  27. #include <coretypes.h>
  28. #include <diagnostic.h>
  29. #include <gimple.h>
  30. #include <tree.h>
  31. #include <tree-flow.h>
  32. #include <tree-pass.h>
  33.  
  34.  
  35.  
  36.  
  37. #define is_alpha(c) (((c)>64 && (c)<91) || ((c)>96 && (c)<123))
  38.  
  39.  
  40. int plugin_is_GPL_compatible = 1;
  41. static AspellSpeller *speller_g;
  42.  
  43.  
  44. /* Help info about the plugin if one were to use gcc's --version --help */
  45. static struct plugin_info speller_info =
  46. {
  47. .version = "42",
  48. .help = "Hahahaha yeaaaaa....",
  49. };
  50.  
  51.  
  52. static struct plugin_gcc_version speller_ver =
  53. {
  54. .basever = "4.6",
  55. };
  56.  
  57.  
  58. /* We don't need to run any tests before we execute our plugin pass */
  59. static bool speller_gate(void)
  60. {
  61. return true;
  62. }
  63.  
  64.  
  65. static const_tree is_str_cst(const_tree node)
  66. {
  67. /*
  68. const_tree str = node;
  69.  
  70. // Filter out types we are ignoring
  71. if (TREE_CODE(str) == VAR_DECL)
  72. {
  73. if (!(str = DECL_INITIAL(node)))
  74. return NULL_TREE;
  75. else if (TREE_OPERAND_LENGTH(str))
  76. str = TREE_OPERAND(str, 0);
  77. }
  78. else if (TREE_CODE(str) == ADDR_EXPR &&
  79. TREE_OPERAND_LENGTH(str) > 0)
  80. str = TREE_OPERAND(str, 0);
  81.  
  82. if (TREE_CODE(str) != STRING_CST &&
  83. TREE_OPERAND_LENGTH(str) > 0)
  84. str = TREE_OPERAND(str, 0);
  85.  
  86. if (TREE_CODE(str) != STRING_CST)
  87. return NULL_TREE;
  88. else
  89. return str;
  90. */
  91. }
  92.  
  93.  
  94. static AspellSpeller *init_spellchecker(void)
  95. {
  96. /*
  97. AspellConfig *cfg;
  98. AspellCanHaveError *err;
  99.  
  100. // Configure and instantiate a spell checker
  101. cfg = new_aspell_config();
  102. aspell_config_replace(cfg, "lang", "en_US");
  103. err = new_aspell_speller(cfg);
  104. if (aspell_error_number(err) != 0)
  105. {
  106. puts(aspell_error_message(err));
  107. return NULL;
  108. }
  109.  
  110. return to_aspell_speller(err);
  111. */
  112. }
  113.  
  114.  
  115. static void spell_check(const_gimple stmt, const_tree str)
  116. {
  117. /*
  118. char buf[32] = {0};
  119. const char *data, *end;
  120.  
  121. data = TREE_STRING_POINTER(str);
  122. printf("Spell checking string: '%s'n", data);
  123.  
  124. while (*data)
  125. {
  126. // Skip non alphas including whitespace
  127. while (!is_alpha(data[0]))
  128. {
  129. if (data[0] == '')
  130. return;
  131. ++data;
  132. }
  133.  
  134. // Find the end of the word
  135. end = data;
  136. while (is_alpha(end[0]))
  137. ++end;
  138.  
  139. if ((end - data) > sizeof(buf))
  140. return;
  141.  
  142. memcpy(buf, data, end - data);
  143. buf[end-data] = '';
  144. if (!(aspell_speller_check(speller_g, buf, end - data)))
  145. warning_at(gimple_location(stmt), 0, "%s (bad spelling)", buf);
  146. data = end;
  147. }
  148. */
  149. }
  150.  
  151.  
  152. static unsigned speller_exec(void)
  153. {
  154. /*
  155. unsigned i;
  156. const_tree str, op;
  157. basic_block bb;
  158. gimple stmt;
  159. gimple_stmt_iterator gsi;
  160.  
  161. FOR_EACH_BB(bb)
  162. for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
  163. {
  164. stmt = gsi_stmt(gsi);
  165. for (i=0; i<gimple_num_ops(stmt); ++i)
  166. if ((op = gimple_op(stmt, i)) && (str = is_str_cst(op)))
  167. spell_check(stmt, str);
  168. }
  169.  
  170. return 0;
  171. */
  172. }
  173.  
  174.  
  175. /* See tree-pass.h for a list and desctiptions for the fields of this struct */
  176. static struct gimple_opt_pass speller_pass =
  177. {
  178. .pass.type = GIMPLE_PASS,
  179. .pass.name = "speller", /* For use in the dump file */
  180. .pass.gate = speller_gate,
  181. .pass.execute = speller_exec, /* Pass handler/callback */
  182. };
  183.  
  184.  
  185. /* Return 0 on success or error code on failure */
  186. int plugin_init(struct plugin_name_args *info, /* Argument infor */
  187. struct plugin_gcc_version *ver) /* Version of GCC */
  188. {
  189. struct register_pass_info pass;
  190.  
  191. if (strncmp(ver->basever, speller_ver.basever, strlen("4.6")))
  192. return -1; /* Incorrect version of gcc */
  193.  
  194. pass.pass = &speller_pass.pass;
  195. pass.reference_pass_name = "ssa";
  196. pass.ref_pass_instance_number = 1;
  197. pass.pos_op = PASS_POS_INSERT_AFTER;
  198.  
  199. /* Tell gcc we want to be called after the first SSA pass */
  200. register_callback("speller", PLUGIN_PASS_MANAGER_SETUP, NULL, &pass);
  201. register_callback("speller", PLUGIN_INFO, NULL, &speller_info);
  202.  
  203. /* Initilize our spell checker */
  204. if (!(speller_g = init_spellchecker()))
  205. return -1;
  206.  
  207. return 0;
  208. }
  209.  
  210. %.o : %.c
  211. gcc $(DEFINES) $(INCLUDES) -fPIC -o $@ -c $^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement