diff --git a/.gitignore b/.gitignore index 6aeb4efc9b6b4b14738f88f3796aeb913b110fd0..6b896c0655e8d1df9b4ecfa8a764e3f444515326 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,125 @@ libraries/draft/* compiler/*.o build/* /Makefile -/docs/_sidebar.md \ No newline at end of file +/docs/_sidebar.md + +# Created by https://www.toptal.com/developers/gitignore/api/flex,c++ +# Edit at https://www.toptal.com/developers/gitignore?templates=flex,c++ + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Linker files +*.ilk + +# Debugger Files +*.pdb + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### Flex ### + +# Build and Release Folders +bin/ +bin-debug/ +bin-release/ +.actionScriptProperties + +# only for a non-library project +.flexProperties + +# only for library project +.flexLibProperties + + +# Other files and folders +.settings/ +.project/ + +.FlexUnitSettings +.externalToolBuilders +.model + +# End of https://www.toptal.com/developers/gitignore/api/flex,c++ + +# http://www.gnu.org/software/automake + +Makefile.in +/ar-lib +/mdate-sh +/py-compile +/test-driver +/ylwrap +.deps/ +.dirstamp + +# http://www.gnu.org/software/autoconf + +autom4te.cache +/autoscan.log +/autoscan-*.log +/aclocal.m4 +/compile +/config.guess +/config.h.in +/config.log +/config.status +/config.sub +/configure +/configure~ +/configure.scan +/depcomp +/install-sh +/missing +/stamp-h1 + +# https://www.gnu.org/software/libtool/ + +/ltmain.sh + +# http://www.gnu.org/software/texinfo + +/texinfo.tex + +# http://www.gnu.org/software/m4/ + +m4/libtool.m4 +m4/ltoptions.m4 +m4/ltsugar.m4 +m4/ltversion.m4 +m4/lt~obsolete.m4 + +# Generated Makefile +# (meta build system like autotools, +# can automatically generate from config.status script +# (which is called by configure script)) +Makefile \ No newline at end of file diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index c8ec5df2d4439b59b1064370dfd2ae80d4629e5a..0000000000000000000000000000000000000000 --- a/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,6 +0,0 @@ -doxygen/doxygen_new_line_after_brief=true -doxygen/doxygen_use_brief_tag=false -doxygen/doxygen_use_javadoc_tags=true -doxygen/doxygen_use_pre_tag=false -doxygen/doxygen_use_structural_commands=false -eclipse.preferences.version=1 diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000000000000000000000000000000000..6ca08f277abb68ae91316ea28d21d280032d1552 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "daohong-emilio.yash" + ] +} \ No newline at end of file diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000000000000000000000000000000000000..2427a5c1f014d418f49ae16fb0c1c6bf651be61c --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +Authors +Yitong Dang (NaiveTomcat) +Bocheng Zou (uebian) +Yubo Zhao (zyb, qyuqxun) +Zichun Gong (gongzichun2) +Haoran Wang (haoran) +Anlan Zhao (zal) \ No newline at end of file diff --git a/COPYING b/COPYING new file mode 100644 index 0000000000000000000000000000000000000000..efc5d950ffda0b83e893ed3e5877f679122dac21 --- /dev/null +++ b/COPYING @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000000000000000000000000000000000000..d49893cd615b349bf16896f8eee0c1820a6817ee --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ +Since AloLang Compiler is still under heavy development, no changelog is available \ No newline at end of file diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000000000000000000000000000000000000..8865734f81b136629e961c230380423899c75794 --- /dev/null +++ b/INSTALL @@ -0,0 +1,368 @@ +Installation Instructions +************************* + + Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software +Foundation, Inc. + + Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. This file is offered as-is, +without warranty of any kind. + +Basic Installation +================== + + Briefly, the shell command './configure && make && make install' +should configure, build, and install this package. The following +more-detailed instructions are generic; see the 'README' file for +instructions specific to this package. Some packages provide this +'INSTALL' file but do not implement all of the features documented +below. The lack of an optional feature in a given package is not +necessarily a bug. More recommendations for GNU packages can be found +in *note Makefile Conventions: (standards)Makefile Conventions. + + The 'configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a 'Makefile' in each directory of the package. +It may also create one or more '.h' files containing system-dependent +definitions. Finally, it creates a shell script 'config.status' that +you can run in the future to recreate the current configuration, and a +file 'config.log' containing compiler output (useful mainly for +debugging 'configure'). + + It can also use an optional file (typically called 'config.cache' and +enabled with '--cache-file=config.cache' or simply '-C') that saves the +results of its tests to speed up reconfiguring. Caching is disabled by +default to prevent problems with accidental use of stale cache files. + + If you need to do unusual things to compile the package, please try +to figure out how 'configure' could check whether to do them, and mail +diffs or instructions to the address given in the 'README' so they can +be considered for the next release. If you are using the cache, and at +some point 'config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file 'configure.ac' (or 'configure.in') is used to create +'configure' by a program called 'autoconf'. You need 'configure.ac' if +you want to change it or regenerate 'configure' using a newer version of +'autoconf'. + + The simplest way to compile this package is: + + 1. 'cd' to the directory containing the package's source code and type + './configure' to configure the package for your system. + + Running 'configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type 'make' to compile the package. + + 3. Optionally, type 'make check' to run any self-tests that come with + the package, generally using the just-built uninstalled binaries. + + 4. Type 'make install' to install the programs and any data files and + documentation. When installing into a prefix owned by root, it is + recommended that the package be configured and built as a regular + user, and only the 'make install' phase executed with root + privileges. + + 5. Optionally, type 'make installcheck' to repeat any self-tests, but + this time using the binaries in their final installed location. + This target does not install anything. Running this target as a + regular user, particularly if the prior 'make install' required + root privileges, verifies that the installation completed + correctly. + + 6. You can remove the program binaries and object files from the + source code directory by typing 'make clean'. To also remove the + files that 'configure' created (so you can compile the package for + a different kind of computer), type 'make distclean'. There is + also a 'make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 7. Often, you can also type 'make uninstall' to remove the installed + files again. In practice, not all packages have tested that + uninstallation works correctly, even though it is required by the + GNU Coding Standards. + + 8. Some packages, particularly those that use Automake, provide 'make + distcheck', which can by used by developers to test that all other + targets like 'make install' and 'make uninstall' work correctly. + This target is generally not run by end users. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the 'configure' script does not know about. Run './configure --help' +for details on some of the pertinent environment variables. + + You can give 'configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here is +an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU 'make'. 'cd' to the +directory where you want the object files and executables to go and run +the 'configure' script. 'configure' automatically checks for the source +code in the directory that 'configure' is in and in '..'. This is known +as a "VPATH" build. + + With a non-GNU 'make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use 'make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple '-arch' options to the +compiler but only a single '-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the 'lipo' tool if you have problems. + +Installation Names +================== + + By default, 'make install' installs the package's commands under +'/usr/local/bin', include files under '/usr/local/include', etc. You +can specify an installation prefix other than '/usr/local' by giving +'configure' the option '--prefix=PREFIX', where PREFIX must be an +absolute file name. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option '--exec-prefix=PREFIX' to 'configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like '--bindir=DIR' to specify different values for particular +kinds of files. Run 'configure --help' for a list of the directories +you can set and what kinds of files go in them. In general, the default +for these options is expressed in terms of '${prefix}', so that +specifying just '--prefix' will affect all of the other directory +specifications that were not explicitly provided. + + The most portable way to affect installation locations is to pass the +correct locations to 'configure'; however, many packages provide one or +both of the following shortcuts of passing variable assignments to the +'make install' command line to change installation locations without +having to reconfigure or recompile. + + The first method involves providing an override variable for each +affected directory. For example, 'make install +prefix=/alternate/directory' will choose an alternate location for all +directory configuration variables that were expressed in terms of +'${prefix}'. Any directories that were specified during 'configure', +but not in terms of '${prefix}', must each be overridden at install time +for the entire installation to be relocated. The approach of makefile +variable overrides for each directory variable is required by the GNU +Coding Standards, and ideally causes no recompilation. However, some +platforms have known limitations with the semantics of shared libraries +that end up requiring recompilation when using this method, particularly +noticeable in packages that use GNU Libtool. + + The second method involves providing the 'DESTDIR' variable. For +example, 'make install DESTDIR=/alternate/directory' will prepend +'/alternate/directory' before all installation names. The approach of +'DESTDIR' overrides is not required by the GNU Coding Standards, and +does not work on platforms that have drive letters. On the other hand, +it does better at avoiding recompilation issues, and works well even +when some directory options were not specified in terms of '${prefix}' +at 'configure' time. + +Optional Features +================= + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving 'configure' the +option '--program-prefix=PREFIX' or '--program-suffix=SUFFIX'. + + Some packages pay attention to '--enable-FEATURE' options to +'configure', where FEATURE indicates an optional part of the package. +They may also pay attention to '--with-PACKAGE' options, where PACKAGE +is something like 'gnu-as' or 'x' (for the X Window System). The +'README' should mention any '--enable-' and '--with-' options that the +package recognizes. + + For packages that use the X Window System, 'configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the 'configure' options '--x-includes=DIR' and +'--x-libraries=DIR' to specify their locations. + + Some packages offer the ability to configure how verbose the +execution of 'make' will be. For these packages, running './configure +--enable-silent-rules' sets the default to minimal output, which can be +overridden with 'make V=1'; while running './configure +--disable-silent-rules' sets the default to verbose, which can be +overridden with 'make V=0'. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC +is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + HP-UX 'make' updates targets which have the same time stamps as their +prerequisites, which makes it generally unusable when shipped generated +files such as 'configure' are involved. Use GNU 'make' instead. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its '' header file. The option '-nodtk' can be used as a +workaround. If GNU CC is not installed, it is therefore recommended to +try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + + On Solaris, don't put '/usr/ucb' early in your 'PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in '/usr/bin'. So, if you need '/usr/ucb' +in your 'PATH', put it _after_ '/usr/bin'. + + On Haiku, software installed for all users goes in '/boot/common', +not '/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + +Specifying the System Type +========================== + + There may be some features 'configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, 'configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +'--build=TYPE' option. TYPE can either be a short name for the system +type, such as 'sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS + KERNEL-OS + + See the file 'config.sub' for the possible values of each field. If +'config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option '--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with '--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for 'configure' scripts to share, +you can create a site shell script called 'config.site' that gives +default values for variables like 'CC', 'cache_file', and 'prefix'. +'configure' looks for 'PREFIX/share/config.site' if it exists, then +'PREFIX/etc/config.site' if it exists. Or, you can set the +'CONFIG_SITE' environment variable to the location of the site script. +A warning: not all 'configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to 'configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the 'configure' command line, using 'VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified 'gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for 'CONFIG_SHELL' due to an +Autoconf limitation. Until the limitation is lifted, you can use this +workaround: + + CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash + +'configure' Invocation +====================== + + 'configure' recognizes the following options to control how it +operates. + +'--help' +'-h' + Print a summary of all of the options to 'configure', and exit. + +'--help=short' +'--help=recursive' + Print a summary of the options unique to this package's + 'configure', and exit. The 'short' variant lists options used only + in the top level, while the 'recursive' variant lists options also + present in any nested packages. + +'--version' +'-V' + Print the version of Autoconf used to generate the 'configure' + script, and exit. + +'--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally 'config.cache'. FILE defaults to '/dev/null' to + disable caching. + +'--config-cache' +'-C' + Alias for '--cache-file=config.cache'. + +'--quiet' +'--silent' +'-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to '/dev/null' (any error + messages will still be shown). + +'--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + 'configure' can determine that directory automatically. + +'--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: for + more details, including other options available for fine-tuning the + installation locations. + +'--no-create' +'-n' + Run the configure checks, but stop before creating any output + files. + +'configure' also accepts some other, not widely useful, options. Run +'configure --help' for more details. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..c3a63e1c890bbddd21268a89a22e1e58d84c2572 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = src src/lib +dist_doc_DATA = docs/README.md \ No newline at end of file diff --git a/Makefile.content b/Makefile.content deleted file mode 100644 index eb80d90de934a45ed3c2f9d88022f10f2472626c..0000000000000000000000000000000000000000 --- a/Makefile.content +++ /dev/null @@ -1,35 +0,0 @@ - -AST_SRCS := $(wildcard compiler/ast/*.cpp) -AST_OBJS_BUILD := $(addprefix build/,$(AST_SRCS:.cpp=.o)) -OBJ_DIR = build/ - -aloc: build/compiler/cppfront.o build/compiler/preprocessor.o build/compiler/utils.o build/compiler/CompileUnit.o build/compiler/Token.o $(AST_OBJS_BUILD) - $(CC) $(CFLAG) build/compiler/cppfront.o build/compiler/preprocessor.o build/compiler/utils.o build/compiler/CompileUnit.o build/compiler/Token.o $(AST_OBJS_BUILD) -lLLVM-11 -lboost_program_options -lstdc++ -o aloc - -build/compiler/preprocessor.o: compiler/preprocessor.cpp compiler/CompileError.hpp - $(CC) $(CFLAG) -c -I ./compiler/ compiler/preprocessor.cpp -o build/compiler/preprocessor.o - -build/compiler/cppfront.o: compiler/cppfront.cpp - $(CC) $(CFLAG) -c -I ./compiler/ compiler/cppfront.cpp -o build/compiler/cppfront.o - -build/compiler/utils.o: compiler/utils.cpp - $(CC) $(CFLAG) -c -I ./compiler/ compiler/utils.cpp -o build/compiler/utils.o - -build/compiler/CompileUnit.o: compiler/CompileUnit.cpp - $(CC) $(CFLAG) -c -I ./compiler/ compiler/CompileUnit.cpp -o build/compiler/CompileUnit.o - -build/compiler/Token.o: compiler/Token.cpp - $(CC) $(CFLAG) -c -I ./compiler/ compiler/Token.cpp -o build/compiler/Token.o - -$(AST_OBJS_BUILD):$(OBJ_DIR)%.o : %.cpp - $(CC) $(CFLAG) -c $< -o $@ - -.PHONY : clean,install,readytomake -install: aloc readytomake - mv aloc /usr/bin/ -clean: - -rm -r aloc build -readytomake: - mkdir -p build - mkdir -p build/compiler - mkdir -p build/compiler/ast diff --git a/NEWS b/NEWS new file mode 100644 index 0000000000000000000000000000000000000000..685facbb0738c7a1ef9f2e754a9b2efbaf967d22 --- /dev/null +++ b/NEWS @@ -0,0 +1 @@ +AloLang Compiler News \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000000000000000000000000000000000000..a559c2a21699465471384fb46237f11827283275 --- /dev/null +++ b/README @@ -0,0 +1,20 @@ +AloLang Compiler Readme + +Distributed under the Lesser General Public License V3 + +To compile, we suggest that you have the project made in a dedicated directory. +Use the following commands. + +mkdir -p build +cd build +../configure +make + +Now that you should see a file called aloc within the build directory. + +To install that to your system, run the following command + +make install + +It will copy the associated file to your system's program directory(possibly be +/usr/local/bin). \ No newline at end of file diff --git a/config.h.in~ b/config.h.in~ new file mode 100644 index 0000000000000000000000000000000000000000..e2993a5e4a460ca4ec793365c992529b5a6fa859 --- /dev/null +++ b/config.h.in~ @@ -0,0 +1,122 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `boost_program_options' library + (-lboost_program_options). */ +#undef HAVE_LIBBOOST_PROGRAM_OPTIONS + +/* Define to 1 if you have the `LLVM-11' library (-lLLVM-11). */ +#undef HAVE_LIBLLVM_11 + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#undef HAVE_REALLOC + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#undef STDC_HEADERS + +/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a + `char[]'. */ +#undef YYTEXT_POINTER + +/* Define for Solaris 2.5.1 so the uint32_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT32_T + +/* Define for Solaris 2.5.1 so the uint8_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT8_T + +/* Define to the type of a signed integer type of width exactly 16 bits if + such a type exists and the standard includes do not define it. */ +#undef int16_t + +/* Define to the type of a signed integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +#undef int32_t + +/* Define to the type of a signed integer type of width exactly 8 bits if such + a type exists and the standard includes do not define it. */ +#undef int8_t + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc + +/* Define to rpl_realloc if the replacement function should be used. */ +#undef realloc + +/* Define to `unsigned int' if does not define. */ +#undef size_t + +/* Define to the type of an unsigned integer type of width exactly 16 bits if + such a type exists and the standard includes do not define it. */ +#undef uint16_t + +/* Define to the type of an unsigned integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +#undef uint32_t + +/* Define to the type of an unsigned integer type of width exactly 8 bits if + such a type exists and the standard includes do not define it. */ +#undef uint8_t diff --git a/configure b/configure deleted file mode 100755 index 57c1b6aa1f5f832fea328e723522217733adaf74..0000000000000000000000000000000000000000 --- a/configure +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -./make-config > tmpcfg -cat tmpcfg Makefile.content > Makefile -rm tmpcfg \ No newline at end of file diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000000000000000000000000000000000000..9551bec7d32fccc452cf27aa8e99d51c1a3ba1b4 --- /dev/null +++ b/configure.ac @@ -0,0 +1,45 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.70]) +AC_INIT([AloLang Compiler], [Dev Beta], [https://github.com/XJTU-Youth/AloLang-Dev/issues]) +AC_CONFIG_SRCDIR([src/aloc.cpp]) +AC_CONFIG_HEADERS([config.h]) + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AC_PROG_LEX(noyywrap) +AC_PROG_RANLIB + +# Checks for libraries. +# FIXME: Replace 'main' with a function in '-lboost_program_options': +AC_CHECK_LIB([boost_program_options], [boost::program_options::strip_prefixes]) +AC_CHECK_LIB([LLVM-11], [llvm::demangle]) + +# Checks for header files. +AC_CHECK_HEADERS([inttypes.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT8_T +AC_TYPE_SIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT8_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_CHECK_FUNCS([memset strtol]) + +AC_CONFIG_FILES([ + Makefile + src/Makefile + src/lib/Makefile +]) + +AM_INIT_AUTOMAKE +AC_OUTPUT diff --git a/make-config b/make-config deleted file mode 100755 index dd5c8b3b38e0158ac593996c268369109fddfba0..0000000000000000000000000000000000000000 Binary files a/make-config and /dev/null differ diff --git a/make-config.cc b/make-config.cc deleted file mode 100644 index 56f0ea17f6b370fb69809f83ab39ad648dbcfada..0000000000000000000000000000000000000000 --- a/make-config.cc +++ /dev/null @@ -1,25 +0,0 @@ -#include -using namespace std; - -int main() -{ - string tmp1, tmp2; - cerr << "Specifi compiler path: "; - getline(cin, tmp1); - tmp2 = "CC = "; - tmp2 += tmp1; - cout << tmp2 << endl; - - cerr << "Specifi ar path: "; - getline(cin, tmp1); - tmp2 = "AR = "; - tmp2 += tmp1; - cout << tmp2 << endl; - - cerr << "Specifi compile flag(include include path): "; - getline(cin, tmp1); - tmp2 = "CFLAG = "; - tmp2 += tmp1; - cout << tmp2 << endl; - -} \ No newline at end of file diff --git a/compiler/CompileError.hpp b/src/CompileError.hpp similarity index 100% rename from compiler/CompileError.hpp rename to src/CompileError.hpp diff --git a/compiler/CompileUnit.cpp b/src/CompileUnit.cpp similarity index 49% rename from compiler/CompileUnit.cpp rename to src/CompileUnit.cpp index 5b493c228098434d78730c74e610d39a25535a90..74aadd0a275d6cff0c35628d69427c15080021ca 100644 --- a/compiler/CompileUnit.cpp +++ b/src/CompileUnit.cpp @@ -25,6 +25,7 @@ CompileUnit::CompileUnit(std::string name, std::string source) { this->name = name; this->source = source; this->sis = std::istringstream(source); + this->lexer = new yyFlexLexer(sis, std::cerr); context = new llvm::LLVMContext(); module = new llvm::Module("test.ll", *context); } @@ -35,88 +36,32 @@ CompileUnit::~CompileUnit() { //获取下一个Token Token CompileUnit::next_tok() { Token token; - skipSpace(sis); - char lastChar = sis.get(); - std::string dataStr; - if (std::isalpha(lastChar)) { // 标志符: [a-zA-Z][a-zA-Z0-9]* - dataStr = lastChar; - while (!isSyntax((lastChar = sis.peek()))) { - lastChar = sis.get(); - dataStr += lastChar; - } - if (dataStr == "fun") { - token.type = tok_fun; - return token; - } - if (dataStr == "func") { - token.type = tok_fun; - return token; - } - if (dataStr == "extern") { - token.type = tok_extern; - return token; - } - if (dataStr == "return") { - token.type = tok_return; - return token; - } - - token.tokenValue = dataStr; - token.type = tok_identifier; - return token; + int tokenid = lexer->yylex(); + token.type = TokenType(tokenid); + switch (token.type) { + tok_fun: + tok_extern: + tok_return: + tok_return_type: + tok_eof: break; + default: token.tokenValue = lexer->YYText(); } - if (lastChar == '-' && sis.peek() == '>') { - sis.get(); - token.type = tok_return_type; - return token; - } - int numTypeFlag = 10; //进制数 - int statusFlag = 0; //0未处理进制标识,1正在处理进制标识,2已处理进制标识 - //TODO 对浮点数的支持,对非long型数的支持 - bool firstRun = true; - if (std::isdigit(lastChar) || lastChar == '.') { // 数字: [0-9.]+ - do { - if (!firstRun) { - sis.get(); - } else { - firstRun = false; - } - if (statusFlag == 1) { - if (lastChar == 'b') { - numTypeFlag = 2; - } else if (lastChar == 'x' || lastChar == 'X') { - numTypeFlag = 16; - } else if (std::isdigit(lastChar)) { - numTypeFlag = 8; - dataStr += lastChar; - } else { - dataStr = "0"; - } - statusFlag = 2; - lastChar = sis.peek(); - continue; - } - if (lastChar == '0' && statusFlag == 0) { - statusFlag = 1; - lastChar = sis.peek(); - continue; - } - dataStr += lastChar; - lastChar = sis.peek(); - } while (!isSyntax(lastChar)); - token.type = tok_number; + //Deal with numbers + if (token.type == tok_number) + { + int numTypeFlag = 10; //进制数 + if (token.tokenValue.substr(0, 2) == "0x" || token.tokenValue.substr(0, 2) == "0X") + numTypeFlag = 16; + else if (token.tokenValue.substr(0, 2) == "0b" || token.tokenValue.substr(0, 2) == "0B") + numTypeFlag = 2; + else if (token.tokenValue.substr(0, 1) == "0") + numTypeFlag = 8; char tmp[256]; - sprintf(tmp, "%ld", strtol(dataStr.c_str(), NULL, numTypeFlag)); + sprintf(tmp, "%ld", strtol(token.tokenValue.c_str(), NULL, numTypeFlag)); token.tokenValue = tmp; - return token; - } - if (lastChar == EOF) { - token.type = tok_eof; - return token; } - token.type = tok_syntax; - token.tokenValue = lastChar; - return token; //todo:可能不严谨,仔细test + // std::cout << token.dump() << std::endl; + return token; } void CompileUnit::compile() { @@ -126,8 +71,8 @@ void CompileUnit::compile() { switch (curTok.type) { case tok_fun: { - FunctionAST *func_ast = FunctionAST::ParseFunction(this); - llvm::Function *func = func_ast->Codegen(); + FunctionAST* func_ast = FunctionAST::ParseFunction(this); + llvm::Function* func = func_ast->Codegen(); /*llvm::Type* type=llvm::FunctionType::get(llvm::Type::getVoidTy(*context), false); module->getOrInsertGlobal(func_ast->proto->name, func->getType()); diff --git a/compiler/CompileUnit.h b/src/CompileUnit.h similarity index 93% rename from compiler/CompileUnit.h rename to src/CompileUnit.h index e99a51c6e8dac2ba93bdb54dd3d2aaaf1fa0f538..7d97b4e553dd46160402dcf15a37bc3c0609a960 100644 --- a/compiler/CompileUnit.h +++ b/src/CompileUnit.h @@ -13,6 +13,7 @@ #include "Token.h" #include #include +#include class CompileUnit { public: @@ -22,6 +23,8 @@ public: Token next_tok(); void build(); + FlexLexer* lexer; + std::string name; std::string source; std::istringstream sis; diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..cb640c7c2cce0a6b48b4a3987e6e5b1cbc8e29cf --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,16 @@ +AUTOMAKE_OPTIONS = foreign subdir-objects +bin_PROGRAMS = aloc +aloc_SOURCES = aloc.cpp CompileUnit.cpp preprocessor.cpp Token.cpp utils.cpp\ + ast/BaseAST.cpp ast/CallExprAST.cpp ast/CodeBlockAST.cpp ast/ExprAST.cpp\ + ast/ExternAST.cpp ast/FunctionAST.cpp ast/IntExprAST.cpp ast/PrototypeAST.cpp\ + ast/VariableExprAST.cpp yacc_stuff/tokenizer.ll + +AM_LFLAGS = -otokenizer.cc + +ldflagsLLVM := $(shell llvm-config --ldflags) +cxxflagsLLVM := $(shell llvm-config --cxxflags) +libLLVM := $(shell llvm-config --libs) +includeLLVM := $(shell llvm-config --includedir) + +aloc_CPPFLAGS = $(cxxflagsLLVM) -I$(includeLLVM) -I$(srcdir) -fexceptions +aloc_LDFLAGS = $(ldflagsLLVM) $(libLLVM) -lboost_program_options diff --git a/compiler/Token.cpp b/src/Token.cpp similarity index 100% rename from compiler/Token.cpp rename to src/Token.cpp diff --git a/compiler/Token.h b/src/Token.h similarity index 100% rename from compiler/Token.h rename to src/Token.h diff --git a/compiler/cppfront.cpp b/src/aloc.cpp similarity index 89% rename from compiler/cppfront.cpp rename to src/aloc.cpp index c8db1518dd361c669d2db50c9007ff5bfd191859..01e215dc29de1b1d4719415d16df36fb44e269cb 100644 --- a/compiler/cppfront.cpp +++ b/src/aloc.cpp @@ -1,4 +1,4 @@ -#include +#include "CompileError.hpp" #include #include #include @@ -25,6 +25,7 @@ namespace po = boost::program_options; std::vector input_file_names; std::string output_file_name; +std::string alolanglibdir; int main(int argc, char *argv[]) { try { @@ -39,6 +40,7 @@ int main(int argc, char *argv[]) { // config file po::options_description config("Configuration"); config.add_options()("output,o", po::value(), "output file"); + config.add_options()("alolanglib,L", po::value(), "Alolang Core Library Position, default to src/lib"); // Hidden options, will be allowed both on command line and // in config file, but will not be shown to the user. @@ -74,6 +76,11 @@ int main(int argc, char *argv[]) { if (vm.count("input-file")) { input_file_names = vm["input-file"].as>(); + if (vm.count("alolanglib")) + alolanglibdir = vm["alolanglib"].as(); + else + output_file_name = "src/lib"; + for (std::string input_file_name : input_file_names) { if (vm.count("output")) output_file_name = vm["output"].as(); @@ -113,7 +120,7 @@ int main(int argc, char *argv[]) { for (std::string input_file_name : input_file_names) { objs += "./" + input_file_name + ".s "; } - std::string cmdline = "gcc" + objs + " -fPIE -o " + std::string cmdline = "gcc" + objs + " -fPIE -L " + alolanglibdir + " -l alolangcore" + " -o " + output_file_name; std::cout << "debug info:" << cmdline << std::endl; system(cmdline.c_str()); diff --git a/src/ast/AllAST.h b/src/ast/AllAST.h new file mode 100644 index 0000000000000000000000000000000000000000..fd5e3a29a5b6ffe3225eae85dc1e8046af522aab --- /dev/null +++ b/src/ast/AllAST.h @@ -0,0 +1,23 @@ +/* + * AllAST.h + * + * Created on: Feb 14, 2021 + * Author: tomdang + * + * Wrapper header for all AST headers + */ + +#ifndef _ALLAST_H_ +#define _ALLAST_H_ + +#include "BaseAST.h" +#include "CallExprAST.h" +#include "CodeBlockAST.h" +#include "ExprAST.h" +#include "ExternAST.h" +#include "FunctionAST.h" +#include "IntExprAST.h" +#include "PrototypeAST.h" +#include "VariableExprAST.h" + +#endif \ No newline at end of file diff --git a/compiler/ast/BaseAST.cpp b/src/ast/BaseAST.cpp similarity index 100% rename from compiler/ast/BaseAST.cpp rename to src/ast/BaseAST.cpp diff --git a/compiler/ast/BaseAST.h b/src/ast/BaseAST.h similarity index 100% rename from compiler/ast/BaseAST.h rename to src/ast/BaseAST.h diff --git a/compiler/ast/CallExprAST.cpp b/src/ast/CallExprAST.cpp similarity index 100% rename from compiler/ast/CallExprAST.cpp rename to src/ast/CallExprAST.cpp diff --git a/compiler/ast/CallExprAST.h b/src/ast/CallExprAST.h similarity index 100% rename from compiler/ast/CallExprAST.h rename to src/ast/CallExprAST.h diff --git a/compiler/ast/CodeBlockAST.cpp b/src/ast/CodeBlockAST.cpp similarity index 100% rename from compiler/ast/CodeBlockAST.cpp rename to src/ast/CodeBlockAST.cpp diff --git a/compiler/ast/CodeBlockAST.h b/src/ast/CodeBlockAST.h similarity index 100% rename from compiler/ast/CodeBlockAST.h rename to src/ast/CodeBlockAST.h diff --git a/compiler/ast/ExprAST.cpp b/src/ast/ExprAST.cpp similarity index 100% rename from compiler/ast/ExprAST.cpp rename to src/ast/ExprAST.cpp diff --git a/compiler/ast/ExprAST.h b/src/ast/ExprAST.h similarity index 100% rename from compiler/ast/ExprAST.h rename to src/ast/ExprAST.h diff --git a/compiler/ast/ExternAST.cpp b/src/ast/ExternAST.cpp similarity index 100% rename from compiler/ast/ExternAST.cpp rename to src/ast/ExternAST.cpp diff --git a/compiler/ast/ExternAST.h b/src/ast/ExternAST.h similarity index 100% rename from compiler/ast/ExternAST.h rename to src/ast/ExternAST.h diff --git a/compiler/ast/FunctionAST.cpp b/src/ast/FunctionAST.cpp similarity index 100% rename from compiler/ast/FunctionAST.cpp rename to src/ast/FunctionAST.cpp diff --git a/compiler/ast/FunctionAST.h b/src/ast/FunctionAST.h similarity index 100% rename from compiler/ast/FunctionAST.h rename to src/ast/FunctionAST.h diff --git a/compiler/ast/IntExprAST.cpp b/src/ast/IntExprAST.cpp similarity index 100% rename from compiler/ast/IntExprAST.cpp rename to src/ast/IntExprAST.cpp diff --git a/compiler/ast/IntExprAST.h b/src/ast/IntExprAST.h similarity index 100% rename from compiler/ast/IntExprAST.h rename to src/ast/IntExprAST.h diff --git a/compiler/ast/PrototypeAST.cpp b/src/ast/PrototypeAST.cpp similarity index 100% rename from compiler/ast/PrototypeAST.cpp rename to src/ast/PrototypeAST.cpp diff --git a/compiler/ast/PrototypeAST.h b/src/ast/PrototypeAST.h similarity index 100% rename from compiler/ast/PrototypeAST.h rename to src/ast/PrototypeAST.h diff --git a/compiler/ast/VariableExprAST.cpp b/src/ast/VariableExprAST.cpp similarity index 100% rename from compiler/ast/VariableExprAST.cpp rename to src/ast/VariableExprAST.cpp diff --git a/compiler/ast/VariableExprAST.h b/src/ast/VariableExprAST.h similarity index 100% rename from compiler/ast/VariableExprAST.h rename to src/ast/VariableExprAST.h diff --git a/compiler/ast/todo b/src/ast/todo similarity index 100% rename from compiler/ast/todo rename to src/ast/todo diff --git a/compiler/test/test03.alo.ac b/src/autoscan.log similarity index 100% rename from compiler/test/test03.alo.ac rename to src/autoscan.log diff --git a/src/config.log b/src/config.log new file mode 100644 index 0000000000000000000000000000000000000000..7f82c008acdc9d547bf4f1c7a281b35749448e72 --- /dev/null +++ b/src/config.log @@ -0,0 +1,159 @@ +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by AloLang Compiler configure Dev Beta, which was +generated by GNU Autoconf 2.70. Invocation command line was + + $ ./configure + +## --------- ## +## Platform. ## +## --------- ## + +hostname = Deskmini-A300 +uname -m = x86_64 +uname -r = 5.10.10-arch1-1 +uname -s = Linux +uname -v = #1 SMP PREEMPT Sat, 23 Jan 2021 23:59:48 +0000 + +/usr/bin/uname -p = unknown +/bin/uname -X = unknown + +/bin/arch = unknown +/usr/bin/arch -k = unknown +/usr/convex/getsysinfo = unknown +/usr/bin/hostinfo = unknown +/bin/machine = unknown +/usr/bin/oslevel = unknown +/bin/universe = unknown + +PATH: /usr/local/sbin/ +PATH: /usr/local/bin/ +PATH: /usr/bin/ +PATH: /usr/lib/jvm/default/bin/ +PATH: /opt/nessus/bin/ +PATH: /opt/nessus/sbin/ +PATH: /usr/bin/site_perl/ +PATH: /usr/bin/vendor_perl/ +PATH: /usr/bin/core_perl/ +PATH: /var/lib/snapd/snap/bin/ +PATH: /home/tomdang/go/bin/ +PATH: /home/tomdang/go/bin/ + + +## ----------- ## +## Core tests. ## +## ----------- ## + +configure:2735: looking for aux files: config.guess config.sub +configure:2748: trying ./ +configure:2748: trying ./../ +configure:2748: trying ./../../ +configure:2801: error: cannot find required auxiliary files: config.guess config.sub + +## ---------------- ## +## Cache variables. ## +## ---------------- ## + +ac_cv_env_CCC_set= +ac_cv_env_CCC_value= +ac_cv_env_CC_set= +ac_cv_env_CC_value= +ac_cv_env_CFLAGS_set= +ac_cv_env_CFLAGS_value= +ac_cv_env_CPPFLAGS_set= +ac_cv_env_CPPFLAGS_value= +ac_cv_env_CXXFLAGS_set= +ac_cv_env_CXXFLAGS_value= +ac_cv_env_CXX_set= +ac_cv_env_CXX_value= +ac_cv_env_LDFLAGS_set= +ac_cv_env_LDFLAGS_value= +ac_cv_env_LIBS_set= +ac_cv_env_LIBS_value= +ac_cv_env_build_alias_set= +ac_cv_env_build_alias_value= +ac_cv_env_host_alias_set= +ac_cv_env_host_alias_value= +ac_cv_env_target_alias_set= +ac_cv_env_target_alias_value= + +## ----------------- ## +## Output variables. ## +## ----------------- ## + +CC='' +CFLAGS='' +CPPFLAGS='' +CXX='' +CXXFLAGS='' +DEFS='' +ECHO_C='' +ECHO_N='-n' +ECHO_T='' +EXEEXT='' +FLEX_CHECK='' +LDFLAGS='' +LIBOBJS='' +LIBS='' +LLVM_CHECK='' +LTLIBOBJS='' +OBJEXT='' +PACKAGE_BUGREPORT='https://github.com/XJTU-Youth/AloLang-Dev/issues' +PACKAGE_NAME='AloLang Compiler' +PACKAGE_STRING='AloLang Compiler Dev Beta' +PACKAGE_TARNAME='alolang-compiler' +PACKAGE_URL='' +PACKAGE_VERSION='Dev Beta' +PATH_SEPARATOR=':' +SHELL='/bin/sh' +ac_ct_CC='' +ac_ct_CXX='' +bindir='${exec_prefix}/bin' +build='' +build_alias='' +build_cpu='' +build_os='' +build_vendor='' +datadir='${datarootdir}' +datarootdir='${prefix}/share' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +dvidir='${docdir}' +exec_prefix='NONE' +host='' +host_alias='' +host_cpu='' +host_os='' +host_vendor='' +htmldir='${docdir}' +includedir='${prefix}/include' +infodir='${datarootdir}/info' +libdir='${exec_prefix}/lib' +libexecdir='${exec_prefix}/libexec' +localedir='${datarootdir}/locale' +localstatedir='${prefix}/var' +mandir='${datarootdir}/man' +oldincludedir='/usr/include' +pdfdir='${docdir}' +prefix='NONE' +program_transform_name='s,x,x,' +psdir='${docdir}' +runstatedir='${localstatedir}/run' +sbindir='${exec_prefix}/sbin' +sharedstatedir='${prefix}/com' +sysconfdir='${prefix}/etc' +target_alias='' + +## ----------- ## +## confdefs.h. ## +## ----------- ## + +/* confdefs.h */ +#define PACKAGE_NAME "AloLang Compiler" +#define PACKAGE_TARNAME "alolang-compiler" +#define PACKAGE_VERSION "Dev Beta" +#define PACKAGE_STRING "AloLang Compiler Dev Beta" +#define PACKAGE_BUGREPORT "https://github.com/XJTU-Youth/AloLang-Dev/issues" +#define PACKAGE_URL "" + +configure: exit 1 diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..caaa9175c322c75e6547603f19100c3dc1fd2ccf --- /dev/null +++ b/src/lib/Makefile.am @@ -0,0 +1,3 @@ +AUTOMAKE_OPTIONS = foreign +lib_LIBRARIES = libalolangcore.a +libalolangcore_a_SOURCES = testPuts.c diff --git a/src/lib/testPuts.c b/src/lib/testPuts.c new file mode 100644 index 0000000000000000000000000000000000000000..43797a33d0d93bf507259b3a8fc189e155742271 --- /dev/null +++ b/src/lib/testPuts.c @@ -0,0 +1,5 @@ +#include + +extern void _alolang_8testPuts(void){ + puts("AloLang Test Function"); +} \ No newline at end of file diff --git a/compiler/preprocessor.cpp b/src/preprocessor.cpp similarity index 100% rename from compiler/preprocessor.cpp rename to src/preprocessor.cpp diff --git a/compiler/preprocessor.h b/src/preprocessor.h similarity index 100% rename from compiler/preprocessor.h rename to src/preprocessor.h diff --git a/compiler/todo.md b/src/todo.md similarity index 100% rename from compiler/todo.md rename to src/todo.md diff --git a/compiler/utils.cpp b/src/utils.cpp similarity index 100% rename from compiler/utils.cpp rename to src/utils.cpp diff --git a/compiler/utils.h b/src/utils.h similarity index 100% rename from compiler/utils.h rename to src/utils.h diff --git a/src/yacc_stuff/tokenizer.ll b/src/yacc_stuff/tokenizer.ll new file mode 100644 index 0000000000000000000000000000000000000000..013bac8f159106bc5b54d90f78b37b215abe1bf5 --- /dev/null +++ b/src/yacc_stuff/tokenizer.ll @@ -0,0 +1,117 @@ +%{ +#include "../Token.h" +#include +#include +int token; + +%} +%option yylineno +%option c++ +%% +[ \t]+ {/*Skip spaces and tabs*/}; +\/\*[.\n]*?\*\/|\/\/.* {/*Skip comments*/}; + +-> token = tok_return_type; return token; +fun token = tok_fun; return token; +func token = tok_fun; return token; +extern token = tok_extern; return token; +return token = tok_extern; return token; +[a-zA-Z_][a-zA-Z0-9_]* token = tok_identifier; return token; +0b[01]* token = tok_number; return token; +0x[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0B[01]* token = tok_number; return token; +0X[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0[1-7][0-7]* token = tok_number; return token; +[1-9][0-9.]* token = tok_number; return token; +0 token = tok_number; return token; + +! token = tok_syntax; return token; +% token = tok_syntax; return token; +\^ token = tok_syntax; return token; +& token = tok_syntax; return token; +\* token = tok_syntax; return token; +\( token = tok_syntax; return token; +\) token = tok_syntax; return token; +\+ token = tok_syntax; return token; += token = tok_syntax; return token; +\{ token = tok_syntax; return token; +\} token = tok_syntax; return token; +\| token = tok_syntax; return token; +~ token = tok_syntax; return token; +\[ token = tok_syntax; return token; +\] token = tok_syntax; return token; +\\ token = tok_syntax; return token; +; token = tok_syntax; return token; +' token = tok_syntax; return token; +: token = tok_syntax; return token; +\" token = tok_syntax; return token; +, token = tok_syntax; return token; +\< token = tok_syntax; return token; +\> token = tok_syntax; return token; +\? token = tok_syntax; return token; +\. token = tok_syntax; return token; +\/ token = tok_syntax; return token; +# token = tok_syntax; return token; +<> {token = tok_eof; return token;} +. token = tok_err; return token; +%% + +int yyFlexLexer::yywrap(){return 1;} +%{ +#include "../Token.h" +#include +#include +int token; + +%} +%option yylineno +%% +[ \t]+ {/*Skip spaces and tabs*/}; +\/\*[.\n]*?\*\/|\/\/.* {/*Skip comments*/}; + +-> token = tok_return_type; return token; +fun token = tok_fun; return token; +func token = tok_fun; return token; +extern token = tok_extern; return token; +return token = tok_extern; return token; +[a-zA-Z_][a-zA-Z0-9_]* token = tok_identifier; return token; +0b[01]* token = tok_number; return token; +0x[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0B[01]* token = tok_number; return token; +0X[1-9a-fA-F][0-9a-fA-F]* token = tok_number; return token; +0[1-7][0-7]* token = tok_number; return token; +[1-9][0-9.]* token = tok_number; return token; +0 token = tok_number; return token; + +! token = tok_syntax; return token; +% token = tok_syntax; return token; +\^ token = tok_syntax; return token; +& token = tok_syntax; return token; +\* token = tok_syntax; return token; +\( token = tok_syntax; return token; +\) token = tok_syntax; return token; +\+ token = tok_syntax; return token; += token = tok_syntax; return token; +\{ token = tok_syntax; return token; +\} token = tok_syntax; return token; +\| token = tok_syntax; return token; +~ token = tok_syntax; return token; +\[ token = tok_syntax; return token; +\] token = tok_syntax; return token; +\\ token = tok_syntax; return token; +; token = tok_syntax; return token; +' token = tok_syntax; return token; +: token = tok_syntax; return token; +\" token = tok_syntax; return token; +, token = tok_syntax; return token; +\< token = tok_syntax; return token; +\> token = tok_syntax; return token; +\? token = tok_syntax; return token; +\. token = tok_syntax; return token; +\/ token = tok_syntax; return token; +# token = tok_syntax; return token; +<> {token = tok_eof; return token;} +. token = tok_error; return token; +%% + +int yyFlexLexer::yywrap(){return 1;} diff --git a/test.alo.bc b/test.alo.bc new file mode 100644 index 0000000000000000000000000000000000000000..f8e1297a94ac8ffdc5da4ca8b6f3dbc47e4e015a Binary files /dev/null and b/test.alo.bc differ diff --git a/test.alo.ll b/test.alo.ll new file mode 100644 index 0000000000000000000000000000000000000000..1cfe5c4e3b22c5f8a2f744ce39701c5872debb97 --- /dev/null +++ b/test.alo.ll @@ -0,0 +1,15 @@ +; ModuleID = './test.alo.bc' +source_filename = "test.ll" + +declare void @_alolang_8testPuts() + +define void @"_alolang_2te1(1a3int"(i64 %int, i64 %",", i64 %b) { +entry: + ret void +} + +define void @main() { +entry: + call void @_alolang_8testPuts() + ret void +} diff --git a/test.alo.s b/test.alo.s new file mode 100644 index 0000000000000000000000000000000000000000..742b5fd402c7982b7e5a6ade8c2aae685f20ff37 --- /dev/null +++ b/test.alo.s @@ -0,0 +1,30 @@ + .text + .file "test.ll" + .globl "_alolang_2te1(1a3int" # -- Begin function _alolang_2te1(1a3int + .p2align 4, 0x90 + .type "_alolang_2te1(1a3int",@function +"_alolang_2te1(1a3int": # @"_alolang_2te1(1a3int" + .cfi_startproc +# %bb.0: # %entry + retq +.Lfunc_end0: + .size "_alolang_2te1(1a3int", .Lfunc_end0-"_alolang_2te1(1a3int" + .cfi_endproc + # -- End function + .globl main # -- Begin function main + .p2align 4, 0x90 + .type main,@function +main: # @main + .cfi_startproc +# %bb.0: # %entry + pushq %rax + .cfi_def_cfa_offset 16 + callq _alolang_8testPuts@PLT + popq %rax + .cfi_def_cfa_offset 8 + retq +.Lfunc_end1: + .size main, .Lfunc_end1-main + .cfi_endproc + # -- End function + .section ".note.GNU-stack","",@progbits diff --git a/compiler/test/demo.alo b/test/demo.alo similarity index 100% rename from compiler/test/demo.alo rename to test/demo.alo diff --git a/compiler/test/demo.alo.bc b/test/demo.alo.bc similarity index 100% rename from compiler/test/demo.alo.bc rename to test/demo.alo.bc diff --git a/compiler/test/demo.alo.s b/test/demo.alo.s similarity index 100% rename from compiler/test/demo.alo.s rename to test/demo.alo.s diff --git a/compiler/test/module b/test/module similarity index 100% rename from compiler/test/module rename to test/module diff --git a/compiler/test/module.ll b/test/module.ll similarity index 100% rename from compiler/test/module.ll rename to test/module.ll diff --git a/compiler/test/module.s b/test/module.s similarity index 100% rename from compiler/test/module.s rename to test/module.s diff --git a/compiler/test/test01.alo b/test/test01.alo similarity index 100% rename from compiler/test/test01.alo rename to test/test01.alo diff --git a/compiler/test/test02.alo b/test/test02.alo similarity index 100% rename from compiler/test/test02.alo rename to test/test02.alo diff --git a/compiler/test/test03.alo b/test/test03.alo similarity index 100% rename from compiler/test/test03.alo rename to test/test03.alo diff --git a/test/test03.alo.ac b/test/test03.alo.ac new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/compiler/test/types b/test/types similarity index 100% rename from compiler/test/types rename to test/types diff --git a/compiler/test/alo.out b/test02demo similarity index 59% rename from compiler/test/alo.out rename to test02demo index 1b0e3a17dcc1671b38facdc6186c7d8f0035044d..df8dbb31e199f6fa8f79835453f1e3773bb0091b 100755 Binary files a/compiler/test/alo.out and b/test02demo differ diff --git a/testdemo b/testdemo new file mode 100755 index 0000000000000000000000000000000000000000..df8dbb31e199f6fa8f79835453f1e3773bb0091b Binary files /dev/null and b/testdemo differ diff --git a/tools/demangle b/tools/demangle index 80d2807006a03bb99018f1a4039882680ebb027c..7e73da6f7a34a10bedc2f780789d237db2ea0fc2 100755 Binary files a/tools/demangle and b/tools/demangle differ diff --git a/tools/demangle.cpp b/tools/demangle.cpp index b95bff1ebbb79ce1da98c7ca18b751e6bd88e0d5..a172413386e005741697110c848f06a454593757 100644 --- a/tools/demangle.cpp +++ b/tools/demangle.cpp @@ -1,5 +1,5 @@ #include -#include "../CompileError.hpp" +#include "../src/CompileError.hpp" using namespace std; @@ -94,6 +94,15 @@ std::string demangle(const std::string& line) { int main(int argc, char* argv[]) { + try + { cout << demangle(argv[1]) << endl; return 0; } + + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + +} \ No newline at end of file