Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PIRC: Really use headerizer

git-svn-id: https://svn.parrot.org/parrot/trunk@44008 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 00b5d6221ee4f470694d173856ff27d12f99082c 1 parent d5a8e07
Vasily Chekalkin bacek authored
Showing with 161 additions and 73 deletions.
  1. +130 −69 src/pirpcc.c
  2. +31 −4 src/pirpcc.h
199 src/pirpcc.c
View
@@ -25,78 +25,122 @@ Conventions.
#include "parrot/oplib/ops.h"
-/* HEADERIZER HFILE: none */
+/* HEADERIZER HFILE: compilers/pirc/src/pirpcc.h */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
static void add_alias_operand(
- lexer_state * const lexer,
- PMC *array,
+ ARGIN(lexer_state * const lexer),
+ ARGIN(PMC *array),
int index,
- char const * const alias);
+ ARGIN(char const * const alias))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(4);
static void arguments_to_operands(
- lexer_state * const lexer,
+ ARGIN(lexer_state * const lexer),
argument * const args,
- unsigned num_arguments);
+ unsigned num_arguments)
+ __attribute__nonnull__(1);
+static int calculate_pcc_argument_flags(argument * const arg);
+static int calculate_pcc_target_flags(target * const result);
static void convert_nci_call(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_call(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_methodcall(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_methodtailcall(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_return(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_tailcall(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
static void convert_pcc_yield(
- lexer_state * const lexer,
- invocation * const inv);
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
+
+static int generate_signature_pmc(
+ ARGIN(lexer_state * const lexer),
+ unsigned size)
+ __attribute__nonnull__(1);
-static int generate_signature_pmc(lexer_state * const lexer, unsigned size);
static target * generate_unique_pir_reg(
- lexer_state * const lexer,
- pir_type type);
+ ARGIN(lexer_state * const lexer),
+ pir_type type)
+ __attribute__nonnull__(1);
+
+static target * get_invoked_sub(
+ ARGIN(lexer_state * const lexer),
+ target * const sub)
+ __attribute__nonnull__(1);
static void save_global_reference(
- lexer_state * const lexer,
+ ARGIN(lexer_state * const lexer),
instruction * const instr,
- char const * const label);
+ char const * const label)
+ __attribute__nonnull__(1);
static void targets_to_operands(
- lexer_state * const lexer,
+ ARGIN(lexer_state * const lexer),
target * const targets,
- unsigned num_targets);
-
-#define ASSERT_ARGS_add_alias_operand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_arguments_to_operands __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_nci_call __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_call __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_methodcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_methodtailcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_return __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_tailcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_convert_pcc_yield __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_generate_signature_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_generate_unique_pir_reg __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_save_global_reference __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_targets_to_operands __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+ unsigned num_targets)
+ __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_add_alias_operand __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(array) \
+ , PARROT_ASSERT_ARG(alias))
+#define ASSERT_ARGS_arguments_to_operands __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_calculate_pcc_argument_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_calculate_pcc_target_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_convert_nci_call __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_call __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_methodcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_methodtailcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_return __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_tailcall __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_convert_pcc_yield __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_generate_signature_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_generate_unique_pir_reg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_get_invoked_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_save_global_reference __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_targets_to_operands __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -105,8 +149,7 @@ static void targets_to_operands(
=over 4
-=item C<static int
-calculate_pcc_target_flags(target * const result)>
+=item C<static int calculate_pcc_target_flags(target * const result)>
Calculate Parrot Calling Conventions flags for the target node
C<result>.
@@ -115,7 +158,8 @@ C<result>.
*/
static int
-calculate_pcc_target_flags(target * const result) {
+calculate_pcc_target_flags(target * const result)
+{
int flag = 0;
@@ -140,8 +184,7 @@ calculate_pcc_target_flags(target * const result) {
/*
-=item C<static int
-calculate_pcc_argument_flags(argument * const arg)>
+=item C<static int calculate_pcc_argument_flags(argument * const arg)>
Calculate the Parrot Calling Conventions flags for the
argument C<arg>. An int encoding the flags is returned.
@@ -150,7 +193,8 @@ argument C<arg>. An int encoding the flags is returned.
*/
static int
-calculate_pcc_argument_flags(argument * const arg) {
+calculate_pcc_argument_flags(argument * const arg)
+{
int flag = 0;
switch (arg->value->type) {
@@ -198,7 +242,8 @@ mapped to a PASM register, so using negative PIR register is safe.
*/
static target *
-generate_unique_pir_reg(lexer_state * const lexer, pir_type type) {
+generate_unique_pir_reg(ARGIN(lexer_state * const lexer), pir_type type)
+{
ASSERT_ARGS(generate_unique_pir_reg)
return new_reg(lexer, type, --lexer->pir_reg_generator);
@@ -218,7 +263,8 @@ PBC constant table is returned.
*/
static int
-generate_signature_pmc(lexer_state * const lexer, unsigned size) {
+generate_signature_pmc(ARGIN(lexer_state * const lexer), unsigned size)
+{
ASSERT_ARGS(generate_signature_pmc)
PMC *fixed_int_array;
@@ -249,7 +295,8 @@ otherwise it's a standard return sequence.
*/
void
-emit_sub_epilogue(lexer_state * const lexer) {
+emit_sub_epilogue(ARGIN(lexer_state * const lexer))
+{
if (TEST_FLAG(lexer->subs->flags, PIRC_SUB_FLAG_MAIN))
new_sub_instr(lexer, PARROT_OP_end, "end", 0);
@@ -276,10 +323,11 @@ The alias name is passed in C<alias>.
*/
static void
-add_alias_operand(lexer_state * const lexer, PMC *array, int index, char const * const alias) {
+add_alias_operand(ARGIN(lexer_state * const lexer),
+ ARGIN(PMC *array), int index,
+ ARGIN(char const * const alias))
+{
ASSERT_ARGS(add_alias_operand)
-
- PARROT_ASSERT(alias);
/* set flags for being a string constant, and being a :named operand. */
VTABLE_set_integer_keyed_int(lexer->interp, array, index, PARROT_ARG_NAME | PARROT_ARG_SC);
push_operand(lexer, expr_from_string(lexer, alias));
@@ -310,7 +358,8 @@ with value "answer".
*/
static void
-targets_to_operands(lexer_state * const lexer, target * const targets, unsigned num_targets) {
+targets_to_operands(ARGIN(lexer_state * const lexer), target * const targets, unsigned num_targets)
+{
ASSERT_ARGS(targets_to_operands)
target *iter;
@@ -384,7 +433,8 @@ at index C<i> encodes the type and flags (such as C<:flat>) for operand C<i>.
*/
static void
-arguments_to_operands(lexer_state * const lexer, argument * const args, unsigned num_arguments) {
+arguments_to_operands(ARGIN(lexer_state * const lexer), argument * const args, unsigned num_arguments)
+{
ASSERT_ARGS(arguments_to_operands)
argument *argiter;
@@ -440,7 +490,8 @@ this is the number of parameters of this function.
*/
void
-generate_parameters_instr(lexer_state * const lexer, unsigned num_parameters) {
+generate_parameters_instr(ARGIN(lexer_state * const lexer), unsigned num_parameters)
+{
if (TEST_FLAG(CURRENT_SUB(lexer)->flags , (PIRC_SUB_FLAG_METHOD | PIRC_SUB_FLAG_VTABLE))) {
++num_parameters; /* didn't count implicit "self" parameter yet. */
}
@@ -464,7 +515,8 @@ Generate instruction for the C<.get_results> statement.
*/
void
-generate_getresults_instr(lexer_state * const lexer, target * const targetlist) {
+generate_getresults_instr(ARGIN(lexer_state * const lexer), target * const targetlist)
+{
/* add this point we know that there's only 1 target, as that's the convention for
* exception handlers:
*
@@ -491,7 +543,7 @@ during compile time.
*/
static void
-save_global_reference(lexer_state * const lexer, instruction * const instr,
+save_global_reference(ARGIN(lexer_state * const lexer), instruction * const instr,
char const * const label)
{
ASSERT_ARGS(save_global_reference)
@@ -508,8 +560,8 @@ save_global_reference(lexer_state * const lexer, instruction * const instr,
/*
-=item C<static target *
-get_invoked_sub(lexer_state * const lexer, target * const sub)>
+=item C<static target * get_invoked_sub(lexer_state * const lexer, target *
+const sub)>
Return a C<target> node that represents the sub to invoke.
If C<sub> is a register, that is returned. If it's a declared C<.local>,
@@ -523,7 +575,8 @@ instruction is emitted.
*/
static target *
-get_invoked_sub(lexer_state * const lexer, target * const sub) {
+get_invoked_sub(ARGIN(lexer_state * const lexer), target * const sub)
+{
target *subreg = NULL;
symbol *sym = NULL;
global_label *glob = NULL;
@@ -600,7 +653,8 @@ For "foo"() and foo():
*/
static void
-convert_pcc_call(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_call(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_call)
target *sub;
@@ -639,7 +693,8 @@ The sequence of instructions is:
*/
static void
-convert_pcc_tailcall(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_tailcall(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_tailcall)
target *sub;
@@ -668,7 +723,8 @@ Conventions (PCC). The sequence of instructions is:
*/
static void
-convert_pcc_return(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_return(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_return)
new_sub_instr(lexer, PARROT_OP_set_returns_pc, "set_returns_pc", inv->num_arguments);
@@ -692,7 +748,8 @@ Interface (NCI). The sequence of instructions is:
*/
static void
-convert_nci_call(lexer_state * const lexer, invocation * const inv) {
+convert_nci_call(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_nci_call)
target *sub;
@@ -724,7 +781,8 @@ The sequence of instructions is:
*/
static void
-convert_pcc_yield(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_yield(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_yield)
new_sub_instr(lexer, PARROT_OP_set_returns_pc, "set_returns_pc", inv->num_arguments);
@@ -749,7 +807,8 @@ The sequence of instructions is:
*/
static void
-convert_pcc_methodcall(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_methodcall(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_methodcall)
/* in a methodcall, the invocant object is passed as the first argument */
@@ -781,7 +840,8 @@ The sequence of instructions is:
*/
static void
-convert_pcc_methodtailcall(lexer_state * const lexer, invocation * const inv) {
+convert_pcc_methodtailcall(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
ASSERT_ARGS(convert_pcc_methodtailcall)
unshift_arg(inv, new_argument(lexer, expr_from_target(lexer, inv->sub)));
@@ -820,7 +880,8 @@ on the type of C<inv>.
*/
void
-convert_inv_to_instr(lexer_state * const lexer, invocation * const inv) {
+convert_inv_to_instr(ARGIN(lexer_state * const lexer), invocation * const inv)
+{
switch (inv->type) {
case CALL_PCC:
convert_pcc_call(lexer, inv);
35 src/pirpcc.h
View
@@ -9,10 +9,37 @@
#include "pircompunit.h"
#include "pircompiler.h"
-void convert_inv_to_instr(struct lexer_state * const lexer, invocation * const inv);
-void generate_parameters_instr(struct lexer_state * const lexer, unsigned num_parameters);
-void generate_getresults_instr(struct lexer_state * const lexer, target * const targetlist);
-void emit_sub_epilogue(struct lexer_state * const lexer);
+/* HEADERIZER BEGIN: compilers/pirc/src/pirpcc.c */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+void convert_inv_to_instr(
+ ARGIN(lexer_state * const lexer),
+ invocation * const inv)
+ __attribute__nonnull__(1);
+
+void emit_sub_epilogue(ARGIN(lexer_state * const lexer))
+ __attribute__nonnull__(1);
+
+void generate_getresults_instr(
+ ARGIN(lexer_state * const lexer),
+ target * const targetlist)
+ __attribute__nonnull__(1);
+
+void generate_parameters_instr(
+ ARGIN(lexer_state * const lexer),
+ unsigned num_parameters)
+ __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_convert_inv_to_instr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_emit_sub_epilogue __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_generate_getresults_instr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_generate_parameters_instr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: compilers/pirc/src/pirpcc.c */
#endif /* PARROT_PIR_PIRPCC_H_GUARD */
Please sign in to comment.
Something went wrong with that request. Please try again.