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

LLVM backend support #558

Draft
wants to merge 85 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4a083ff
LLVM backend: kcc/runner scripts.
Jun 28, 2019
a8061d4
Dockerfile: build LLVM backend.
chathhorn Aug 28, 2019
b9cd90a
Jenkinsfile: disable rule parse profiling.
chathhorn Aug 30, 2019
2200763
Jenkinsfile: remove parse profiling.
chathhorn Sep 19, 2019
afb5e12
Enable kore output for C++ parser.
chathhorn Oct 22, 2019
5b609e4
generate readable dumps
h0nzZik Feb 6, 2020
03fc204
llvm-krun -save-temps
h0nzZik Feb 6, 2020
2d91b87
kcc -fdebug-translation
h0nzZik Mar 2, 2020
3861e02
append sorts to symbols
h0nzZik Mar 5, 2020
e55a487
fix lookupEnumerator
h0nzZik Mar 5, 2020
05422b7
fix
h0nzZik Mar 5, 2020
ed47382
rename isNoInit => hasInit
h0nzZik Mar 13, 2020
b291263
Revert "append sorts to symbols"
h0nzZik Mar 13, 2020
18f40a9
C++ semantics [symbol] tags.
chathhorn Oct 22, 2019
ee06607
update K
h0nzZik Mar 27, 2020
b8e640b
llvm debug
h0nzZik Mar 27, 2020
a718f5e
UnknownCabsLoc
h0nzZik Mar 25, 2020
d6af82b
workaround for K bug https://github.com/kframework/k/issues/1193
h0nzZik Apr 1, 2020
28cb90a
C++ parser: toplevel sort is KItem
h0nzZik Apr 1, 2020
1a8cdb4
C++ parser #NoName
h0nzZik Apr 2, 2020
aad43ba
[symbol]
h0nzZik Apr 7, 2020
df184b4
remove overloaded ExprLoc
h0nzZik Apr 7, 2020
01944f2
C++ [symbol]
h0nzZik Apr 9, 2020
f88d3b3
fix toCPPTypes
h0nzZik Apr 9, 2020
5ffaa52
fix sorts
h0nzZik Apr 9, 2020
da13059
fix NoInit
h0nzZik Apr 10, 2020
b1e20bd
fix sorts
h0nzZik Apr 10, 2020
f82292b
strip traces in linking semantics
h0nzZik Apr 15, 2020
2c5ded1
fix sort
h0nzZik Apr 15, 2020
edcc511
fix `assertInBounds` and `assert`
h0nzZik Apr 15, 2020
12d1c03
do not escape strings twice
h0nzZik Apr 16, 2020
367ef5e
fix sorts
h0nzZik Apr 16, 2020
5e80cb0
IfAStmtD
h0nzZik Apr 17, 2020
f6cb33b
operatorXYZ_CPP-SYNTAX_OpId
h0nzZik Apr 17, 2020
679b821
fix sorts
h0nzZik Apr 17, 2020
280c0f5
fix sorts
h0nzZik Apr 17, 2020
42ae7ca
isKResult
h0nzZik Apr 17, 2020
f2f2798
fix sorts
h0nzZik Apr 17, 2020
dd76982
fix sorts
h0nzZik Apr 17, 2020
eb36782
Fix sorts
h0nzZik Apr 17, 2020
095d645
Parser: 'And-'
h0nzZik Apr 17, 2020
fbdad09
We no longer have sort BraceInit
h0nzZik Apr 17, 2020
1867f49
fix sorts
h0nzZik Apr 17, 2020
8219c33
fix csetunion
h0nzZik Apr 20, 2020
b2cd6d8
LLVM backend: kcc/runner scripts.
Jun 28, 2019
5b76644
Dockerfile: build LLVM backend.
chathhorn Aug 28, 2019
9bd143f
Jenkinsfile: disable rule parse profiling.
chathhorn Aug 30, 2019
61bccb4
Jenkinsfile: remove parse profiling.
chathhorn Sep 19, 2019
6be94d3
Enable kore output for C++ parser.
chathhorn Oct 22, 2019
b12feca
generate readable dumps
h0nzZik Feb 6, 2020
ae8d900
llvm-krun -save-temps
h0nzZik Feb 6, 2020
0d2a4bd
kcc -fdebug-translation
h0nzZik Mar 2, 2020
04e280c
append sorts to symbols
h0nzZik Mar 5, 2020
b904c32
fix lookupEnumerator
h0nzZik Mar 5, 2020
bd1fd9c
fix
h0nzZik Mar 5, 2020
722765b
rename isNoInit => hasInit
h0nzZik Mar 13, 2020
f8f01a3
Revert "append sorts to symbols"
h0nzZik Mar 13, 2020
3640887
C++ semantics [symbol] tags.
chathhorn Oct 22, 2019
315a00d
update K
h0nzZik Mar 27, 2020
cc2ef43
llvm debug
h0nzZik Mar 27, 2020
f35abc8
UnknownCabsLoc
h0nzZik Mar 25, 2020
0d13a74
workaround for K bug https://github.com/kframework/k/issues/1193
h0nzZik Apr 1, 2020
dd08978
C++ parser: toplevel sort is KItem
h0nzZik Apr 1, 2020
0de15eb
C++ parser #NoName
h0nzZik Apr 2, 2020
63b33c7
fix kcc script merge conflict
Apr 24, 2020
04e182f
Merge branch 'llvm' into latest
h0nzZik Apr 29, 2020
998108d
fix checkLoc
h0nzZik Apr 29, 2020
6124977
fix missing [function]
h0nzZik Apr 29, 2020
c323c29
little refactoring
h0nzZik Apr 29, 2020
a937f17
fix missing [symbol]
h0nzZik Apr 29, 2020
76e5953
Constructor takes AStmt
h0nzZik Apr 30, 2020
0c3571d
Revert "fix csetunion"
h0nzZik Apr 30, 2020
614aeca
make csetunion work with types
h0nzZik Apr 30, 2020
93a6b30
fix sorts
h0nzZik Apr 30, 2020
45c70ba
remove the content of `<initializers>` in the link time
h0nzZik Apr 30, 2020
3dd482d
fix sorts
h0nzZik Apr 30, 2020
8810ac8
parser: skip default arguments in a call
h0nzZik May 1, 2020
8dcf2ed
fix sorts
h0nzZik May 11, 2020
be8951f
fixes
h0nzZik May 12, 2020
eda43b4
kcc -fdebug-linking
h0nzZik May 14, 2020
3818a61
kcc: fix generating kcc_config from linking semantics
h0nzZik May 14, 2020
2891833
linking: overwrite with the same value
h0nzZik May 14, 2020
a5b4248
brace initialization: fix sorts
h0nzZik May 14, 2020
8615063
for: fix sort
h0nzZik May 14, 2020
e88a01b
isKResult
h0nzZik May 14, 2020
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
2 changes: 1 addition & 1 deletion .build/k
Submodule k updated from 748a6d to bb0ebd
42 changes: 28 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ FROM runtimeverificationinc/kframework:ubuntu-bionic
# Install packages. #
#####################

