Skip to content

Commit

Permalink
Add support for 64-bit NASM assembly.
Browse files Browse the repository at this point in the history
  • Loading branch information
beroset committed Nov 8, 2020
1 parent 7c85ba2 commit a96d8df
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ endif()

INSTALL(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/c DESTINATION share/autoproject/config)
INSTALL(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/cpp DESTINATION share/autoproject/config)
INSTALL(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/asm DESTINATION share/autoproject/config)
INSTALL(FILES "${PROJECT_BINARY_DIR}/autoproject.conf" DESTINATION share/autoproject/config)
20 changes: 20 additions & 0 deletions config/asm/rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# rules.txt
#
# AutoProject rules file.
#
# Each line is composed of three fields each separated with the '@' character
# The fields are "Rule regex", "CMake extras" and "Libraries"
#
# The "Rule regex" is the regular expression that triggers the rule and is
# determined by searching each line of the input sources for the regex
#
# The "CMake extras" field is the only one that can be empty and represents extra
# rules that may need to be inserted before the "add_executable" line. If
# multiple lines are needed, separate them using "\n" within the field.
#
# The "Libraries" is the list of additional libraries that need to be added
# to the "target_link_libraries" line. If the same library is needed by
# multiple components, only a single instance will appear. The ordering
# of libraries is arbitrary.
#
#\s*#include\s*<(experimental/)?filesystem>@@stdc++fs
4 changes: 4 additions & 0 deletions config/asm/srclevel.cmake.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.1)
{extras}
add_executable({projname} {srcnames})
target_link_libraries({projname} {libraries})
13 changes: 13 additions & 0 deletions config/asm/toplevel.cmake.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project({projname})
enable_language(ASM_NASM)
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> \
<FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE> -l <OBJECT>.lst")
set(CMAKE_ASM_NASM_LINK_EXECUTABLE "ld <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS} -g -Fdwarf")
else()
set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS}")
endif()
add_subdirectory(src)
10 changes: 10 additions & 0 deletions config/autoproject.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ RulesFileName=rules.txt
TopLevelCMakeFileName=toplevel.cmake.txt
# The name of the source level CMake file
SrcLevelCMakeFileName=srclevel.cmake.txt

[asm]
# The name of the subdirectory under ConfigFileDir
Subdir=asm
# The name of the rules file
RulesFileName=rules.txt
# The name of the top level CMake file
TopLevelCMakeFileName=toplevel.cmake.txt
# The name of the source level CMake file
SrcLevelCMakeFileName=srclevel.cmake.txt
18 changes: 14 additions & 4 deletions src/AutoProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ bool AutoProject::createProject(bool overwrite) {
} else {
if (thislang == "c") {
srcfilename = fs::path(srcdir) / "main.c";
} else {
} else if (thislang == "c++") {
srcfilename = fs::path(srcdir) / "main.cpp";
}
} else if (thislang == "asm") {
srcfilename = fs::path(srcdir) / "main.asm";
}
}
if (firstFile) {
makeTree(overwrite);
Expand Down Expand Up @@ -150,8 +152,10 @@ bool AutoProject::createProject(bool overwrite) {
firstFile = false;
if (thislang == "c") {
srcfilename = fs::path(srcdir) / "main.c";
} else {
} else if (thislang == "c++") {
srcfilename = fs::path(srcdir) / "main.cpp";
} else if (thislang == "asm") {
srcfilename = fs::path(srcdir) / "main.asm";
}
srcfile.open(srcfilename);
if (srcfile) {
Expand Down Expand Up @@ -257,6 +261,7 @@ void AutoProject::checkRules(const std::string &line) {
void AutoProject::checkLanguageTags(const std::string& line) {
static const std::regex tagcpp{"### tags: \\[.*'c\\+\\+'.*\\]"};
static const std::regex tagc{"### tags: \\[.*'c'.*\\]"};
static const std::regex tagasm{"### tags: \\[.*'assembly'.*\\]"};
std::smatch pieces;
if (std::regex_match(line, pieces, tagcpp)) {
thislang = "c++";
Expand All @@ -268,6 +273,11 @@ void AutoProject::checkLanguageTags(const std::string& line) {
rules = loadrules(lang[thislang].rulesfilename);
toplevelfilename = lang[thislang].toplevelcmakefilename;
srclevelfilename = lang[thislang].srclevelcmakefilename;
} else if (std::regex_match(line, pieces, tagasm)) {
thislang = "asm";
rules = loadrules(lang[thislang].rulesfilename);
toplevelfilename = lang[thislang].toplevelcmakefilename;
srclevelfilename = lang[thislang].srclevelcmakefilename;
}
}

Expand All @@ -281,7 +291,7 @@ std::ostream& operator<<(std::ostream& out, const AutoProject &ap) {

/// returns true if passed file extension is an identified source code extension.
bool isSourceExtension(const std::string_view ext) {
static const std::unordered_set<std::string_view> source_extensions{".cpp", ".c", ".h", ".hpp"};
static const std::unordered_set<std::string_view> source_extensions{".cpp", ".c", ".h", ".hpp", ".asm"};
return source_extensions.find(ext) != source_extensions.end();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ int main(int argc, char *argv[]) {
configuration.lang["c"].toplevelcmakefilename = configuration.configfiledir + "/" + cfg.get_value("c", "Subdir") + "/" + cfg.get_value("c", "TopLevelCMakeFileName");
configuration.lang["c"].srclevelcmakefilename = configuration.configfiledir + "/" + cfg.get_value("c", "Subdir") + "/" + cfg.get_value("c", "SrcLevelCMakeFileName");

configuration.lang["asm"].rulesfilename = configuration.configfiledir + "/" + cfg.get_value("asm", "Subdir") + "/" + cfg.get_value("asm", "RulesFileName");
configuration.lang["asm"].toplevelcmakefilename = configuration.configfiledir + "/" + cfg.get_value("asm", "Subdir") + "/" + cfg.get_value("asm", "TopLevelCMakeFileName");
configuration.lang["asm"].srclevelcmakefilename = configuration.configfiledir + "/" + cfg.get_value("asm", "Subdir") + "/" + cfg.get_value("asm", "SrcLevelCMakeFileName");

if (argc - processed_args != 2) {
std::cerr << "Usage: autoproject project.md\nCreates a CMake build tree under 'project' subdirectory\n";
for (int i=processed_args+1; i < argc; ++i) {
Expand Down

0 comments on commit a96d8df

Please sign in to comment.