Skip to content

Commit

Permalink
asm: Add support for function attributes.
Browse files Browse the repository at this point in the history
Updates #15.
  • Loading branch information
mewmew committed Mar 29, 2017
1 parent fd113c0 commit 308df76
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
75 changes: 72 additions & 3 deletions asm/internal/ll.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ label_ident
| _quoted_string ':'
;

// --- [ Attribute group identifiers ] -----------------------------------------

attr_group_id
: '#' _id
;

// === [ Integer literals ] ====================================================

// Integer [-]?[0-9]+
Expand Down Expand Up @@ -176,6 +182,7 @@ TopLevelDecl
| Global
| FunctionDecl
| FunctionDef
| AttrGroupDef
;

// === [ Source filename ] =====================================================
Expand Down Expand Up @@ -267,11 +274,11 @@ Align
// === [ Functions ] ===========================================================

FunctionDecl
: "declare" OptExternLinkage FunctionHeader OptUnnamedAddr OptAlign << $2, nil >>
: "declare" OptExternLinkage FunctionHeader OptUnnamedAddr FuncAttrs OptAlign << $2, nil >>
;

FunctionDef
: "define" OptLinkage FunctionHeader OptUnnamedAddr OptAlign FunctionBody << astx.NewFunctionDef($2, $5) >>
: "define" OptLinkage FunctionHeader OptUnnamedAddr FuncAttrs OptAlign FunctionBody << astx.NewFunctionDef($2, $6) >>
;

FunctionHeader
Expand Down Expand Up @@ -304,6 +311,64 @@ FunctionBody
: "{" BasicBlocks "}" << $1, nil >>
;

// === [ Attribute group definitions ] =========================================

AttrGroupDef
: "attributes" AttrGroupID "=" "{" FuncAttrs "}" << nil, nil >>
;

FuncAttrs
: empty
| FuncAttrs FuncAttr
;

// ref: http://llvm.org/docs/LangRef.html#function-attributes
FuncAttr
: string_lit
| string_lit "=" string_lit
| AttrGroupID
| "alignstack" "(" int_lit ")"
| "allocsize" "(" int_lit OptAllocSizeNElems ")"
| "alwaysinline"
| "builtin"
| "cold"
| "convergent"
| "inaccessiblememonly"
| "inaccessiblemem_or_argmemonly"
| "inlinehint"
| "jumptable"
| "minsize"
| "naked"
| "nobuiltin"
| "noduplicate"
| "noimplicitfloat"
| "noinline"
| "nonlazybind"
| "noredzone"
| "noreturn"
| "norecurse"
| "nounwind"
| "optnone"
| "optsize"
| "readnone"
| "readonly"
| "writeonly"
| "argmemonly"
| "returns_twice"
| "safestack"
| "sanitize_address"
| "sanitize_memory"
| "sanitize_thread"
| "ssp"
| "sspreq"
| "sspstrong"
| "uwtable"
;

OptAllocSizeNElems
: "," int_lit
;

// === [ Identifiers ] =========================================================

GlobalIdent
Expand All @@ -318,6 +383,10 @@ LabelIdent
: label_ident << astx.NewLabelIdent($0) >>
;

AttrGroupID
: attr_group_id
;

// === [ Types ] ===============================================================

Type
Expand Down Expand Up @@ -1032,7 +1101,7 @@ SelectInst
;

CallInst
: "call" FastMathFlags Type Value "(" Args ")" << astx.NewCallInst($2, $3, $5) >>
: "call" FastMathFlags Type Value "(" Args ")" FuncAttrs << astx.NewCallInst($2, $3, $5) >>
;

Args
Expand Down
4 changes: 0 additions & 4 deletions asm/internal/testdata/strip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ f=$1
sar -i "; <label>:([0-9]+):[^\n]+" "\${1}:" "${f}"
# Remove comments.
sar -i "(^|[\n]);[^\n]+" "" "${f}"
# Remove attributes.
sar -i "(^|[\n])attributes[^\n]+" "" "${f}"
# Remove function attributes.
sar -i "[)] #[0-9]+" ")" "${f}"
# Remove metadata nodes.
sar -i "(^|[\n])[!][^\n]+" "" "${f}"
# Add labels for the first basic block of functions with 0 parameters.
Expand Down

0 comments on commit 308df76

Please sign in to comment.