RUN apt-get update -q \
&& apt install --yes \
libstdc++6 \
llvm-6.0 \
clang++-6.0 \
clang-6.0
RUN apt-get update -q \
&& apt-get install --yes \
libstdc++6 \
llvm-6.0 \
clang++-6.0 \
clang-6.0 \
clang-8 \
libclang-8-dev \
llvm-8-tools \
lld-8 \
zlib1g-dev \
bison \
flex \
libboost-test-dev \
libgmp-dev \
libmpfr-dev \
libyaml-dev \
libjemalloc-dev \
pkg-config

RUN git clone 'https://github.com/z3prover/z3' --branch=z3-4.8.7 \
&& cd z3 \
Expand Down Expand Up @@ -41,20 +54,21 @@ COPY --from=runtimeverificationinc/ocaml:ubuntu-bionic \
/home/user/.opam \
/home/user/.opam


# This is where the rest of the dependencies go.
ENV DEPS_DIR="/home/user/c-semantics-deps"

############
# Build K. #
############

# This is where the rest of the dependencies go.
ENV DEPS_DIR="/home/user/c-semantics-deps"
ENV PATH="${DEPS_DIR}/k/llvm-backend/src/main/native/llvm-backend/build/bin:${PATH}"
ENV K_BIN="${DEPS_DIR}/k/k-distribution/target/release/k/bin"

