Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor issues in ABI conversions. #492

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/vast/Conversion/ABI/Common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Conversion/ABI/Common.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Conversion/ABI/Common.hpp

File include/vast/Conversion/ABI/Common.hpp does not conform to Custom style guidelines. (lines 5)

#pragma once

namespace vast::conv::abi
{
static inline const std::string abi_func_name_prefix = "vast.abi.";

Check failure on line 7 in include/vast/Conversion/ABI/Common.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

include/vast/Conversion/ABI/Common.hpp:7:25 [clang-diagnostic-error]

use of undeclared identifier 'std'
} // namespace vast::conv::abi
16 changes: 9 additions & 7 deletions lib/vast/Conversion/ABI/EmitABI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Conversion/ABI/EmitABI.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on lib/vast/Conversion/ABI/EmitABI.cpp

File lib/vast/Conversion/ABI/EmitABI.cpp does not conform to Custom style guidelines. (lines 232, 242, 243, 763, 835)

#include "vast/Conversion/Passes.hpp"

Expand All @@ -18,6 +18,8 @@

#include "../PassesDetails.hpp"

#include "vast/Conversion/ABI/Common.hpp"

#include "vast/Conversion/Common/Patterns.hpp"
#include "vast/Conversion/TypeConverters/TypeConverter.hpp"

Expand Down Expand Up @@ -227,7 +229,7 @@
op.getLoc(),
// Temporal, to avoid verification issues, will be changed once
// original func is removed.
"vast.abi" + op.getName().str(),
conv::abi::abi_func_name_prefix + op.getName().str(),
this->abified_type(),
core::GlobalLinkageKind::InternalLinkage,
other_attrs,
Expand All @@ -237,7 +239,8 @@
// Copying visibility from the original function results in error?
wrapper.setVisibility(mlir::SymbolTable::Visibility::Private);

mk_prologue(wrapper);
if (!op.getBody().empty())
mk_prologue(wrapper);

return wrapper;
}
Expand Down Expand Up @@ -757,7 +760,7 @@
return mlir::failure();

auto name = func.getName();
if (!name.consume_front("vast.abi"))
if (!name.consume_front(conv::abi::abi_func_name_prefix))
return mlir::failure();

auto abi_map_it = abi_info_map.find(name.str());
Expand Down Expand Up @@ -805,9 +808,8 @@

auto should_transform = [&](hl::FuncOp op)
{
// TODO(abi): Due to some issues with location info of arguments
// declaration are not yet supported.
return op.getName() == "main" && !op.isDeclaration();
// TODO(conv:abi): We should always emit main with a fixed type.
return op.getName() == "main";
};

target.addDynamicallyLegalOp< hl::FuncOp >(should_transform);
Expand All @@ -830,7 +832,7 @@
auto is_return_legal = [&](hl::ReturnOp op)
{
auto func = op->getParentOfType< abi::FuncOp >();
if (!func || func.getName() == "main")
if (!func)
return true;

for (auto val : op.getResult())
Expand Down
3 changes: 2 additions & 1 deletion lib/vast/Conversion/ABI/LowerABI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Conversion/ABI/LowerABI.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on lib/vast/Conversion/ABI/LowerABI.cpp

File lib/vast/Conversion/ABI/LowerABI.cpp does not conform to Custom style guidelines. (lines 608)

#include "vast/Conversion/Passes.hpp"

Expand All @@ -18,6 +18,7 @@
#include "../PassesDetails.hpp"

#include "vast/Conversion/Common/Patterns.hpp"
#include "vast/Conversion/ABI/Common.hpp"

#include "vast/Dialect/HighLevel/HighLevelAttributes.hpp"
#include "vast/Dialect/HighLevel/HighLevelTypes.hpp"
Expand Down Expand Up @@ -604,7 +605,7 @@
op.getAllArgAttrs(arg_attrs);

auto name = op.getName();
if (!name.consume_front("vast.abi"))
if (!name.consume_front(conv::abi::abi_func_name_prefix))
return mlir::failure();

auto fn = rewriter.create< hl::FuncOp >(
Expand Down
4 changes: 4 additions & 0 deletions lib/vast/Conversion/FromHL/ToLLCF.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Conversion/FromHL/ToLLCF.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on lib/vast/Conversion/FromHL/ToLLCF.cpp

File lib/vast/Conversion/FromHL/ToLLCF.cpp does not conform to Custom style guidelines. (lines 461)

#include "vast/Conversion/Passes.hpp"

Expand All @@ -25,6 +25,7 @@


#include "vast/Dialect/Core/CoreTraits.hpp"
#include "vast/Dialect/Core/CoreOps.hpp"
#include "vast/Dialect/HighLevel/HighLevelDialect.hpp"
#include "vast/Dialect/LowLevel/LowLevelOps.hpp"

Expand Down Expand Up @@ -457,6 +458,7 @@
, while_op
, for_op
, replace< hl::ReturnOp, ll::ReturnOp >
, replace< core::ImplicitReturnOp, ll::ReturnOp >
>;

} // namespace pattern
Expand All @@ -474,7 +476,9 @@

trg.addIllegalOp< hl::ContinueOp >();
trg.addIllegalOp< hl::BreakOp >();

trg.addIllegalOp< hl::ReturnOp >();
trg.addIllegalOp< core::ImplicitReturnOp >();

trg.addLegalOp< mlir::cf::BranchOp >();
trg.markUnknownOpDynamicallyLegal([](auto){ return true; });
Expand Down
1 change: 0 additions & 1 deletion test/vast/Compile/SingleSource/putchar-a.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %vast-front -o %t %s && %t | %file-check %s
// REQUIRES: abi

int putchar(int);

Expand Down
1 change: 0 additions & 1 deletion test/vast/Compile/SingleSource/puts-a.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %vast-front -o %t %s && %t hello | %file-check %s
// REQUIRES: abi

int puts(const char *);

Expand Down
Loading