self->ir_v = func->value;
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->expression.flags & AST_FLAG_ERASEABLE)
+ self->ir_v->flags |= IR_FLAG_ERASEABLE;
/* The function is filled later on ast_function_codegen... */
return true;
}
v->unique_life = true;
v->locked = true;
array->ir_v = self->ir_v = v;
+
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->expression.flags & AST_FLAG_ERASEABLE)
+ self->ir_v->flags |= IR_FLAG_ERASEABLE;
namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16);
self->ir_v = v;
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+
+ if (self->expression.flags & AST_FLAG_ERASEABLE)
+ self->ir_v->flags |= IR_FLAG_ERASEABLE;
}
return true;
}
v->context = ast_ctx(self);
v->unique_life = true;
v->locked = true;
+
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
v->flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->expression.flags & AST_FLAG_ERASEABLE)
+ self->ir_v->flags |= IR_FLAG_ERASEABLE;
namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16);
/* link us to the ir_value */
v->cvq = self->cvq;
self->ir_v = v;
+
if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->expression.flags & AST_FLAG_ERASEABLE)
+ self->ir_v->flags |= IR_FLAG_ERASEABLE;
/* initialize */
if (self->hasvalue) {
#define AST_FLAG_INCLUDE_DEF (1<<5)
#define AST_FLAG_IS_VARARG (1<<6)
#define AST_FLAG_ALIAS (1<<7)
+#define AST_FLAG_ERASEABLE (1<<8)
/* An array declared as []
* so that the size is taken from the initializer */
-#define AST_FLAG_ARRAY_INIT (1<<8)
+#define AST_FLAG_ARRAY_INIT (1<<9)
#define AST_FLAG_TYPE_MASK (AST_FLAG_VARIADIC | AST_FLAG_NORETURN)
/* Value
"__builtin_" NAME, \
(VALUE) \
); \
+ (VALUE)->expression.flags |= AST_FLAG_ERASEABLE; \
} while (0)
#define INTRIN_REG(FUNC, VALUE) \
if (irfun->builtin)
return true;
+ /*
+ * If there is no definition and the thing is eraseable, we can ignore
+ * outputting the function to begin with.
+ */
+ if (global->flags & IR_FLAG_ERASEABLE && irfun->code_function_def < 0) {
+ return true;
+ }
+
if (irfun->code_function_def < 0) {
irerror(irfun->context, "`%s`: IR global wasn't generated, failed to access function-def", irfun->name);
return false;
{
pushdef = true;
+ /*
+ * if we're eraseable and the function isn't referenced ignore outputting
+ * the function.
+ */
+ if (global->flags & IR_FLAG_ERASEABLE && vec_size(global->reads) == 0) {
+ return true;
+ }
+
if (OPTS_OPTIMIZATION(OPTIM_STRIP_CONSTANT_NAMES) &&
!(global->flags & IR_FLAG_INCLUDE_DEF) &&
(global->name[0] == '#' || global->cvq == CV_CONST))
#define IR_FLAG_HAS_UNINITIALIZED (1<<2)
#define IR_FLAG_HAS_GOTO (1<<3)
#define IR_FLAG_INCLUDE_DEF (1<<4)
+#define IR_FLAG_ERASEABLE (1<<5)
#define IR_FLAG_MASK_NO_OVERLAP (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED)
#define IR_FLAG_MASK_NO_LOCAL_TEMPS (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED)
else if (!strcmp(parser_tokval(parser), "inline")) {
flags |= AST_FLAG_INLINE;
if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
- parseerror(parser, "`noref` attribute has no parameters, expected `]]`");
+ parseerror(parser, "`inline` attribute has no parameters, expected `]]`");
+ *cvq = CV_WRONG;
+ return false;
+ }
+ }
+ else if (!strcmp(parser_tokval(parser), "eraseable")) {
+ flags |= AST_FLAG_ERASEABLE;
+ if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
+ parseerror(parser, "`eraseable` attribute has no parameters, expected `]]`");
*cvq = CV_WRONG;
return false;
}