COPY --chown=user:user ./.build/k/ ${DEPS_DIR}/k

RUN cd ${DEPS_DIR}/k \
&& mvn package -q -U \
&& mvn package -e -q -U \
-DskipTests -DskipKTest \
-Dhaskell.backend.skip -Dllvm.backend.skip \
-Dcheckstyle.skip
-Dhaskell.backend.skip \
-Dcheckstyle.skip \
-Dproject.build.type=FastBuild

ENV K_BIN="${DEPS_DIR}/k/k-distribution/target/release/k/bin"
5 changes: 1 addition & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ pipeline {
eval $(opam config env)
eval $(perl -I "~/perl5/lib/perl5" -Mlocal::lib)
export KOMPILE_FLAGS=-O2
make -j4 profile-rule-parsing --output-sync=line
make -j4 --output-sync=line
'''
} }
}
post { success {
archiveArtifacts 'dist/timelogs.d/timelogs.csv'
} }
}
stage ( 'Re-compile w/ timeout' ) { steps {
timeout(time: 8, unit: 'SECONDS' ) {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export KOMPILE := $(K_BIN)/kompile
export KDEP := $(K_BIN)/kdep

# Appending to whatever the environment provided.
K_OPTS += -Xmx8g
K_OPTS += -Xmx16g
K_OPTS += -Xss32m
export K_OPTS

Expand Down
7 changes: 4 additions & 3 deletions clang-tools/ClangKast/ClangKast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ std::ostream& operator<<(std::ostream & os, const Sort & sort) {
case Sort::NAMESPACE: os << "Namespeace"; break;
case Sort::NNS: os << "NNS"; break;
case Sort::NNSSPECIFIER: os << "NNSSpecifier"; break;
case Sort::NOINIT: os << "NoInit"; break;
case Sort::NONAME: os << "NoName"; break;
case Sort::OPID: os << "OpId"; break;
case Sort::QUALIFIER: os << "Qualifier"; break;
Expand Down Expand Up @@ -140,7 +141,7 @@ string Kast::Node::escapeKLabel(const string & label) {
case '#': subst = "Hash'"; break;
case '$': subst = "Dolr'"; break;
case '%': subst = "Perc'"; break;
case '&': subst = "And'" ; break;
case '&': subst = "And-'"; break;
case '\'': subst = "Apos'"; break;
case '(': subst = "LPar'"; break;
case ')': subst = "RPar'"; break;
Expand Down Expand Up @@ -223,7 +224,7 @@ void Kast::KApply::print(Sort parentSort, function<void (Sort)> printChild) cons
// *** Kast::KToken ***

string Kast::KToken::toKString(const string & s) {
return string(Kore ? escape(s) : "\"" + escape(s) + "\"");
return string(Kore ? s : "\"" + escape(s) + "\"");
}

string Kast::KToken::toKString(bool b) {
Expand Down Expand Up @@ -330,7 +331,7 @@ void Kast::add(const T & node) {
Kast::Nodes.push_back(make_unique<T>(node));
}

void Kast::print() { print(Sort::K, 0); }
void Kast::print() { print(Sort::KITEM, 0); }

int Kast::print(Sort parentSort, int idx) {
if (!Nodes[idx]) throw logic_error("parse error");
Expand Down
1 change: 1 addition & 0 deletions clang-tools/ClangKast/ClangKast.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class Sort {
NAMESPACE,
NNS,
NNSSPECIFIER,
NOINIT,
NONAME,
OPID,
QUALIFIER,
Expand Down
96 changes: 50 additions & 46 deletions clang-tools/ClangKast/GetKastVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,21 @@ class GetKastVisitor
Kast::add(Kast::KApply("NestedName", Sort::NNS, {Sort::NNS, Sort::NNSSPECIFIER}));
TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
}
auto nns = Kast::KApply("NNS", Sort::NNSSPECIFIER, {Sort::CID});
switch (NNS->getKind()) {
case NestedNameSpecifier::Identifier:
Kast::add(nns);
Kast::add(Kast::KApply("NNSCId", Sort::NNSSPECIFIER, {Sort::CID}));
TRY_TO(TraverseIdentifierInfo(NNS->getAsIdentifier()));
break;
case NestedNameSpecifier::Namespace:
Kast::add(nns);
Kast::add(Kast::KApply("NNSName", Sort::NNSSPECIFIER, {Sort::NAME}));
TRY_TO(TraverseDeclarationName(NNS->getAsNamespace()->getDeclName()));
break;
case NestedNameSpecifier::NamespaceAlias:
Kast::add(nns);
Kast::add(Kast::KApply("NNSName", Sort::NNSSPECIFIER, {Sort::NAME}));
TRY_TO(TraverseDeclarationName(NNS->getAsNamespaceAlias()->getDeclName()));
break;
case NestedNameSpecifier::TypeSpec:
Kast::add(nns);
Kast::add(Kast::KApply("NNSName", Sort::NNSSPECIFIER, {Sort::NAME}));
TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
break;
case NestedNameSpecifier::TypeSpecWithTemplate:
Expand All @@ -266,7 +265,7 @@ class GetKastVisitor
bool TraverseIdentifierInfo(const IdentifierInfo *info, uintptr_t decl) {
if (!info) {
if (decl == 0) {
Kast::add(Kast::KApply("#NoName_COMMON-SYNTAX", Sort::NONAME));
Kast::add(Kast::KApply("#NoName_COMMON-SYNTAX_NoName", Sort::NONAME));
} else {
Kast::add(Kast::KApply("unnamed", Sort::UNNAMEDCID, {Sort::INT, Sort::STRING}));
VisitUnsigned((unsigned long long)decl);
Expand Down Expand Up @@ -456,7 +455,7 @@ class GetKastVisitor

if (D->isThisDeclarationADefinition()) {
if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
Kast::add(Kast::KApply("Constructor", Sort::STMT, {Sort::LIST, Sort::STMT}));
Kast::add(Kast::KApply("Constructor", Sort::STMT, {Sort::LIST, Sort::ASTMT}));
int i = 0;
for (auto *I : Ctor->inits()) {
if (I->isWritten()) i++;
Expand Down Expand Up @@ -498,6 +497,10 @@ class GetKastVisitor
return TraverseFunctionHelper(D);
}

void NoInit() {
Kast::add(Kast::KApply("NoInit", Sort::NOINIT));
}

bool TraverseVarHelper(VarDecl *D) {
StorageClass(D->getStorageClass());
ThreadStorageClass(D->getTSCSpec());
Expand All @@ -518,7 +521,7 @@ class GetKastVisitor
if (D->getInit()) {
TRY_TO(TraverseStmt(D->getInit()));
} else {
Kast::add(Kast::KApply("NoInit", Sort::INIT));
NoInit();
}
VisitBool(D->isDirectInit());
return true;
Expand All @@ -545,7 +548,7 @@ class GetKastVisitor
} else if (D->hasInClassInitializer()) {
TRY_TO(TraverseStmt(D->getInClassInitializer()));
} else {
Kast::add(Kast::KApply("NoInit", Sort::INIT));
NoInit();
}
return true;
}
Expand All @@ -561,21 +564,16 @@ class GetKastVisitor
}

void VisitAccessSpecifier(AccessSpecifier Spec) {
const char *spec;
switch (Spec) {
case AS_public:
spec = "Public";
break;
case AS_protected:
spec = "Protected";
break;
case AS_private:
spec = "Private";
break;
case AS_none:
spec = "NoAccessSpec";
break;
}
const char * const spec = [&]{
switch (Spec) {
case AS_public: return "Public";
case AS_protected: return "Protected";
case AS_private: return "Private";
case AS_none: return "NoAccessSpec";
}
assert(false && "Unknown access specifier");
return (const char *)nullptr;
}();
Kast::add(Kast::KApply(spec, Sort::ACCESSSPECIFIER));
}

Expand Down Expand Up @@ -1283,7 +1281,7 @@ class GetKastVisitor
bool VisitReturnStmt(ReturnStmt *S) {
Kast::add(Kast::KApply("ReturnStmt", Sort::STMT, {Sort::INIT}));
if (!S->getRetValue()) {
Kast::add(Kast::KApply("NoInit", Sort::INIT));
NoInit();
}
return false;
}
Expand Down Expand Up @@ -1344,10 +1342,11 @@ class GetKastVisitor
}

bool TraverseIfStmt(IfStmt *S) {
Kast::add(Kast::KApply("IfAStmt", Sort::ASTMT, {Sort::DECL, Sort::ASTMT, Sort::ASTMT}));
if (VarDecl *D = S->getConditionVariable()) {
Kast::add(Kast::KApply("IfAStmtD", Sort::ASTMT, {Sort::DECL, Sort::ASTMT, Sort::ASTMT}));
TRY_TO(TraverseDecl(D));
} else {
Kast::add(Kast::KApply("IfAStmt", Sort::ASTMT, {Sort::EXPR, Sort::ASTMT, Sort::ASTMT}));
TRY_TO(TraverseStmt(S->getCond()));
}
TRY_TO(TraverseStmt(S->getThen()));
Expand All @@ -1360,10 +1359,11 @@ class GetKastVisitor
}

bool TraverseSwitchStmt(SwitchStmt *S) {
Kast::add(Kast::KApply("SwitchAStmt", Sort::ASTMT, {Sort::DECL, Sort::ASTMT}));
if (VarDecl *D = S->getConditionVariable()) {
Kast::add(Kast::KApply("SwitchAStmtD", Sort::ASTMT, {Sort::DECL, Sort::ASTMT}));
TRY_TO(TraverseDecl(D));
} else {
Kast::add(Kast::KApply("SwitchAStmt", Sort::ASTMT, {Sort::EXPR, Sort::ASTMT}));
TRY_TO(TraverseStmt(S->getCond()));
}
TRY_TO(TraverseStmt(S->getBody()));
Expand Down Expand Up @@ -1444,19 +1444,23 @@ class GetKastVisitor

bool TraverseCallExpr(CallExpr *E) {
Kast::add(Kast::KApply("CallExpr", Sort::RESOLVEDEXPR, {Sort::EXPR, Sort::STRICTLIST, Sort::STRICTLISTRESULT}));
unsigned i = 0;
for (Stmt *SubStmt : E->children()) {
i++;
}
if (i-1 != E->getNumArgs()) {
throw std::logic_error("unimplemented: pre_args???");
}
bool first = true;
for (Stmt *SubStmt : E->children()) {
TRY_TO(TraverseStmt(SubStmt));
if (first) List(i-1);
first = false;
}

// 1
TRY_TO(TraverseStmt(E->getCallee()));

// 2
Kast::add(Kast::KApply("list", Sort::STRICTLIST, {Sort::LIST}));
for (unsigned int i = 0; i < E->getNumArgs(); i++) {
clang::Expr * arg = E->getArg(i);
if (!isa<CXXDefaultArgExpr>(arg)) {
Kast::add(Kast::KApply("_List_", Sort::LIST, {Sort::LIST, Sort::LIST}));
Kast::add(Kast::KApply("ListItem", Sort::LIST, {Sort::KITEM}));
TRY_TO(TraverseStmt(arg));
}
}
Kast::add(Kast::KApply(".List", Sort::LIST));

// 3
Kast::add(Kast::KApply("krlist", Sort::STRICTLISTRESULT, {Sort::LIST}));
Kast::add(Kast::KApply(".List", Sort::LIST));
return true;
Expand Down Expand Up @@ -1503,7 +1507,7 @@ class GetKastVisitor
switch (Kind) {
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
case OO_##Name: \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX", Sort::OPID)); \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX_OpId", Sort::OPID)); \
break;
#include "clang/Basic/OperatorKinds.def"
default:
Expand All @@ -1515,7 +1519,7 @@ class GetKastVisitor
switch (Kind) {
#define UNARY_OP(Name, Spelling) \
case UO_##Name: \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX", Sort::OPID)); \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX_OpId", Sort::OPID)); \
break;
UNARY_OP(PostInc, "_++")
UNARY_OP(PostDec, "_--")
Expand Down Expand Up @@ -1548,7 +1552,7 @@ class GetKastVisitor
switch (Kind) {
#define BINARY_OP(Name, Spelling) \
case BO_##Name: \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX", Sort::OPID)); \
Kast::add(Kast::KApply("operator" Spelling "_CPP-SYNTAX_OpId", Sort::OPID)); \
break;
BINARY_OP(PtrMemD, ".*")
BINARY_OP(PtrMemI, "->*")
Expand Down Expand Up @@ -1838,7 +1842,7 @@ class GetKastVisitor
if (E->hasInitializer()) {
TRY_TO(TraverseStmt(E->getInitializer()));
} else {
Kast::add(Kast::KApply("NoInit", Sort::INIT));
NoInit();
}
KSeqList(E->getNumPlacementArgs());
for (unsigned i = 0; i < E->getNumPlacementArgs(); i++) {
Expand Down Expand Up @@ -2022,7 +2026,7 @@ class GetKastVisitor

bool TraverseInitListExpr(InitListExpr *E) {
InitListExpr *Syntactic = E->isSemanticForm() ? E->getSyntacticForm() ? E->getSyntacticForm() : E : E;
Kast::add(Kast::KApply("BraceInit", Sort::BRACEINIT, {Sort::LIST}));
Kast::add(Kast::KApply("BraceInit", Sort::INIT, {Sort::LIST}));
KSeqList(Syntactic->getNumInits());
for (Stmt *SubStmt : Syntactic->children()) {
TRY_TO(TraverseStmt(SubStmt));
Expand Down Expand Up @@ -2250,7 +2254,7 @@ class GetKastVisitor
VisitUnsigned(presumed.getColumn());
VisitBool(mgr.isInSystemHeader(loc));
} else {
Kast::add(Kast::KApply("UnknownCabsLoc_COMMON-SYNTAX", Sort::CABSLOC));
Kast::add(Kast::KApply("UnknownCabsLoc_COMMON-SYNTAX_CabsLoc", Sort::CABSLOC));
}
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/RV_Kcc/Opts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ sub parseOpts {
for GCC.
{ RV_Kcc::Opts::pushArg('cppArgs', "-d$chars"); }
-ftranslation-depth=<depth> Compile program up to a given depth. [undocumented]
-fdebug-translation Run translation semantics with GDB. [undocumented]
-flinking-depth=<depth> Link program up to a given depth. [undocumented]
-fdebug-linking Run linking semantics with GDB. [undocumented]
-fmessage-length=0 Write all error messages on a single line.
-frunner-script Compile program to perl script with analysis tool options. [undocumented]
-fissue-report=<file> Write issues to the specified file.
Expand Down
Loading