summaryrefslogtreecommitdiff
path: root/sinter.c
diff options
context:
space:
mode:
authorTom Harley2020-01-08 20:17:50 +0000
committerTom Harley2020-01-08 23:47:14 +0000
commit505d8a2d364b3012455068d433ccec73cac38a50 (patch)
treeed7a4a58e0c02074c4fcf9ebc89954fef5c74330 /sinter.c
parentI should commit more (diff)
downloadsinter-505d8a2d364b3012455068d433ccec73cac38a50.tar.gz
sinter-505d8a2d364b3012455068d433ccec73cac38a50.zip

Add option to enable/disable boxing

Only affects atomic types, not structs. Accepts three options:

  • “-u always”: always boxes
  • “-u never”: never boxes
  • “-u smart”: inserts a comparison of sizes, and boxes only if the item is bigger than a pointer.

“smart” is smart in name only; I expected the comparison to be optimised away (since the sizes of the types are known at compile-time), but it seems to run significantly slower than the other options.

Steps to improve: - try making the comparison compile-time (or, if it already is, find out why it’s so slow);

Diffstat (limited to 'sinter.c')
-rw-r--r--sinter.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/sinter.c b/sinter.c
index 1021d86..0eaeb85 100644
--- a/sinter.c
+++ b/sinter.c
@@ -19,6 +19,8 @@ static char *input_filename;
static char *output_filename;
static format_t format;
+static boxing_rule_t boxing_rules;
+
extern FILE *yyin;
int yyparse(void);
@@ -71,7 +73,7 @@ void prologue() {
case LLVM_INTERMEDIATE:
case BITCODE:
case INTERPRET:
- llvm_codegen_prologue(input_filename);
+ llvm_codegen_prologue(input_filename, boxing_rules);
break;
case GRAPHVIZ:
@@ -133,9 +135,12 @@ int main(int argc, char **argv) {
output_filename = 0;
format = LLVM_INTERMEDIATE;
+ boxing_rules = ALWAYS_BOX;
verbose = 0;
- while ((c = getopt(argc, argv, "bghilo:qsv")) != -1) {
+ debug("\n");
+
+ while ((c = getopt(argc, argv, "bghilo:qsu:v")) != -1) {
switch (c) {
case 'b':
format = BITCODE;
@@ -146,17 +151,19 @@ int main(int argc, char **argv) {
break;
case 'h':
- printf( "usage: %s [options] <input_file>\n"
- "-b Specify bitcode-format output\n"
- "-c Compile mode\n"
- "-g Output a Graphviz .dot file\n"
- "-h Print this help message\n"
- "-i Interpret mode\n"
- "-l Specify human-readable output\n"
- "-o <output> Specify output filename\n"
- "-q Quiet (default)\n"
- "-s Output S-expression description\n"
- "-v Verbose\n",
+ printf(
+"usage: %s [options] <input_file>\n"
+"-b Specify bitcode-format output\n"
+"-c Compile mode\n"
+"-g Output a Graphviz .dot file\n"
+"-h Print this help message\n"
+"-i Interpret mode\n"
+"-l Specify human-readable output\n"
+"-o <output> Specify output filename\n"
+"-q Quiet (default)\n"
+"-s Output S-expression description\n"
+"-u <rule> Set the boxing rule: always, never, or smart\n"
+"-v Verbose\n",
argv[0]);
exit(0);
@@ -169,7 +176,7 @@ int main(int argc, char **argv) {
break;
case 'o':
- output_filename = optarg;
+ output_filename = strdup(optarg);
break;
case 'q':
@@ -180,6 +187,23 @@ int main(int argc, char **argv) {
format = SINTER;
break;
+ case 'u':
+ if (!strcmp(optarg, "always")) {
+ boxing_rules = ALWAYS_BOX;
+
+ } else if (!strcmp(optarg, "never")) {
+ boxing_rules = NEVER_BOX;
+
+ } else if (!strcmp(optarg, "smart")) {
+ boxing_rules = SMART_BOX;
+
+ } else {
+ error(INVALID_ARGUMENTS,
+ "%s is not a valid option for -u\n", optarg);
+
+ }
+ break;
+
case 'v':
verbose = 1;
break;