Skip to content

Commit

Permalink
target-optional attribute for all async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
idgay committed Apr 21, 2010
1 parent 472b67f commit 7882f33
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/envtarget.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<tr><td>int1248_align <td>align,align,align,align <td>1,1,1,1
<tr><td>wchar_size_size <td>size,size <td>2,2
<tr><td>char_wchar_signed <td>bool,bool <td>true,true
<tr><td>async_functions <td>string <td>empty
</table>

</blockquote>
Expand Down
2 changes: 1 addition & 1 deletion nregress/exts/keil/run1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$NESC1 $1 >/dev/null
$NESC1 -fnesc-target=keil $1 >/dev/null
19 changes: 19 additions & 0 deletions nregress/exts/keil/t4.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
int h(void) { return 2; }

module t4 {
provides async command int f();
}
implementation {

int g(void) { return 1; }

async command int f()
{
return g() + h();
}

void hmm() @spontaneous()
{
call f();
}
}
1 change: 1 addition & 0 deletions src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct {
size_t int1_align, int2_align, int4_align, int8_align;
size_t wchar_t_size, size_t_size;
bool char_signed, wchar_t_signed;
char *async_functions_atribute;

cval (*adjust_field_align)(field_declaration fdecl, cval alignment);

Expand Down
1 change: 1 addition & 0 deletions src/machine/avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static machine_spec avr_machine = {
1, 1, 1, 1, /* int1/2/4/8 align */
2, 2, /* wchar_t, size_t size */
TRUE, TRUE, /* char, wchar_t signed */
NULL, /* no attribute for async functions */

NULL, /* adjust_field_align */

Expand Down
10 changes: 10 additions & 0 deletions src/machine/env_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static machine_spec env_machine = {
1, 1, 1, 1, /* int1248_align */
2, 2, /* wchar_size_size */
TRUE, TRUE, /* char_wchar_signed */
NULL, /* no attribute for async functions */

NULL, /* adjust_field_align */

Expand Down Expand Up @@ -260,6 +261,15 @@ static bool scan_env_machine(machine_spec * machine, const char *envname)
n_errors++;
}
}
else if (is_literali(name = "async_functions", begin, equal))
{
int l = space - value;
char *s = rstralloc(permanent, l + 1);

memcpy(s, value, l);
s[l] = '\0';
machine->async_functions_atribute = s;
}
else
{
int i = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/machine/keil.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declaration keil_special(location loc, cstring keyword, cstring name,
region r = parse_region;
/* Build __attribute__((keil_address(address))) */
word aword = new_word(r, loc, str2cstring(r, "keil_address"));
gcc_attribute address_attr = new_gcc_attribute(r, loc, aword, address);
target_attribute address_attr = new_target_attribute(r, loc, aword, address);

/* Build a declaration for name */
declarator d = make_identifier_declarator(loc, name);
Expand All @@ -84,7 +84,7 @@ declaration keil_special(location loc, cstring keyword, cstring name,

/* Basic pointer sizes and alignments for the 8051's compiled w/ Keil C51 */
static machine_spec keil_machine = {
"keil", NULL,
"keil51", NULL,
TRUE, /* big_endian */
FALSE, /* pcc_bitfield_type_matters */
8, /* empty field boundary - in bits */
Expand All @@ -101,6 +101,7 @@ static machine_spec keil_machine = {
1, 1, 1, 1, /* int1/2/4/8 align */
2, 2, /* wchar_t, size_t size */
TRUE, TRUE, /* char, wchar_t signed */
"reentrant", /* attribute for async functions */

NULL, /* adjust_field_align function */
NULL, NULL, NULL, NULL, /* attribute handling functions */
Expand Down
1 change: 1 addition & 0 deletions src/machine/msp430.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static machine_spec msp430_machine = {
1, 2, 2, 2, /* int1/2/4/8 align */
2, 2, /* wchar_t, size_t size */
TRUE, TRUE, /* char, wchar_t signed */
NULL, /* no attribute for async functions */

NULL, /* adjust_field_align */

Expand Down
3 changes: 2 additions & 1 deletion src/machine/sdcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int sdcc_token(const char *token, int len, struct yystype *lvalp)
}

static machine_spec sdcc_machine = {
"sdcc", NULL,
"sdcc51", NULL,
FALSE, /* big_endian */
FALSE, /* pcc_bitfield_type_matters */
8, /* empty field boundary - in bits */
Expand All @@ -70,6 +70,7 @@ static machine_spec sdcc_machine = {
1, 1, 1, 1, /* int1/2/4/8 align */
2, 2, /* wchar_t, size_t size */
TRUE, TRUE, /* char, wchar_t signed */
NULL, /* no attribute for async functions */

NULL, /* adjust_field_align function */
NULL, NULL, NULL, NULL, /* attribute handling functions */
Expand Down
1 change: 1 addition & 0 deletions src/machine/self.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static machine_spec self_machine = {
__alignof__(myint4), __alignof__(myint8), /* int1/2/4/8 align */
sizeof(wchar_t), sizeof(size_t), /* wchar_t, size_t size */
(char)-1 < 0, (wchar_t)-1 < 0, /* char, wchar_t signed */
NULL, /* no attribute for async functions */

SELF_ADJUST_FIELD_ALIGN, /* adjust_field_align */

Expand Down
15 changes: 15 additions & 0 deletions src/nesc-concurrency.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Boston, MA 02111-1307, USA. */
#include "nesc-cg.h"
#include "nesc-concurrency.h"
#include "nesc-semantics.h"
#include "machine.h"
#include "c-parse.h"

static inline bool is_call_edge(gedge e)
{
Expand All @@ -36,6 +38,19 @@ static void rec_async(gnode n, bool async_caller)
return;
fn->actual_async = async;

/* Martin Leopold: add an "async" gcc attribute to any async elements for targets
that need to identify functions callable from interrupts. */
if (fn->definition && target->async_functions_atribute)
{
function_decl fd = CAST(function_decl, fn->definition);
location l = fd->modifiers->location;
region r = parse_region;
word aname = new_word(r, l, str2cstring(r, target->async_functions_atribute));
target_attribute attr = new_target_attribute(r, l, aname, NULL);

fd->attributes = attribute_chain(attr, fd->attributes);
}

/* We don't pass async through commands or events that are not
declared async to avoid reporting errors for the fns called
by the "async but not so declared" command or event */
Expand Down
2 changes: 2 additions & 0 deletions src/unparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,8 @@ void prt_target_attribute(target_attribute a)
set_location(a->location);
if (!strcmp(a->word1->cstring.data, "iar_at"))
output("@");
else if (!strcmp(a->word1->cstring.data, "keil_address"))
output("=");
else
prt_word(a->word1);
if (a->args)
Expand Down

0 comments on commit 7882f33

Please sign in to comment.