Skip to content

Commit

Permalink
memory safe for inline assembly (#685)
Browse files Browse the repository at this point in the history
* memory safe for inline assembly

* adding language option for assembly
  • Loading branch information
Janther authored Jun 17, 2022
1 parent 9c07d3d commit 90dd003
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/nodes/InlineAssemblyStatement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// @TODO: add support for assembly language specifier
const { printString } = require('../prettier-comments/common/util');
const printSeparatedList = require('./print-separated-list');

const InlineAssemblyStatement = {
print: ({ path, print }) => ['assembly ', path.call(print, 'body')]
print: ({ node, path, print, options }) => [
'assembly ',
node.language ? `${printString(node.language, options)} ` : '',
node.flags && node.flags.length > 0
? [
'(',
printSeparatedList(
node.flags.map((flag) => printString(flag, options))
),
') '
]
: '',
path.call(print, 'body')
]
};
module.exports = InlineAssemblyStatement;
7 changes: 7 additions & 0 deletions tests/format/Assembly/Assembly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,11 @@ function $somefn(somearg) {
}
}
}

function memorySafe() {
assembly ("memory-safe") {
}
assembly "evmasm" ("memory-safe") {
}
}
}
16 changes: 16 additions & 0 deletions tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ function $somefn(somearg) {
}
}
}
function memorySafe() {
assembly ("memory-safe") {
}
assembly "evmasm" ("memory-safe") {
}
}
}
=====================================output=====================================
Expand Down Expand Up @@ -400,6 +407,15 @@ contract Assembly {
}
}
}
function memorySafe() {
assembly ("memory-safe") {
}
assembly "evmasm" ("memory-safe") {
}
}
}
================================================================================
Expand Down

0 comments on commit 90dd003

Please sign in to comment.