Skip to content
Open
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
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,23 @@
<maven.test.failure.ignore>false</maven.test.failure.ignore>
</properties>
</profile>
<profile>
<id>llvm-integration-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<systemPropertyVariables>
<methodscript_run_llvm_integration_tests>true</methodscript_run_llvm_integration_tests>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<pluginRepositories>
<pluginRepository>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/laytonsmith/core/asm/AsmCommonLibTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ private static void register(String code, Environment env) {
register("declare dso_local i32 @time(...)", env);
};

/**
* C Standard
*/
public static final Generator STRCMP = (env) -> {
register("declare dso_local i32 @strcmp(i8*, i8*)", env);
};

/**
* C Standard
*/
public static final Generator STRLEN = (env) -> {
register("declare dso_local i64 @strlen(i8*)", env);
};

public static final Generator LLVM_MEMCPY_P0I8_P0I8_I64 = (env) -> {
register("declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) nounwind", env);
};
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/laytonsmith/core/asm/AsmCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public void compileEntryPoint(File file, File outputDirectory, String exeName)
}
StringBuilder program = new StringBuilder();
llvmenv.newMethodFrame("@main");
llvmenv.pushVariableScope();
// TODO: Eventually add the argument processing for this
// Pop 0..2 for the main args and entry label
llvmenv.getNewLocalVariableReference(IRType.INTEGER32);
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/com/laytonsmith/core/asm/AsmMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,28 @@
*/
public class AsmMain {

private static void LogErrorAndQuit(String error, int code) {
StreamUtils.GetSystemErr().println(TermColors.RED + error + TermColors.RESET);
System.exit(code);
}

@tool(value = "asm", undocumented = true)
public static class AsmMainCmdlineTool extends AbstractCommandLineTool {

private boolean throwOnError = false;

/**
* When set to true, errors that would normally call System.exit will instead throw a
* RuntimeException. This is intended for use in test environments where System.exit
* would kill the test runner.
*/
public void setThrowOnError(boolean value) {
this.throwOnError = value;
}

private void logErrorAndQuit(String error, int code) {
StreamUtils.GetSystemErr().println(TermColors.RED + error + TermColors.RESET);
if(throwOnError) {
throw new RuntimeException("ASM compilation failed (exit code " + code + "): " + error);
}
System.exit(code);
}

@Override
public ArgumentParser getArgumentParser() {
// Normally we would keep this builder in here, but there are so many options that it makes
Expand All @@ -41,6 +55,9 @@ public void execute(ArgumentParser.ArgumentParserResults parsedArgs) throws Exce
new AsmInstaller().install(parsedArgs.isFlagSet("install-toolchain-non-interactive"));
} catch (IOException | InterruptedException e) {
StreamUtils.GetSystemErr().println(e.getMessage());
if(throwOnError) {
throw new RuntimeException("Toolchain installation failed", e);
}
System.exit(1);
}
return;
Expand All @@ -59,15 +76,15 @@ public void execute(ArgumentParser.ArgumentParserResults parsedArgs) throws Exce
try {
try {
if(input.isDirectory()) {
LogErrorAndQuit("Currently only single files are supported.", 1);
logErrorAndQuit("Currently only single files are supported.", 1);
} else {
AsmCompiler compiler = new AsmCompiler(parsedArgs);
try {
compiler.compileEntryPoint(input, output, exeName);
} catch (IOException ex) {
LogErrorAndQuit(ex.getMessage(), 1);
logErrorAndQuit(ex.getMessage(), 1);
} catch (InternalException ex) {
LogErrorAndQuit(ex.getMessage() + "\nAn internal exception occurred, which is not caused by your code. "
logErrorAndQuit(ex.getMessage() + "\nAn internal exception occurred, which is not caused by your code. "
+ (parsedArgs.isFlagSet("verbose")
? "Please report this with all the above information."
: "Please re-run with the --verbose switch."), 2);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/laytonsmith/core/asm/AsmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public static String formatLine(Target t, LLVMEnvironment llvmenv, String line,
if(s.length() < commentTab) {
s += StringUtils.stringMultiply(commentTab - s.length(), " ");
}
s += " ; " + t.toString();
if(t == Target.UNKNOWN) {
s += " ; <<synthetic>>";
} else {
s += " ; " + t.toString();
}
}
s += OSUtils.GetLineEnding();
return s;
Expand Down
Loading
Loading